Stan Math Library  2.20.0
reverse mode automatic differentiation
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/meta.hpp>
5 #include <stan/math/rev/core.hpp>
10 
11 namespace stan {
12 namespace math {
13 
14 namespace internal {
15 
17  public:
18  inc_beta_vvv_vari(vari* avi, vari* bvi, vari* cvi)
19  : op_vvv_vari(inc_beta(avi->val_, bvi->val_, cvi->val_), avi, bvi, cvi) {}
20  void chain() {
21  double d_a;
22  double d_b;
23  const double beta_ab = beta(avi_->val_, bvi_->val_);
24  grad_reg_inc_beta(d_a, d_b, avi_->val_, bvi_->val_, cvi_->val_,
26  digamma(avi_->val_ + bvi_->val_), beta_ab);
27 
28  avi_->adj_ += adj_ * d_a;
29  bvi_->adj_ += adj_ * d_b;
30  cvi_->adj_ += adj_ * std::pow(1 - cvi_->val_, bvi_->val_ - 1)
31  * std::pow(cvi_->val_, avi_->val_ - 1) / beta_ab;
32  }
33 };
34 
35 } // namespace internal
36 
37 inline var inc_beta(const var& a, const var& b, const var& c) {
38  return var(new internal::inc_beta_vvv_vari(a.vi_, b.vi_, c.vi_));
39 }
40 
41 } // namespace math
42 } // namespace stan
43 #endif
The variable implementation base class.
Definition: vari.hpp:30
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:33
friend class var
Definition: vari.hpp:32
const double val_
The value of this variable.
Definition: vari.hpp:38
fvar< T > inc_beta(const fvar< T > &a, const fvar< T > &b, const fvar< T > &x)
Definition: inc_beta.hpp:18
fvar< T > beta(const fvar< T > &x1, const fvar< T > &x2)
Return fvar with the beta function applied to the specified arguments and its gradient.
Definition: beta.hpp:51
void grad_reg_inc_beta(T &g1, T &g2, const T &a, const T &b, const T &z, const T &digammaA, const T &digammaB, const T &digammaSum, const T &betaAB)
Computes the gradients of the regularized incomplete beta function.
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: inc_beta.hpp:20
inc_beta_vvv_vari(vari *avi, vari *bvi, vari *cvi)
Definition: inc_beta.hpp:18
double adj_
The adjoint of this variable, which is the partial derivative of this variable with respect to the ro...
Definition: vari.hpp:44
fvar< T > pow(const fvar< T > &x1, const fvar< T > &x2)
Definition: pow.hpp:16
fvar< T > digamma(const fvar< T > &x)
Return the derivative of the log gamma function at the specified argument.
Definition: digamma.hpp:23

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