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

| Stan Math Library 2.10.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(stan::math::inc_beta(avi->val_, bvi->val_, cvi->val_),
21 avi, bvi, cvi) {
22 }
23 void chain() {
24 using stan::math::digamma;
25 using stan::math::lbeta;
26
27 double d_a; double d_b;
28 stan::math::grad_reg_inc_beta(d_a, d_b, avi_->val_, bvi_->val_,
29 cvi_->val_, digamma(avi_->val_),
30 digamma(bvi_->val_),
31 digamma(avi_->val_ + bvi_->val_),
32 std::exp(lbeta(avi_->val_,
33 bvi_->val_)));
34
35 avi_->adj_ += adj_ * d_a;
36 bvi_->adj_ += adj_ * d_b;
37 cvi_->adj_ += adj_ * std::pow((1-cvi_->val_), bvi_->val_-1)
38 * std::pow(cvi_->val_, avi_->val_-1)
39 / std::exp(stan::math::lbeta(avi_->val_, bvi_->val_));
40 }
41 };
42
43 }
44
45 inline var inc_beta(const stan::math::var& a,
46 const stan::math::var& b,
47 const stan::math::var& c) {
48 return var(new inc_beta_vvv_vari(a.vi_, b.vi_, c.vi_));
49 }
50
51 }
52 }
53 #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:16
digamma.hpp
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:31
stan::math::inc_beta
fvar< T > inc_beta(const fvar< T > &a, const fvar< T > &b, const fvar< T > &x)
Definition: inc_beta.hpp:20
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:43
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:18
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:16

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