1 #ifndef STAN_MATH_PRIM_SCAL_FUN_LUB_CONSTRAIN_HPP 2 #define STAN_MATH_PRIM_SCAL_FUN_LUB_CONSTRAIN_HPP 9 #include <boost/math/tools/promotion.hpp> 43 template <
typename T,
typename L,
typename U>
44 inline typename boost::math::tools::promote_args<T, L, U>::type
lub_constrain(
45 const T& x,
const L& lb,
const U& ub) {
57 if ((x <
INFTY) && (inv_logit_x == 1))
58 inv_logit_x = 1 - 1
e-15;
65 return fma((ub - lb), inv_logit_x, lb);
109 template <
typename T,
typename L,
typename U>
110 inline typename boost::math::tools::promote_args<T, L, U>::type
lub_constrain(
111 const T& x,
const L& lb,
const U& ub, T& lp) {
121 T exp_minus_x =
exp(-x);
123 lp +=
log(ub - lb) - x - 2 *
log1p(exp_minus_x);
125 if ((x <
INFTY) && (inv_logit_x == 1))
126 inv_logit_x = 1 - 1
e-15;
130 lp +=
log(ub - lb) + x - 2 *
log1p(exp_x);
135 return fma((ub - lb), inv_logit_x, lb);
fvar< T > log(const fvar< T > &x)
fvar< T > inv_logit(const fvar< T > &x)
Returns the inverse logit function applied to the argument.
boost::math::tools::promote_args< T, U >::type ub_constrain(const T &x, const U &ub)
Return the upper-bounded value for the specified unconstrained scalar and upper bound.
boost::math::tools::promote_args< T, L >::type lb_constrain(const T &x, const L &lb)
Return the lower-bounded value for the specified unconstrained input and specified lower bound...
boost::math::tools::promote_args< T, L, U >::type lub_constrain(const T &x, const L &lb, const U &ub)
Return the lower- and upper-bounded scalar derived by transforming the specified free scalar given th...
fvar< T > exp(const fvar< T > &x)
fvar< typename stan::return_type< T1, T2, T3 >::type > fma(const fvar< T1 > &x1, const fvar< T2 > &x2, const fvar< T3 > &x3)
The fused multiply-add operation (C99).
double e()
Return the base of the natural logarithm.
fvar< T > log1p(const fvar< T > &x)
const double INFTY
Positive infinity.
const double NEGATIVE_INFTY
Negative infinity.
void check_less(const char *function, const char *name, const T_y &y, const T_high &high)
Check if y is strictly less than high.