| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

inc_beta.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_SCAL_FUN_INC_BETA_HPP
2 #define STAN_MATH_REV_SCAL_FUN_INC_BETA_HPP
3
4 #include <stan/math/rev/core.hpp>
5 #include <stan/math/prim/scal/fun/constants.hpp>
6 #include <stan/math/prim/scal/fun/grad_reg_inc_beta.hpp>
7 #include <stan/math/rev/scal/fun/pow.hpp>
8 #include <stan/math/prim/scal/fun/lbeta.hpp>
9 #include <stan/math/prim/scal/fun/digamma.hpp>
10 #include <valarray>
11
12 namespace stan {
13 namespace math {
14
15 namespace {
16
17 class inc_beta_vvv_vari : public op_vvv_vari {
18 public:
19 inc_beta_vvv_vari(vari* avi, vari* bvi, vari* cvi) :
20 op_vvv_vari(inc_beta(avi->val_, bvi->val_, cvi->val_),
21 avi, bvi, cvi) {
22 }
23 void chain() {
24 double d_a; double d_b;
25 grad_reg_inc_beta(d_a, d_b, avi_->val_, bvi_->val_,
26 cvi_->val_, digamma(avi_->val_),
27 digamma(bvi_->val_),
28 digamma(avi_->val_ + bvi_->val_),
29 std::exp(lbeta(avi_->val_,
30 bvi_->val_)));
31
32 avi_->adj_ += adj_ * d_a;
33 bvi_->adj_ += adj_ * d_b;
34 cvi_->adj_ += adj_ * std::pow((1-cvi_->val_), bvi_->val_-1)
35 * std::pow(cvi_->val_, avi_->val_-1)
36 / std::exp(lbeta(avi_->val_, bvi_->val_));
37 }
38 };
39
40 }
41
42 inline var inc_beta(const var& a,
43 const var& b,
44 const var& c) {
45 return var(new inc_beta_vvv_vari(a.vi_, b.vi_, c.vi_));
46 }
47
48 }
49 }
50 #endif
core.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::lbeta
fvar< T > lbeta(const fvar< T > &x1, const fvar< T > &x2)
Definition: lbeta.hpp:15
digamma.hpp
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:30
stan::math::inc_beta
fvar< T > inc_beta(const fvar< T > &a, const fvar< T > &b, const fvar< T > &x)
Definition: inc_beta.hpp:19
stan::math::exp
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
stan::math::var::vi_
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:42
grad_reg_inc_beta.hpp
constants.hpp
pow.hpp
lbeta.hpp
stan::math::pow
fvar< T > pow(const fvar< T > &x1, const fvar< T > &x2)
Definition: pow.hpp:17
stan::math::grad_reg_inc_beta
void grad_reg_inc_beta(T &g1, T &g2, T a, T b, T z, T digammaA, T digammaB, T digammaSum, T betaAB)
Definition: grad_reg_inc_beta.hpp:14
stan::math::digamma
fvar< T > digamma(const fvar< T > &x)
Definition: digamma.hpp:15

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