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
10#include <cmath>
11
12namespace stan {
13namespace math {
14
15namespace internal {
16
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_), avi, bvi, cvi) {}
21 void chain() {
22 double d_a;
23 double d_b;
24 const double beta_ab = beta(avi_->val_, bvi_->val_);
25 grad_reg_inc_beta(d_a, d_b, avi_->val_, bvi_->val_, cvi_->val_,
26 digamma(avi_->val_), digamma(bvi_->val_),
27 digamma(avi_->val_ + bvi_->val_), beta_ab);
28
29 avi_->adj_ += adj_ * d_a;
30 bvi_->adj_ += adj_ * d_b;
31 cvi_->adj_ += adj_ * std::pow(1 - cvi_->val_, bvi_->val_ - 1)
32 * std::pow(cvi_->val_, avi_->val_ - 1) / beta_ab;
33 }
34};
35
36} // namespace internal
37
38inline var inc_beta(const var& a, const var& b, const var& c) {
39 return var(new internal::inc_beta_vvv_vari(a.vi_, b.vi_, c.vi_));
40}
41
42} // namespace math
43} // namespace stan
44#endif
inc_beta_vvv_vari(vari *avi, vari *bvi, vari *cvi)
Definition inc_beta.hpp:19
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 ...