Automatic Differentiation
 
Loading...
Searching...
No Matches
grad_inc_beta.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_REV_FUN_GRAD_INC_BETA_HPP
2#define STAN_MATH_REV_FUN_GRAD_INC_BETA_HPP
3
19#include <cmath>
20
21namespace stan {
22namespace math {
23
37inline void grad_inc_beta(var& g1, var& g2, const var& a, const var& b,
38 const var& z) {
39 var c1 = log(z);
40 var c2 = log1m(z);
41 var c3 = beta(a, b) * inc_beta(a, b, z);
42 var C = exp(a * c1 + b * c2) / a;
43 var dF1 = 0;
44 var dF2 = 0;
45 var dF3 = 0;
46 var dFz = 0;
47 if (value_of_rec(C)) {
48 std::forward_as_tuple(dF1, dF2, dF3, dFz)
49 = grad_2F1<true>(a + b, var(1.0), a + 1, z);
50 }
51 g1 = (c1 - 1.0 / a) * c3 + C * (dF1 + dF3);
52 g2 = c2 * c3 + C * dF1;
53}
54
55} // namespace math
56} // namespace stan
57#endif
double value_of_rec(const fvar< T > &v)
Return the value of the specified variable.
fvar< T > log(const fvar< T > &x)
Definition log.hpp:15
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:19
var_value< double > var
Definition var.hpp:1187
fvar< T > log1m(const fvar< T > &x)
Definition log1m.hpp:12
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:13
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...