Automatic Differentiation
 
Loading...
Searching...
No Matches
prob_constrain.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_PROB_CONSTRAIN_HPP
2#define STAN_MATH_PRIM_FUN_PROB_CONSTRAIN_HPP
3
8#include <cmath>
9
10namespace stan {
11namespace math {
12
25template <typename T>
26inline T prob_constrain(const T& x) {
27 return inv_logit(x);
28}
29
50template <typename T>
51inline T prob_constrain(const T& x, T& lp) {
52 T log_inv_logit_x = log_inv_logit(x);
53 lp += log_inv_logit_x + log1m_inv_logit(x);
54 return exp(log_inv_logit_x);
55}
56
71template <bool Jacobian, typename T>
72inline auto prob_constrain(const T& x, T& lp) {
73 if (Jacobian) {
74 return prob_constrain(x, lp);
75 } else {
76 return prob_constrain(x);
77 }
78}
79} // namespace math
80} // namespace stan
81
82#endif
fvar< T > log_inv_logit(const fvar< T > &x)
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_inv_logit(const fvar< T > &x)
Return the natural logarithm of one minus the inverse logit of the specified argument.
fvar< T > exp(const fvar< T > &x)
Definition exp.hpp:13
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Definition fvar.hpp:9