| Stan Math Library 2.11.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

rising_factorial.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_SCAL_FUN_RISING_FACTORIAL_HPP
2 #define STAN_MATH_REV_SCAL_FUN_RISING_FACTORIAL_HPP
3
4 #include <stan/math/rev/core.hpp>
5 #include <stan/math/prim/scal/fun/rising_factorial.hpp>
6 #include <boost/math/special_functions/digamma.hpp>
7
8 namespace stan {
9 namespace math {
10
11 namespace {
12
13 class rising_factorial_vv_vari : public op_vv_vari {
14 public:
15 rising_factorial_vv_vari(vari* avi, vari* bvi) :
16 op_vv_vari(stan::math::rising_factorial(avi->val_, bvi->val_),
17 avi, bvi) {
18 }
19 void chain() {
20 avi_->adj_ += adj_
21 * stan::math::rising_factorial(avi_->val_, bvi_->val_)
22 * (boost::math::digamma(avi_->val_ + bvi_->val_)
23 - boost::math::digamma(avi_->val_));
24 bvi_->adj_ += adj_
25 * stan::math::rising_factorial(avi_->val_, bvi_->val_)
26 * boost::math::digamma(bvi_->val_ + avi_->val_);
27 }
28 };
29
30 class rising_factorial_vd_vari : public op_vd_vari {
31 public:
32 rising_factorial_vd_vari(vari* avi, double b) :
33 op_vd_vari(stan::math::rising_factorial(avi->val_, b), avi, b) {
34 }
35 void chain() {
36 avi_->adj_ += adj_ * stan::math::rising_factorial(avi_->val_, bd_)
37 * (boost::math::digamma(avi_->val_ + bd_)
38 - boost::math::digamma(avi_->val_));
39 }
40 };
41
42 class rising_factorial_dv_vari : public op_dv_vari {
43 public:
44 rising_factorial_dv_vari(double a, vari* bvi) :
45 op_dv_vari(stan::math::rising_factorial(a, bvi->val_), a, bvi) {
46 }
47 void chain() {
48 bvi_->adj_ += adj_ * stan::math::rising_factorial(ad_, bvi_->val_)
49 * boost::math::digamma(bvi_->val_ + ad_);
50 }
51 };
52 }
53
54 inline var rising_factorial(const var& a,
55 const double& b) {
56 return var(new rising_factorial_vd_vari(a.vi_, b));
57 }
58
59 inline var rising_factorial(const var& a,
60 const var& b) {
61 return var(new rising_factorial_vv_vari(a.vi_, b.vi_));
62 }
63
64 inline var rising_factorial(const double& a,
65 const var& b) {
66 return var(new rising_factorial_dv_vari(a, b.vi_));
67 }
68 }
69 }
70 #endif
core.hpp
stan
Definition: log_sum_exp.hpp:8
rising_factorial.hpp
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:31
stan::math::var::vi_
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:43
stan::math::rising_factorial
fvar< T > rising_factorial(const fvar< T > &x, const fvar< T > &n)
Definition: rising_factorial.hpp:16
stan::math::digamma
fvar< T > digamma(const fvar< T > &x)
Definition: digamma.hpp:16

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