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