| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
grad_inc_beta.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_PRIM_SCAL_FUN_GRAD_INC_BETA_HPP
2 #define STAN_MATH_PRIM_SCAL_FUN_GRAD_INC_BETA_HPP
3
4 #include <stan/math/prim/scal/fun/lbeta.hpp>
5 #include <stan/math/prim/scal/fun/log1m.hpp>
6 #include <stan/math/prim/scal/fun/inc_beta.hpp>
7 #include <stan/math/prim/scal/fun/grad_2F1.hpp>
8 #include <cmath>
9
10 namespace stan {
11 namespace math {
12
13 // Gradient of the incomplete beta function beta(a, b, z)
14 // with respect to the first two arguments, using the
15 // equivalence to a hypergeometric function.
16 // See http://dlmf.nist.gov/8.17#ii
17 void grad_inc_beta(double& g1, double& g2, double a, double b, double z) {
18 using stan::math::lbeta;
19 using stan::math::inc_beta;
20 using stan::math::log1m;
21 using stan::math::grad_2F1;
22 using std::exp;
23 using std::log;
24
25 double c1 = log(z);
26 double c2 = log1m(z);
27 double c3 = exp(lbeta(a, b)) * inc_beta(a, b, z);
28 double C = exp(a * c1 + b * c2) / a;
29 double dF1 = 0;
30 double dF2 = 0;
31 if (C) grad_2F1(dF1, dF2, a + b, 1.0, a + 1, z);
32 g1 = (c1 - 1.0 / a) * c3 + C * (dF1 + dF2);
33 g2 = c2 * c3 + C * dF1;
34 }
35
36 }
37 }
38 #endif
stan::math::lbeta
fvar< T > lbeta(const fvar< T > &x1, const fvar< T > &x2)
Definition: lbeta.hpp:16
stan::math::log
fvar< T > log(const fvar< T > &x)
Definition: log.hpp:15
stan::math::inc_beta
fvar< T > inc_beta(const fvar< T > &a, const fvar< T > &b, const fvar< T > &x)
Definition: inc_beta.hpp:20
stan::math::grad_inc_beta
void grad_inc_beta(stan::math::fvar< T > &g1, stan::math::fvar< T > &g2, stan::math::fvar< T > a, stan::math::fvar< T > b, stan::math::fvar< T > z)
Definition: grad_inc_beta.hpp:24
stan::math::exp
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
grad_2F1.hpp
log1m.hpp
lbeta.hpp
inc_beta.hpp
stan::math::log1m
fvar< T > log1m(const fvar< T > &x)
Definition: log1m.hpp:16
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:13

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