| 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
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 namespace stan {
10 namespace math {
11
12 namespace {
13 class log_diff_exp_vv_vari : public op_vv_vari {
14 public:
15 log_diff_exp_vv_vari(vari* avi, vari* bvi) :
16 op_vv_vari(stan::math::log_diff_exp(avi->val_, bvi->val_),
17 avi, bvi) {
18 }
19 void chain() {
20 avi_->adj_ += adj_ * calculate_chain(avi_->val_, val_);
21 bvi_->adj_ -= adj_ / ::expm1(avi_->val_ - bvi_->val_);
22 }
23 };
24 class log_diff_exp_vd_vari : public op_vd_vari {
25 public:
26 log_diff_exp_vd_vari(vari* avi, double b) :
27 op_vd_vari(stan::math::log_diff_exp(avi->val_, b),
28 avi, b) {
29 }
30 void chain() {
31 avi_->adj_ += adj_ * calculate_chain(avi_->val_, val_);
32 }
33 };
34 class log_diff_exp_dv_vari : public op_dv_vari {
35 public:
36 log_diff_exp_dv_vari(double a, vari* bvi) :
37 op_dv_vari(stan::math::log_diff_exp(a, bvi->val_),
38 a, bvi) {
39 }
40 void chain() {
41 bvi_->adj_ -= adj_ / ::expm1(ad_ - bvi_->val_);
42 }
43 };
44 }
45
49 inline var log_diff_exp(const stan::math::var& a,
50 const stan::math::var& b) {
51 return var(new log_diff_exp_vv_vari(a.vi_, b.vi_));
52 }
56 inline var log_diff_exp(const stan::math::var& a,
57 const double& b) {
58 return var(new log_diff_exp_vd_vari(a.vi_, b));
59 }
63 inline var log_diff_exp(const double& a,
64 const stan::math::var& b) {
65 return var(new log_diff_exp_dv_vari(a, b.vi_));
66 }
67
68 }
69 }
70 #endif
log_diff_exp.hpp
core.hpp
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:32
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:44
calculate_chain.hpp

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