Stan Math Library  2.20.0
reverse mode automatic differentiation
inc_beta.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_SCAL_FUN_INC_BETA_HPP
2 #define STAN_MATH_FWD_SCAL_FUN_INC_BETA_HPP
3 
4 #include <stan/math/fwd/meta.hpp>
10 #include <stan/math/fwd/core.hpp>
13 
14 namespace stan {
15 namespace math {
16 
17 template <typename T>
18 inline fvar<T> inc_beta(const fvar<T>& a, const fvar<T>& b, const fvar<T>& x) {
19  using std::exp;
20  using std::pow;
21 
22  T d_a;
23  T d_b;
24  T d_x;
25  const T beta_ab = beta(a.val_, b.val_);
26 
27  grad_reg_inc_beta(d_a, d_b, a.val_, b.val_, x.val_, digamma(a.val_),
28  digamma(b.val_), digamma(a.val_ + b.val_), beta_ab);
29  d_x = pow((1 - x.val_), b.val_ - 1) * pow(x.val_, a.val_ - 1) / beta_ab;
30  return fvar<T>(inc_beta(a.val_, b.val_, x.val_),
31  a.d_ * d_a + b.d_ * d_b + x.d_ * d_x);
32 }
33 } // namespace math
34 } // namespace stan
35 
36 #endif
T d_
The tangent (derivative) of this variable.
Definition: fvar.hpp:50
fvar< T > inc_beta(const fvar< T > &a, const fvar< T > &b, const fvar< T > &x)
Definition: inc_beta.hpp:18
fvar< T > beta(const fvar< T > &x1, const fvar< T > &x2)
Return fvar with the beta function applied to the specified arguments and its gradient.
Definition: beta.hpp:51
T val_
The value of this variable.
Definition: fvar.hpp:45
void grad_reg_inc_beta(T &g1, T &g2, const T &a, const T &b, const T &z, const T &digammaA, const T &digammaB, const T &digammaSum, const T &betaAB)
Computes the gradients of the regularized incomplete beta function.
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:11
fvar< T > pow(const fvar< T > &x1, const fvar< T > &x2)
Definition: pow.hpp:16
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.