Stan Math Library  2.15.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 <boost/math/special_functions/beta.hpp>
11 #include <stan/math/fwd/core.hpp>
14 
15 namespace stan {
16  namespace math {
17 
18  template<typename T>
19  inline fvar<T> inc_beta(const fvar<T>& a,
20  const fvar<T>& b,
21  const fvar<T>& x) {
22  using std::exp;
23  using std::pow;
24 
25  T d_a; T d_b; T d_x;
26 
27  grad_reg_inc_beta(d_a, d_b, a.val_, b.val_, x.val_,
28  digamma(a.val_), digamma(b.val_),
29  digamma(a.val_+b.val_),
30  exp(lbeta(a.val_, b.val_)));
31  d_x = pow((1-x.val_), b.val_-1)*pow(x.val_, a.val_-1)
32  / exp(lbeta(a.val_, b.val_));
33  return fvar<T>(inc_beta(a.val_, b.val_, x.val_),
34  a.d_ * d_a + b.d_ * d_b + x.d_ * d_x);
35  }
36  }
37 }
38 
39 #endif
fvar< T > lbeta(const fvar< T > &x1, const fvar< T > &x2)
Definition: lbeta.hpp:15
fvar< T > inc_beta(const fvar< T > &a, const fvar< T > &b, const fvar< T > &x)
Definition: inc_beta.hpp:19
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:10
fvar< T > pow(const fvar< T > &x1, const fvar< T > &x2)
Definition: pow.hpp:17
fvar< T > digamma(const fvar< T > &x)
Return the derivative of the log gamma function at the specified argument.
Definition: digamma.hpp:22

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