Stan Math Library  2.20.0
reverse mode automatic differentiation
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/meta.hpp>
5 #include <stan/math/rev/core.hpp>
9 #include <limits>
10 
11 namespace stan {
12 namespace math {
13 
14 namespace internal {
15 
17  public:
19  : op_vv_vari(log_falling_factorial(avi->val_, bvi->val_), avi, bvi) {}
20  void chain() {
21  if (unlikely(is_any_nan(avi_->val_, bvi_->val_))) {
22  avi_->adj_ = std::numeric_limits<double>::quiet_NaN();
23  bvi_->adj_ = std::numeric_limits<double>::quiet_NaN();
24  } else {
25  avi_->adj_
26  += adj_
27  * (digamma(avi_->val_ + 1) - digamma(avi_->val_ - bvi_->val_ + 1));
28  bvi_->adj_ += adj_ * digamma(avi_->val_ - bvi_->val_ + 1);
29  }
30  }
31 };
32 
34  public:
36  : op_vd_vari(log_falling_factorial(avi->val_, b), avi, b) {}
37  void chain() {
38  if (unlikely(is_any_nan(avi_->val_, bd_)))
39  avi_->adj_ = std::numeric_limits<double>::quiet_NaN();
40  else
41  avi_->adj_
42  += adj_ * (digamma(avi_->val_ + 1) - digamma(avi_->val_ - bd_ + 1));
43  }
44 };
45 
47  public:
49  : op_dv_vari(log_falling_factorial(a, bvi->val_), a, bvi) {}
50  void chain() {
51  if (unlikely(is_any_nan(ad_, bvi_->val_)))
52  bvi_->adj_ = std::numeric_limits<double>::quiet_NaN();
53  else
54  bvi_->adj_ += adj_ * digamma(ad_ - bvi_->val_ + 1);
55  }
56 };
57 } // namespace internal
58 
59 inline var log_falling_factorial(const var& a, double b) {
61 }
62 
63 inline var log_falling_factorial(const var& a, const var& b) {
65 }
66 
67 inline var log_falling_factorial(double a, const var& b) {
69 }
70 
71 } // namespace math
72 } // namespace stan
73 #endif
fvar< T > log_falling_factorial(const fvar< T > &x, const fvar< T > &n)
The variable implementation base class.
Definition: vari.hpp:30
bool is_any_nan(const T &x)
Returns true if the input is NaN and false otherwise.
Definition: is_any_nan.hpp:21
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
#define unlikely(x)
Definition: likely.hpp:9
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:45
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 > digamma(const fvar< T > &x)
Return the derivative of the log gamma function at the specified argument.
Definition: digamma.hpp:23
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...

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