Stan Math Library  2.20.0
reverse mode automatic differentiation
lbeta.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_SCAL_FUN_LBETA_HPP
2 #define STAN_MATH_FWD_SCAL_FUN_LBETA_HPP
3 
4 #include <stan/math/fwd/meta.hpp>
5 #include <stan/math/fwd/core.hpp>
6 
7 #include <boost/math/special_functions/digamma.hpp>
9 
10 namespace stan {
11 namespace math {
12 
13 template <typename T>
14 inline fvar<T> lbeta(const fvar<T>& x1, const fvar<T>& x2) {
16  return fvar<T>(lbeta(x1.val_, x2.val_),
17  x1.d_ * digamma(x1.val_) + x2.d_ * digamma(x2.val_)
18  - (x1.d_ + x2.d_) * digamma(x1.val_ + x2.val_));
19 }
20 
21 template <typename T>
22 inline fvar<T> lbeta(double x1, const fvar<T>& x2) {
24  return fvar<T>(lbeta(x1, x2.val_),
25  x2.d_ * digamma(x2.val_) - x2.d_ * digamma(x1 + x2.val_));
26 }
27 
28 template <typename T>
29 inline fvar<T> lbeta(const fvar<T>& x1, double x2) {
31  return fvar<T>(lbeta(x1.val_, x2),
32  x1.d_ * digamma(x1.val_) - x1.d_ * digamma(x1.val_ + x2));
33 }
34 } // namespace math
35 } // namespace stan
36 #endif
T d_
The tangent (derivative) of this variable.
Definition: fvar.hpp:50
fvar< T > lbeta(const fvar< T > &x1, const fvar< T > &x2)
Definition: lbeta.hpp:14
T val_
The value of this variable.
Definition: fvar.hpp:45
This template class represents scalars used in forward-mode automatic differentiation, which consist of values and directional derivatives of the specified template type.
Definition: fvar.hpp:41
fvar< T > digamma(const fvar< T > &x)
Return the derivative of the log gamma function at the specified argument.
Definition: digamma.hpp:23

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