Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
log1m_exp.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__REV__FUNCTIONS__LOG1M_EXP_HPP
2 #define STAN__AGRAD__REV__FUNCTIONS__LOG1M_EXP_HPP
3 
4 #include <stan/agrad/rev/var.hpp>
8 #include <boost/math/special_functions/expm1.hpp>
9 
10 namespace stan {
11  namespace agrad {
12 
13  namespace {
14  class log1m_exp_v_vari : public op_v_vari {
15  public:
16  log1m_exp_v_vari(vari* avi) :
17  op_v_vari(stan::math::log1m_exp(avi->val_),
18  avi) {
19  }
20  void chain() {
21  //derivative of log(1-exp(x)) = -exp(x)/(1-exp(x)) = -1/(exp(-x)-1) = -1/expm1(-x)
22  avi_->adj_ -= adj_ / boost::math::expm1(-(avi_->val_));
23  }
24  };
25  }
26 
31  inline var log1m_exp(const stan::agrad::var& a) {
32  return var(new log1m_exp_v_vari(a.vi_));
33  }
34 
35  }
36 }
37 #endif
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:40
fvar< T > expm1(const fvar< T > &x)
Definition: expm1.hpp:15
fvar< T > log1m_exp(const fvar< T > &x)
Definition: log1m_exp.hpp:17
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:27

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