Stan Math Library
4.9.0
Automatic Differentiation
|
return_type_t< T1, T2 > stan::math::grad_reg_inc_gamma | ( | T1 | a, |
T2 | z, | ||
T1 | g, | ||
T1 | dig, | ||
double | precision = 1e-6 , |
||
int | max_steps = 1e5 |
||
) |
Gradient of the regularized incomplete gamma functions igamma(a, z)
For small z, the gradient is computed via the series expansion; for large z, the series is numerically inaccurate due to cancellation and the asymptotic expansion is used.
T1 | type of the shape parameter |
T2 | type of the location parameter |
a | shape parameter, a > 0 |
z | location z >= 0 |
g | stan::math::tgamma(a) (precomputed value) |
dig | boost::math::digamma(a) (precomputed value) |
precision | required precision; applies to series expansion only |
max_steps | number of steps to take. |
throws | std::domain_error if not converged after max_steps or increment overflows to inf. |
For the asymptotic expansion, the gradient is given by:
\[ \begin{array}{rcl} \Gamma(a, z) & = & z^{a-1}e^{-z} \sum_{k=0}^N \frac{(a-1)_k}{z^k} \qquad , z \gg a\\ Q(a, z) & = & \frac{z^{a-1}e^{-z}}{\Gamma(a)} \sum_{k=0}^N \frac{(a-1)_k}{z^k}\\ (a)_k & = & (a)_{k-1}(a-k)\\ \frac{d}{da} (a)_k & = & (a)_{k-1} + (a-k)\frac{d}{da} (a)_{k-1}\\ \frac{d}{da}Q(a, z) & = & (log(z) - \psi(a)) Q(a, z)\\ && + \frac{z^{a-1}e^{-z}}{\Gamma(a)} \sum_{k=0}^N \left(\frac{d}{da} (a-1)_k\right) \frac{1}{z^k} \end{array} \]
Definition at line 52 of file grad_reg_inc_gamma.hpp.