Loading [MathJax]/extensions/TeX/AMSsymbols.js
Automatic Differentiation
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 if (a < 0) {
53 double exp_a = std::exp(a);
54 if (a < LOG_EPSILON) {
55 return exp_a;
56 }
57 return exp_a / (1.0 + exp_a);
58 }
59 return inv(1 + std::exp(-a));
60}
61
70 template <typename T>
71 static inline auto fun(T&& x) {
72 return inv_logit(std::forward<T>(x));
73 }
74};
75
83template <typename Container, require_ad_container_t<Container>* = nullptr,
84 require_all_not_nonscalar_prim_or_rev_kernel_expression_t<
85 Container>* = nullptr,
86 require_not_rev_matrix_t<Container>* = nullptr>
87inline auto inv_logit(Container&& x) {
89 std::forward<Container>(x));
90}
91
102template <typename Container,
105 Container>* = nullptr>
106inline auto inv_logit(Container&& x) {
108 std::forward<Container>(x),
109 [](const auto& v) { return v.array().logistic(); });
110}
111} // namespace math
112} // namespace stan
113
114#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.
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: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:71
Structure to wrap inv_logit() so that it can be vectorized.
Definition inv_logit.hpp:69