Stan Math Library: stan/math/rev/scal/fun/log_diff_exp.hpp Source File

| Stan Math Library 2.10.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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/core.hpp>
5 #include <stan/math/rev/scal/fun/calculate_chain.hpp>
6 #include <stan/math/prim/scal/fun/log_diff_exp.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 log_diff_exp_vv_vari : public op_vv_vari {
19 public:
20 log_diff_exp_vv_vari(vari* avi, vari* bvi) :
21 op_vv_vari(stan::math::log_diff_exp(avi->val_, bvi->val_),
22 avi, bvi) {
23 }
24 void chain() {
25 avi_->adj_ += adj_ * calculate_chain(avi_->val_, val_);
26 bvi_->adj_ -= adj_ / ::expm1(avi_->val_ - bvi_->val_);
27 }
28 };
29 class log_diff_exp_vd_vari : public op_vd_vari {
30 public:
31 log_diff_exp_vd_vari(vari* avi, double b) :
32 op_vd_vari(stan::math::log_diff_exp(avi->val_, b),
33 avi, b) {
34 }
35 void chain() {
36 avi_->adj_ += adj_ * calculate_chain(avi_->val_, val_);
37 }
38 };
39 class log_diff_exp_dv_vari : public op_dv_vari {
40 public:
41 log_diff_exp_dv_vari(double a, vari* bvi) :
42 op_dv_vari(stan::math::log_diff_exp(a, bvi->val_),
43 a, bvi) {
44 }
45 void chain() {
46 bvi_->adj_ -= adj_ / ::expm1(ad_ - bvi_->val_);
47 }
48 };
49 }
50
54 inline var log_diff_exp(const stan::math::var& a,
55 const stan::math::var& b) {
56 return var(new log_diff_exp_vv_vari(a.vi_, b.vi_));
57 }
61 inline var log_diff_exp(const stan::math::var& a,
62 const double& b) {
63 return var(new log_diff_exp_vd_vari(a.vi_, b));
64 }
68 inline var log_diff_exp(const double& a,
69 const stan::math::var& b) {
70 return var(new log_diff_exp_dv_vari(a, b.vi_));
71 }
72
73 }
74 }
75 #endif
log_diff_exp.hpp
core.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:31
stan::math::log_diff_exp
fvar< T > log_diff_exp(const fvar< T > &x1, const fvar< T > &x2)
Definition: log_diff_exp.hpp:14
stan::math::expm1
fvar< T > expm1(const fvar< T > &x)
Definition: expm1.hpp:12
stan::math::calculate_chain
double calculate_chain(const double &x, const double &val)
Definition: calculate_chain.hpp:8
stan::math::var::vi_
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:43
calculate_chain.hpp

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