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
11#include <boost/math/special_functions/gamma.hpp>
12
13namespace stan {
14namespace math {
15
16namespace internal {
18 public:
20 : op_vv_vari(gamma_q(avi->val_, bvi->val_), avi, bvi) {}
21 void chain() {
22 avi_->adj_ += adj_
23 * grad_reg_inc_gamma(avi_->val_, bvi_->val_,
24 tgamma(avi_->val_), digamma(avi_->val_));
25 bvi_->adj_
26 -= adj_ * boost::math::gamma_p_derivative(avi_->val_, bvi_->val_);
27 }
28};
29
31 public:
32 gamma_q_vd_vari(vari* avi, double b)
33 : op_vd_vari(gamma_q(avi->val_, b), avi, b) {}
34 void chain() {
35 avi_->adj_ += adj_
36 * grad_reg_inc_gamma(avi_->val_, bd_, tgamma(avi_->val_),
37 digamma(avi_->val_));
38 }
39};
40
42 public:
43 gamma_q_dv_vari(double a, vari* bvi)
44 : op_dv_vari(gamma_q(a, bvi->val_), a, bvi) {}
45 void chain() {
46 bvi_->adj_ -= adj_ * boost::math::gamma_p_derivative(ad_, bvi_->val_);
47 }
48};
49} // namespace internal
50
51inline var gamma_q(const var& a, const var& b) {
52 return var(new internal::gamma_q_vv_vari(a.vi_, b.vi_));
53}
54
55inline var gamma_q(const var& a, double b) {
56 return var(new internal::gamma_q_vd_vari(a.vi_, b));
57}
58
59inline var gamma_q(double a, const var& b) {
60 return var(new internal::gamma_q_dv_vari(a, b.vi_));
61}
62
63} // namespace math
64} // namespace stan
65#endif
gamma_q_dv_vari(double a, vari *bvi)
Definition gamma_q.hpp:43
gamma_q_vd_vari(vari *avi, double b)
Definition gamma_q.hpp:32
gamma_q_vv_vari(vari *avi, vari *bvi)
Definition gamma_q.hpp:19
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:19
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 ...