| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
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/core.hpp>
5 #include <stan/math/prim/scal/fun/gamma_q.hpp>
6 #include <stan/math/prim/scal/fun/grad_reg_inc_gamma.hpp>
7 #include <boost/math/special_functions/gamma.hpp>
8 #include <boost/math/special_functions/digamma.hpp>
9 #include <valarray>
10
11 namespace stan {
12 namespace math {
13
14 namespace {
15 class gamma_q_vv_vari : public op_vv_vari {
16 public:
17 gamma_q_vv_vari(vari* avi, vari* bvi) :
18 op_vv_vari(stan::math::gamma_q(avi->val_, bvi->val_),
19 avi, bvi) {
20 }
21 void chain() {
22 avi_->adj_ += adj_
23 * stan::math::grad_reg_inc_gamma(avi_->val_, bvi_->val_,
24 boost::math::tgamma(avi_->val_),
25 boost::math::digamma(avi_->val_));
26 bvi_->adj_ -= adj_
27 * boost::math::gamma_p_derivative(avi_->val_, bvi_->val_);
28 }
29 };
30
31 class gamma_q_vd_vari : public op_vd_vari {
32 public:
33 gamma_q_vd_vari(vari* avi, double b) :
34 op_vd_vari(stan::math::gamma_q(avi->val_, b),
35 avi, b) {
36 }
37 void chain() {
38 avi_->adj_ += adj_
39 * stan::math::grad_reg_inc_gamma(avi_->val_, bd_,
40 boost::math::tgamma(avi_->val_),
41 boost::math::digamma(avi_->val_));
42 }
43 };
44
45 class gamma_q_dv_vari : public op_dv_vari {
46 public:
47 gamma_q_dv_vari(double a, vari* bvi) :
48 op_dv_vari(stan::math::gamma_q(a, bvi->val_),
49 a, bvi) {
50 }
51 void chain() {
52 bvi_->adj_ -= adj_
53 * boost::math::gamma_p_derivative(ad_, bvi_->val_);
54 }
55 };
56 }
57
58 inline var gamma_q(const stan::math::var& a,
59 const stan::math::var& b) {
60 return var(new gamma_q_vv_vari(a.vi_, b.vi_));
61 }
62
63 inline var gamma_q(const stan::math::var& a,
64 const double& b) {
65 return var(new gamma_q_vd_vari(a.vi_, b));
66 }
67
68 inline var gamma_q(const double& a,
69 const stan::math::var& b) {
70 return var(new gamma_q_dv_vari(a, b.vi_));
71 }
72
73 }
74 }
75 #endif
core.hpp
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:32
stan::math::grad_reg_inc_gamma
T grad_reg_inc_gamma(T a, T z, T g, T dig, T precision=1e-6)
Definition: grad_reg_inc_gamma.hpp:15
gamma_q.hpp
stan::math::var::vi_
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:44
grad_reg_inc_gamma.hpp
stan::math::tgamma
fvar< T > tgamma(const fvar< T > &x)
Definition: tgamma.hpp:15
stan::math::gamma_q
fvar< T > gamma_q(const fvar< T > &x1, const fvar< T > &x2)
Definition: gamma_q.hpp:15
stan::math::digamma
fvar< T > digamma(const fvar< T > &x)
Definition: digamma.hpp:16

[ Stan Home Page ] © 2011–2015, Stan Development Team.