Automatic Differentiation
 
Loading...
Searching...
No Matches

◆ ub_constrain() [2/14]

template<typename T , typename U , require_all_kernel_expressions_and_none_scalar_t< T > * = nullptr, require_all_kernel_expressions_t< U > * = nullptr>
auto stan::math::ub_constrain ( const T &  x,
const U &  ub,
return_type_t< T, U > &  lp 
)
inline

Return the upper-bounded value for the specified unconstrained matrix and upper bound.

Specialization of ub_constrain to apply a matrix of upper bounds elementwise to each input element.

Return the upper-bounded value for the specified unconstrained scalar and upper bound and increment the specified log probability reference with the log absolute Jacobian determinant of the transform.

The transform is

\(f(x) = U - \exp(x)\)

where \(U\) is the upper bound.

Template Parameters
Ttype of Matrix
Utype of upper bound
Parameters
[in]xfree Matrix.
[in]ubupper bound
[in,out]lpreference to log probability to increment
Returns
matrix constrained to have upper bound

The transform is as specified for ub_constrain(T, double). The log absolute Jacobian determinant is

\( \log | \frac{d}{dx} -\mbox{exp}(x) + U | = \log | -\mbox{exp}(x) + 0 | = x\).

Template Parameters
Ttype of scalar
Utype of upper bound
Parameters
[in]xfree scalar
[in]ubupper bound
[in,out]lplog density
Returns
scalar constrained to have upper bound
Template Parameters
TA type inheriting from EigenBase or a var_value with inner type inheriting from EigenBase.
UA type inheriting from EigenBase or a var_value with inner type inheriting from EigenBase.
Parameters
[in]xunconstrained input
[in]ubupper bound on output
[in,out]lpreference to log probability to increment
Returns
upper-bound constrained value corresponding to inputs

Definition at line 60 of file ub_constrain.hpp.