| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

ub_constrain.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_FUN_UB_CONSTRAIN_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_UB_CONSTRAIN_HPP
3
4 #include <boost/math/tools/promotion.hpp>
5 #include <stan/math/prim/scal/fun/identity_constrain.hpp>
6 #include <cmath>
7 #include <limits>
8
9 namespace stan {
10 namespace math {
11
31 template <typename T, typename TU>
32 inline
33 typename boost::math::tools::promote_args<T, TU>::type
34 ub_constrain(const T x, const TU ub) {
35 using std::exp;
36 if (ub == std::numeric_limits<double>::infinity())
37 return identity_constrain(x);
38 return ub - exp(x);
39 }
40
64 template <typename T, typename TU>
65 inline
66 typename boost::math::tools::promote_args<T, TU>::type
67 ub_constrain(const T x, const TU ub, T& lp) {
68 using std::exp;
69 if (ub == std::numeric_limits<double>::infinity())
70 return identity_constrain(x, lp);
71 lp += x;
72 return ub - exp(x);
73 }
74
75 }
76
77 }
78
79 #endif
stan
Definition: log_sum_exp.hpp:8
stan::math::exp
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
identity_constrain.hpp
stan::math::ub_constrain
boost::math::tools::promote_args< T, TU >::type ub_constrain(const T x, const TU ub)
Return the upper-bounded value for the specified unconstrained scalar and upper bound.
Definition: ub_constrain.hpp:34
stan::math::identity_constrain
T identity_constrain(T x)
Returns the result of applying the identity constraint transform to the input.
Definition: identity_constrain.hpp:21

[ Stan Home Page ] © 2011–2016, Stan Development Team.