Stan Math Library  2.20.0
reverse mode automatic differentiation
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/meta.hpp>
5 #include <stan/math/rev/core.hpp>
8 
9 namespace stan {
10 namespace math {
11 
12 namespace internal {
13 
15  public:
17  : op_vv_vari(log_sum_exp(avi->val_, bvi->val_), avi, bvi) {}
18  void chain() {
21  }
22 };
24  public:
25  log_sum_exp_vd_vari(vari* avi, double b)
26  : op_vd_vari(log_sum_exp(avi->val_, b), avi, b) {}
28 };
30  public:
31  log_sum_exp_dv_vari(double a, vari* bvi)
32  : op_dv_vari(log_sum_exp(a, bvi->val_), a, bvi) {}
34 };
35 
36 } // namespace internal
37 
41 inline var log_sum_exp(const var& a, const var& b) {
42  return var(new internal::log_sum_exp_vv_vari(a.vi_, b.vi_));
43 }
47 inline var log_sum_exp(const var& a, double b) {
48  return var(new internal::log_sum_exp_vd_vari(a.vi_, b));
49 }
53 inline var log_sum_exp(double a, const var& b) {
54  return var(new internal::log_sum_exp_dv_vari(a, b.vi_));
55 }
56 
57 } // namespace math
58 } // namespace stan
59 #endif
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
Definition: log_sum_exp.hpp:33
The variable implementation base class.
Definition: vari.hpp:30
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:33
fvar< T > log_sum_exp(const std::vector< fvar< T > > &v)
Definition: log_sum_exp.hpp:12
friend class var
Definition: vari.hpp:32
const double val_
The value of this variable.
Definition: vari.hpp:38
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:45
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
Definition: log_sum_exp.hpp:18
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
Definition: log_sum_exp.hpp:27
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.