Automatic Differentiation
 
Loading...
Searching...
No Matches
inv_logit.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_PRIM_FUN_INV_LOGIT_HPP
2#define STAN_MATH_PRIM_FUN_INV_LOGIT_HPP
3
9#include <cmath>
10
11namespace stan {
12namespace math {
13
51inline double inv_logit(double a) {
52 using std::exp;
53 if (a < 0) {
54 double exp_a = exp(a);
55 if (a < LOG_EPSILON) {
56 return exp_a;
57 }
58 return exp_a / (1 + exp_a);
59 }
60 return inv(1 + exp(-a));
61}
62
71 template <typename T>
72 static inline auto fun(const T& x) {
73 return inv_logit(x);
74 }
75};
76
84template <
85 typename T, require_not_var_matrix_t<T>* = nullptr,
87inline auto inv_logit(const T& x) {
89}
90
91// TODO(Tadej): Eigen is introducing their implementation logistic() of this
92// in 3.4. Use that once we switch to Eigen 3.4
93
94} // namespace math
95} // namespace stan
96
97#endif
require_all_not_t< is_nonscalar_prim_or_rev_kernel_expression< std::decay_t< Types > >... > require_all_not_nonscalar_prim_or_rev_kernel_expression_t
Require none of the types satisfy is_nonscalar_prim_or_rev_kernel_expression.
require_not_t< is_var_matrix< std::decay_t< T > > > require_not_var_matrix_t
Require type does not satisfy is_var_matrix.
const double LOG_EPSILON
The natural logarithm of machine precision , .
Definition constants.hpp:74
fvar< T > inv_logit(const fvar< T > &x)
Returns the inverse logit function applied to the argument.
Definition inv_logit.hpp:20
fvar< T > inv(const fvar< T > &x)
Definition inv.hpp:12
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
Base template class for vectorization of unary scalar functions defined by a template class F to a sc...
static auto fun(const T &x)
Definition inv_logit.hpp:72
Structure to wrap inv_logit() so that it can be vectorized.
Definition inv_logit.hpp:70