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

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