Automatic Differentiation
 
Loading...
Searching...
No Matches
lbeta.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_LBETA_HPP
2#define STAN_MATH_REV_FUN_LBETA_HPP
3
8
9namespace stan {
10namespace math {
11
12namespace internal {
13class lbeta_vv_vari : public op_vv_vari {
14 public:
16 : op_vv_vari(lbeta(avi->val_, bvi->val_), avi, bvi) {}
17 void chain() {
18 const double digamma_ab = digamma(avi_->val_ + bvi_->val_);
19 avi_->adj_ += adj_ * (digamma(avi_->val_) - digamma_ab);
20
21 bvi_->adj_ += adj_ * (digamma(bvi_->val_) - digamma_ab);
22 }
23};
24
25class lbeta_vd_vari : public op_vd_vari {
26 public:
27 lbeta_vd_vari(vari* avi, double b)
28 : op_vd_vari(lbeta(avi->val_, b), avi, b) {}
29 void chain() {
30 avi_->adj_ += adj_ * (digamma(avi_->val_) - digamma(avi_->val_ + bd_));
31 }
32};
33
34class lbeta_dv_vari : public op_dv_vari {
35 public:
36 lbeta_dv_vari(double a, vari* bvi)
37 : op_dv_vari(lbeta(a, bvi->val_), a, bvi) {}
38 void chain() {
39 bvi_->adj_ += adj_ * (digamma(bvi_->val_) - digamma(ad_ + bvi_->val_));
40 }
41};
42} // namespace internal
43
64inline var lbeta(const var& a, const var& b) {
65 return var(new internal::lbeta_vv_vari(a.vi_, b.vi_));
66}
67
83inline var lbeta(const var& a, double b) {
84 return var(new internal::lbeta_vd_vari(a.vi_, b));
85}
86
102inline var lbeta(double a, const var& b) {
103 return var(new internal::lbeta_dv_vari(a, b.vi_));
104}
105
106} // namespace math
107} // namespace stan
108#endif
lbeta_dv_vari(double a, vari *bvi)
Definition lbeta.hpp:36
lbeta_vd_vari(vari *avi, double b)
Definition lbeta.hpp:27
lbeta_vv_vari(vari *avi, vari *bvi)
Definition lbeta.hpp:15
fvar< T > lbeta(const fvar< T > &x1, const fvar< T > &x2)
Definition lbeta.hpp:14
var_value< double > var
Definition var.hpp:1187
fvar< T > digamma(const fvar< T > &x)
Return the derivative of the log gamma function at the specified argument.
Definition digamma.hpp:23
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...