Automatic Differentiation
 
Loading...
Searching...
No Matches
gamma_q.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_GAMMA_Q_HPP
2#define STAN_MATH_REV_FUN_GAMMA_Q_HPP
3
10#include <boost/math/special_functions/gamma.hpp>
11
12namespace stan {
13namespace math {
14
15namespace internal {
17 public:
19 : op_vv_vari(gamma_q(avi->val_, bvi->val_), avi, bvi) {}
20 void chain() {
21 avi_->adj_ += adj_
22 * grad_reg_inc_gamma(avi_->val_, bvi_->val_,
23 tgamma(avi_->val_), digamma(avi_->val_));
24 bvi_->adj_
25 -= adj_ * boost::math::gamma_p_derivative(avi_->val_, bvi_->val_);
26 }
27};
28
30 public:
31 gamma_q_vd_vari(vari* avi, double b)
32 : op_vd_vari(gamma_q(avi->val_, b), avi, b) {}
33 void chain() {
34 avi_->adj_ += adj_
35 * grad_reg_inc_gamma(avi_->val_, bd_, tgamma(avi_->val_),
36 digamma(avi_->val_));
37 }
38};
39
41 public:
42 gamma_q_dv_vari(double a, vari* bvi)
43 : op_dv_vari(gamma_q(a, bvi->val_), a, bvi) {}
44 void chain() {
45 bvi_->adj_ -= adj_ * boost::math::gamma_p_derivative(ad_, bvi_->val_);
46 }
47};
48} // namespace internal
49
50inline var gamma_q(const var& a, const var& b) {
51 return var(new internal::gamma_q_vv_vari(a.vi_, b.vi_));
52}
53
54inline var gamma_q(const var& a, double b) {
55 return var(new internal::gamma_q_vd_vari(a.vi_, b));
56}
57
58inline var gamma_q(double a, const var& b) {
59 return var(new internal::gamma_q_dv_vari(a, b.vi_));
60}
61
62} // namespace math
63} // namespace stan
64#endif
gamma_q_dv_vari(double a, vari *bvi)
Definition gamma_q.hpp:42
gamma_q_vd_vari(vari *avi, double b)
Definition gamma_q.hpp:31
gamma_q_vv_vari(vari *avi, vari *bvi)
Definition gamma_q.hpp:18
return_type_t< T1, T2 > grad_reg_inc_gamma(T1 a, T2 z, T1 g, T1 dig, double precision=1e-6, int max_steps=1e5)
Gradient of the regularized incomplete gamma functions igamma(a, z)
var_value< double > var
Definition var.hpp:1187
fvar< T > tgamma(const fvar< T > &x)
Return the result of applying the gamma function to the specified argument.
Definition tgamma.hpp:21
fvar< T > gamma_q(const fvar< T > &x1, const fvar< T > &x2)
Definition gamma_q.hpp:14
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 ...