Stan Math Library: stan/math/rev/scal/fun/log_sum_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_sum_exp.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_SCAL_FUN_LOG_SUM_EXP_HPP
2 #define STAN_MATH_REV_SCAL_FUN_LOG_SUM_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_sum_exp.hpp>
7
8 namespace stan {
9 namespace math {
10
11 namespace {
12
13 class log_sum_exp_vv_vari : public op_vv_vari {
14 public:
15 log_sum_exp_vv_vari(vari* avi, vari* bvi) :
16 op_vv_vari(stan::math::log_sum_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_ * calculate_chain(bvi_->val_, val_);
22 }
23 };
24 class log_sum_exp_vd_vari : public op_vd_vari {
25 public:
26 log_sum_exp_vd_vari(vari* avi, double b) :
27 op_vd_vari(stan::math::log_sum_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_sum_exp_dv_vari : public op_dv_vari {
35 public:
36 log_sum_exp_dv_vari(double a, vari* bvi) :
37 op_dv_vari(stan::math::log_sum_exp(a, bvi->val_),
38 a, bvi) {
39 }
40 void chain() {
41 bvi_->adj_ += adj_ * calculate_chain(bvi_->val_, val_);
42 }
43 };
44
45 }
46
50 inline var log_sum_exp(const stan::math::var& a,
51 const stan::math::var& b) {
52 return var(new log_sum_exp_vv_vari(a.vi_, b.vi_));
53 }
57 inline var log_sum_exp(const stan::math::var& a,
58 const double& b) {
59 return var(new log_sum_exp_vd_vari(a.vi_, b));
60 }
64 inline var log_sum_exp(const double& a,
65 const stan::math::var& b) {
66 return var(new log_sum_exp_dv_vari(a, b.vi_));
67 }
68
69 }
70 }
71 #endif
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_sum_exp
fvar< T > log_sum_exp(const std::vector< fvar< T > > &v)
Definition: log_sum_exp.hpp:14
log_sum_exp.hpp
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.