1 #ifndef STAN_MATH_REV_SCAL_FUN_IBETA_HPP
2 #define STAN_MATH_REV_SCAL_FUN_IBETA_HPP
6 #include <boost/math/special_functions/digamma.hpp>
7 #include <boost/math/special_functions/gamma.hpp>
18 double ibeta_hypergeometric_helper(
double a,
double b,
double z,
19 double precision = 1
e-8,
20 double max_steps = 1000) {
26 while (
std::abs(diff) > precision && ++k < max_steps) {
35 class ibeta_vvv_vari :
public op_vvv_vari {
37 ibeta_vvv_vari(vari* avi, vari* bvi, vari* xvi) :
38 op_vvv_vari(
ibeta(avi->val_, bvi->val_, xvi->val_),
42 double a = avi_->val_;
43 double b = bvi_->val_;
44 double c = cvi_->val_;
57 * ibeta_hypergeometric_helper(a, 1-b, c);
60 * ibeta_hypergeometric_helper(b, 1-a, 1-c)
64 boost::math::ibeta_derivative(a, b, c);
67 class ibeta_vvd_vari :
public op_vvd_vari {
69 ibeta_vvd_vari(vari* avi, vari* bvi,
double x) :
70 op_vvd_vari(
ibeta(avi->val_, bvi->val_, x), avi, bvi, x) {
73 double a = avi_->val_;
74 double b = bvi_->val_;
88 * ibeta_hypergeometric_helper(a, 1-b, c);
91 * ibeta_hypergeometric_helper(b, 1-a, 1-c)
96 class ibeta_vdv_vari :
public op_vdv_vari {
98 ibeta_vdv_vari(vari* avi,
double b, vari* xvi) :
99 op_vdv_vari(
ibeta(avi->val_, b, xvi->val_), avi, b, xvi) {
102 double a = avi_->val_;
104 double c = cvi_->val_;
117 * ibeta_hypergeometric_helper(a, 1-b, c);
119 boost::math::ibeta_derivative(a, b, c);
122 class ibeta_vdd_vari :
public op_vdd_vari {
124 ibeta_vdd_vari(vari* avi,
double b,
double x) :
125 op_vdd_vari(
ibeta(avi->val_, b, x), avi, b, x) {
128 double a = avi_->val_;
143 * ibeta_hypergeometric_helper(a, 1-b, c);
146 class ibeta_dvv_vari :
public op_dvv_vari {
148 ibeta_dvv_vari(
double a, vari* bvi, vari* xvi) :
149 op_dvv_vari(
ibeta(a, bvi->val_, xvi->val_), a, bvi, xvi) {
153 double b = bvi_->val_;
154 double c = cvi_->val_;
165 * ibeta_hypergeometric_helper(b, 1-a, 1-c)
169 boost::math::ibeta_derivative(a, b, c);
172 class ibeta_dvd_vari :
public op_dvd_vari {
174 ibeta_dvd_vari(
double a, vari* bvi,
double x) :
175 op_dvd_vari(
ibeta(a, bvi->val_, x), a, bvi, x) {
179 double b = bvi_->val_;
191 * ibeta_hypergeometric_helper(b, 1-a, 1-c)
196 class ibeta_ddv_vari :
public op_ddv_vari {
198 ibeta_ddv_vari(
double a,
double b, vari* xvi) :
199 op_ddv_vari(
ibeta(a, b, xvi->val_), a, b, xvi) {
204 double c = cvi_->val_;
207 boost::math::ibeta_derivative(a, b, c);
fvar< T > abs(const fvar< T > &x)
double ibeta(const double a, const double b, const double x)
The normalized incomplete beta function of a, b, and x.
fvar< T > log(const fvar< T > &x)
Independent (input) and dependent (output) variables for gradients.
fvar< T > sin(const fvar< T > &x)
vari * vi_
Pointer to the implementation of this variable.
double e()
Return the base of the natural logarithm.
var ibeta(const var &a, const var &b, const var &x)
The normalized incomplete beta function of a, b, and x.
double pi()
Return the value of pi.
double adj_
The adjoint of this variable, which is the partial derivative of this variable with respect to the ro...
fvar< T > pow(const fvar< T > &x1, const fvar< T > &x2)
fvar< T > tgamma(const fvar< T > &x)
fvar< T > digamma(const fvar< T > &x)