| Stan Math Library 2.12.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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/scal/fun/fabs.hpp>
5 #include <stan/math/fwd/scal/fun/log.hpp>
6 #include <stan/math/fwd/scal/fun/log1m.hpp>
7 #include <stan/math/fwd/scal/fun/lbeta.hpp>
8 #include <stan/math/fwd/scal/fun/exp.hpp>
9 #include <stan/math/fwd/scal/fun/value_of.hpp>
10 #include <stan/math/prim/scal/fun/value_of.hpp>
11 #include <stan/math/fwd/core.hpp>
12 #include <stan/math/fwd/scal/fun/inc_beta.hpp>
13 #include <stan/math/prim/scal/fun/grad_2F1.hpp>
14 #include <cmath>
15
16 namespace stan {
17 namespace math {
18
33 template<typename T>
34 void grad_inc_beta(fvar<T>& g1,
35 fvar<T>& g2,
36 fvar<T> a,
37 fvar<T> b,
38 fvar<T> z) {
39 fvar<T> c1 = log(z);
40 fvar<T> c2 = log1m(z);
41 fvar<T> c3 = exp(lbeta(a, b)) * inc_beta(a, b, z);
42
43 fvar<T> C = exp(a * c1 + b * c2) / a;
44
45 fvar<T> dF1 = 0;
46 fvar<T> dF2 = 0;
47
48 if (value_of(value_of(C)))
49 grad_2F1(dF1, dF2, a + b,
50 fvar<T>(1.0),
51 a + 1, z);
52
53 g1 = (c1 - 1.0 / a) * c3 + C * (dF1 + dF2);
54 g2 = c2 * c3 + C * dF1;
55 }
56
57 }
58 }
59 #endif
inc_beta.hpp
core.hpp
log.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::value_of
T value_of(const fvar< T > &v)
Return the value of the specified variable.
Definition: value_of.hpp:16
value_of.hpp
stan::math::lbeta
fvar< T > lbeta(const fvar< T > &x1, const fvar< T > &x2)
Definition: lbeta.hpp:15
stan::math::log
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:14
fabs.hpp
stan::math::grad_inc_beta
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...
Definition: grad_inc_beta.hpp:34
stan::math::inc_beta
fvar< T > inc_beta(const fvar< T > &a, const fvar< T > &b, const fvar< T > &x)
Definition: inc_beta.hpp:19
stan::math::exp
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
grad_2F1.hpp
log1m.hpp
value_of.hpp
exp.hpp
lbeta.hpp
stan::math::log1m
fvar< T > log1m(const fvar< T > &x)
Definition: log1m.hpp:15
stan::math::fvar
Definition: fvar.hpp:12
stan::math::grad_2F1
void grad_2F1(T &gradA, T &gradC, T a, T b, T c, T z, T precision=1e-6)
Definition: grad_2F1.hpp:12

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