| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
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 namespace stan {
10 namespace math {
11
12 namespace {
13 class log1m_exp_v_vari : public op_v_vari {
14 public:
15 explicit log1m_exp_v_vari(vari* avi) :
16 op_v_vari(stan::math::log1m_exp(avi->val_),
17 avi) {
18 }
19 void chain() {
20 // derivative of
21 // log(1-exp(x)) = -exp(x)/(1-exp(x))
22 // = -1/(exp(-x)-1)
23 // = -1/expm1(-x)
24 avi_->adj_ -= adj_ / ::expm1(-(avi_->val_));
25 }
26 };
27 }
28
33 inline var log1m_exp(const stan::math::var& a) {
34 return var(new log1m_exp_v_vari(a.vi_));
35 }
36
37 }
38 }
39 #endif
core.hpp
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:32
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:44
calculate_chain.hpp

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