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
51template <typename T, require_arithmetic_t<T>* = nullptr>
52inline double inv_logit(T&& a) {
53 if (a < 0) {
54 double exp_a = std::exp(a);
55 if (a < LOG_EPSILON) {
56 return exp_a;
57 }
58 return exp_a / (1.0 + exp_a);
59 }
60 return inv(1.0 + std::exp(-a));
61}
62
71 template <typename T>
72 static inline auto fun(T&& x) {
73 return inv_logit(std::forward<T>(x));
74 }
75};
76
84template <typename Container, require_ad_container_t<Container>* = nullptr,
85 require_all_not_nonscalar_prim_or_rev_kernel_expression_t<
86 Container>* = nullptr,
87 require_not_rev_matrix_t<Container>* = nullptr>
88inline auto inv_logit(Container&& x) {
90 std::forward<Container>(x));
91}
92
103template <typename Container,
106 Container>* = nullptr>
107inline auto inv_logit(Container&& x) {
109 std::forward<Container>(x),
110 [](auto&& v) { return v.array().logistic(); });
111}
112} // namespace math
113} // namespace stan
114
115#endif
require_t< container_type_check_base< is_container, base_type_t, TypeCheck, Check... > > require_container_bt
Require type satisfies is_container.
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.
auto inv_logit(T &&x)
Returns the inverse logit function applied to the argument.
Definition inv_logit.hpp:20
const double LOG_EPSILON
The natural logarithm of machine precision , .
Definition constants.hpp:74
fvar< T > inv(const fvar< T > &x)
Definition inv.hpp:13
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Base template class for vectorization of unary scalar functions defined by a template class F to a sc...
static auto fun(T &&x)
Definition inv_logit.hpp:72
Structure to wrap inv_logit() so that it can be vectorized.
Definition inv_logit.hpp:70