Stan Math Library  2.20.0
reverse mode automatic differentiation
log_diff_exp.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_SCAL_FUN_LOG_DIFF_EXP_HPP
2 #define STAN_MATH_REV_SCAL_FUN_LOG_DIFF_EXP_HPP
3 
4 #include <stan/math/rev/meta.hpp>
5 #include <stan/math/rev/core.hpp>
9 
10 namespace stan {
11 namespace math {
12 
13 namespace internal {
15  public:
17  : op_vv_vari(log_diff_exp(avi->val_, bvi->val_), avi, bvi) {}
18  void chain() {
20  bvi_->adj_ -= adj_ / expm1(avi_->val_ - bvi_->val_);
21  }
22 };
24  public:
25  log_diff_exp_vd_vari(vari* avi, double b)
26  : op_vd_vari(log_diff_exp(avi->val_, b), avi, b) {}
28 };
30  public:
31  log_diff_exp_dv_vari(double a, vari* bvi)
32  : op_dv_vari(log_diff_exp(a, bvi->val_), a, bvi) {}
33  void chain() { bvi_->adj_ -= adj_ / expm1(ad_ - bvi_->val_); }
34 };
35 } // namespace internal
36 
44 inline var log_diff_exp(const var& a, const var& b) {
45  return var(new internal::log_diff_exp_vv_vari(a.vi_, b.vi_));
46 }
47 
55 inline var log_diff_exp(const var& a, double b) {
56  return var(new internal::log_diff_exp_vd_vari(a.vi_, b));
57 }
58 
66 inline var log_diff_exp(double a, const var& b) {
67  return var(new internal::log_diff_exp_dv_vari(a, b.vi_));
68 }
69 
70 } // namespace math
71 } // namespace stan
72 #endif
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
The variable implementation base class.
Definition: vari.hpp:30
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:33
friend class var
Definition: vari.hpp:32
fvar< T > log_diff_exp(const fvar< T > &x1, const fvar< T > &x2)
const double val_
The value of this variable.
Definition: vari.hpp:38
fvar< T > expm1(const fvar< T > &x)
Definition: expm1.hpp:13
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:45
double calculate_chain(double x, double val)
double adj_
The adjoint of this variable, which is the partial derivative of this variable with respect to the ro...
Definition: vari.hpp:44

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