Stan Math Library  2.20.0
reverse mode automatic differentiation
grad_inc_beta.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_SCAL_FUN_GRAD_INC_BETA_HPP
2 #define STAN_MATH_FWD_SCAL_FUN_GRAD_INC_BETA_HPP
3 
4 #include <stan/math/fwd/meta.hpp>
11 #include <stan/math/fwd/core.hpp>
14 #include <cmath>
15 
16 namespace stan {
17 namespace math {
18 
33 template <typename T>
35  fvar<T> c1 = log(z);
36  fvar<T> c2 = log1m(z);
37  fvar<T> c3 = beta(a, b) * inc_beta(a, b, z);
38 
39  fvar<T> C = exp(a * c1 + b * c2) / a;
40 
41  fvar<T> dF1 = 0;
42  fvar<T> dF2 = 0;
43 
44  if (value_of(value_of(C)))
45  grad_2F1(dF1, dF2, a + b, fvar<T>(1.0), a + 1, z);
46 
47  g1 = (c1 - 1.0 / a) * c3 + C * (dF1 + dF2);
48  g2 = c2 * c3 + C * dF1;
49 }
50 
51 } // namespace math
52 } // namespace stan
53 #endif
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition: value_of.hpp:17
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:12
void grad_2F1(T &g_a1, T &g_b1, const T &a1, const T &a2, const T &b1, const T &z, const T &precision=1e-10, int max_steps=1e5)
Gradients of the hypergeometric function, 2F1.
Definition: grad_2F1.hpp:36
void grad_inc_beta(fvar< T > &g1, fvar< T > &g2, fvar< T > a, fvar< T > b, fvar< T > z)
Gradient of the incomplete beta function beta(a, b, z) with respect to the first two arguments...
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
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:11
fvar< T > log1m(const fvar< T > &x)
Definition: log1m.hpp:12
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

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