| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

log1m_exp.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_SCAL_FUN_LOG1M_EXP_HPP
2 #define STAN_MATH_REV_SCAL_FUN_LOG1M_EXP_HPP
3
4 #include <stan/math/rev/core.hpp>
5 #include <stan/math/prim/scal/fun/log1m_exp.hpp>
6 #include <stan/math/rev/scal/fun/calculate_chain.hpp>
7 #include <cmath>
8
9 #ifdef _MSC_VER
10 #include <boost/math/special_functions/expm1.hpp>
11 using boost::math::expm1;
12 #endif
13
14 namespace stan {
15 namespace math {
16
17 namespace {
18 class log1m_exp_v_vari : public op_v_vari {
19 public:
20 explicit log1m_exp_v_vari(vari* avi) :
21 op_v_vari(log1m_exp(avi->val_),
22 avi) {
23 }
24 void chain() {
25 // derivative of
26 // log(1-exp(x)) = -exp(x)/(1-exp(x))
27 // = -1/(exp(-x)-1)
28 // = -1/expm1(-x)
29 avi_->adj_ -= adj_ / ::expm1(-(avi_->val_));
30 }
31 };
32 }
33
38 inline var log1m_exp(const var& a) {
39 return var(new log1m_exp_v_vari(a.vi_));
40 }
41
42 }
43 }
44 #endif
core.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:30
stan::math::expm1
fvar< T > expm1(const fvar< T > &x)
Definition: expm1.hpp:12
stan::math::log1m_exp
fvar< T > log1m_exp(const fvar< T > &x)
Definition: log1m_exp.hpp:16
log1m_exp.hpp
stan::math::var::vi_
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:42
calculate_chain.hpp

[ Stan Home Page ] © 2011–2016, Stan Development Team.