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

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