Stan Math Library  2.20.0
reverse mode automatic differentiation
gamma_q.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_SCAL_FUN_GAMMA_Q_HPP
2 #define STAN_MATH_REV_SCAL_FUN_GAMMA_Q_HPP
3 
4 #include <stan/math/rev/meta.hpp>
5 #include <stan/math/rev/core.hpp>
10 #include <boost/math/special_functions/gamma.hpp>
11 
12 namespace stan {
13 namespace math {
14 
15 namespace internal {
16 class gamma_q_vv_vari : public op_vv_vari {
17  public:
19  : op_vv_vari(gamma_q(avi->val_, bvi->val_), avi, bvi) {}
20  void chain() {
21  avi_->adj_ += adj_
24  bvi_->adj_
25  -= adj_ * boost::math::gamma_p_derivative(avi_->val_, bvi_->val_);
26  }
27 };
28 
29 class gamma_q_vd_vari : public op_vd_vari {
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_
36  digamma(avi_->val_));
37  }
38 };
39 
40 class gamma_q_dv_vari : public op_dv_vari {
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 
50 inline var gamma_q(const var& a, const var& b) {
51  return var(new internal::gamma_q_vv_vari(a.vi_, b.vi_));
52 }
53 
54 inline var gamma_q(const var& a, double b) {
55  return var(new internal::gamma_q_vd_vari(a.vi_, b));
56 }
57 
58 inline 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
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
Definition: gamma_q.hpp:44
The variable implementation base class.
Definition: vari.hpp:30
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
Definition: gamma_q.hpp:33
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
return_type< T1, T2 >::type 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)
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: gamma_q.hpp:20
gamma_q_vd_vari(vari *avi, double b)
Definition: gamma_q.hpp:31
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 > tgamma(const fvar< T > &x)
Return the result of applying the gamma function to the specified argument.
Definition: tgamma.hpp:21
gamma_q_vv_vari(vari *avi, vari *bvi)
Definition: gamma_q.hpp:18
fvar< T > gamma_q(const fvar< T > &x1, const fvar< T > &x2)
Definition: gamma_q.hpp:13
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.