Automatic Differentiation
 
Loading...
Searching...
No Matches
inc_beta.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_INC_BETA_HPP
2#define STAN_MATH_REV_FUN_INC_BETA_HPP
3
11#include <cmath>
12
13namespace stan {
14namespace math {
15
16namespace internal {
17
19 public:
20 inc_beta_vvv_vari(vari* avi, vari* bvi, vari* cvi)
21 : op_vvv_vari(inc_beta(avi->val_, bvi->val_, cvi->val_), avi, bvi, cvi) {}
22 void chain() {
23 double d_a;
24 double d_b;
25 const double beta_ab = beta(avi_->val_, bvi_->val_);
26 grad_reg_inc_beta(d_a, d_b, avi_->val_, bvi_->val_, cvi_->val_,
27 digamma(avi_->val_), digamma(bvi_->val_),
28 digamma(avi_->val_ + bvi_->val_), beta_ab);
29
30 avi_->adj_ += adj_ * d_a;
31 bvi_->adj_ += adj_ * d_b;
32 cvi_->adj_ += adj_ * std::pow(1 - cvi_->val_, bvi_->val_ - 1)
33 * std::pow(cvi_->val_, avi_->val_ - 1) / beta_ab;
34 }
35};
36
37} // namespace internal
38
39inline var inc_beta(const var& a, const var& b, const var& c) {
40 return var(new internal::inc_beta_vvv_vari(a.vi_, b.vi_, c.vi_));
41}
42
43} // namespace math
44} // namespace stan
45#endif
inc_beta_vvv_vari(vari *avi, vari *bvi, vari *cvi)
Definition inc_beta.hpp:20
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.
fvar< T > inc_beta(const fvar< T > &a, const fvar< T > &b, const fvar< T > &x)
Definition inc_beta.hpp:19
var_value< double > var
Definition var.hpp:1187
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
fvar< T > digamma(const fvar< T > &x)
Return the derivative of the log gamma function at the specified argument.
Definition digamma.hpp:23
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...