Stan Math Library  2.20.0
reverse mode automatic differentiation
prob_constrain.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_FUN_PROB_CONSTRAIN_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_PROB_CONSTRAIN_HPP
3 
7 #include <cmath>
8 
9 namespace stan {
10 namespace math {
11 
24 template <typename T>
25 inline T prob_constrain(const T& x) {
26  return inv_logit(x);
27 }
28 
49 template <typename T>
50 inline T prob_constrain(const T& x, T& lp) {
51  using std::log;
52  T inv_logit_x = inv_logit(x);
53  lp += log(inv_logit_x) + log1m(inv_logit_x);
54  return inv_logit_x;
55 }
56 
57 } // namespace math
58 
59 } // namespace stan
60 
61 #endif
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:12
fvar< T > inv_logit(const fvar< T > &x)
Returns the inverse logit function applied to the argument.
Definition: inv_logit.hpp:20
T prob_constrain(const T &x)
Return a probability value constrained to fall between 0 and 1 (inclusive) for the specified free sca...
fvar< T > log1m(const fvar< T > &x)
Definition: log1m.hpp:12

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