Automatic Differentiation
 
Loading...
Searching...
No Matches
inc_beta.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_FUN_INC_BETA_HPP
2#define STAN_MATH_FWD_FUN_INC_BETA_HPP
3
13#include <cmath>
14
15namespace stan {
16namespace math {
17
18template <typename T>
19inline fvar<T> inc_beta(const fvar<T>& a, const fvar<T>& b, const fvar<T>& x) {
20 using std::pow;
21 T d_a;
22 T d_b;
23 const T beta_ab = beta(a.val_, b.val_);
24 grad_reg_inc_beta(d_a, d_b, a.val_, b.val_, x.val_, digamma(a.val_),
25 digamma(b.val_), digamma(a.val_ + b.val_), beta_ab);
26 T d_x = pow((1 - x.val_), b.val_ - 1) * pow(x.val_, a.val_ - 1) / beta_ab;
27 return fvar<T>(inc_beta(a.val_, b.val_, x.val_),
28 a.d_ * d_a + b.d_ * d_b + x.d_ * d_x);
29}
30
31template <typename T>
32inline fvar<T> inc_beta(double a, const fvar<T>& b, const fvar<T>& x) {
33 return inc_beta(fvar<T>(a), b, x);
34}
35template <typename T>
36inline fvar<T> inc_beta(const fvar<T>& a, double b, const fvar<T>& x) {
37 return inc_beta(a, fvar<T>(b), x);
38}
39template <typename T>
40inline fvar<T> inc_beta(const fvar<T>& a, const fvar<T>& b, double x) {
41 return inc_beta(a, b, fvar<T>(x));
42}
43
44template <typename T>
45inline fvar<T> inc_beta(double a, double b, const fvar<T>& x) {
46 return inc_beta(fvar<T>(a), fvar<T>(b), x);
47}
48template <typename T>
49inline fvar<T> inc_beta(const fvar<T>& a, double b, double x) {
50 return inc_beta(a, fvar<T>(b), fvar<T>(x));
51}
52template <typename T>
53inline fvar<T> inc_beta(double a, const fvar<T>& b, double x) {
54 return inc_beta(fvar<T>(a), b, fvar<T>(x));
55}
56
57} // namespace math
58} // namespace stan
59
60#endif
auto pow(const T1 &x1, const T2 &x2)
Definition pow.hpp:32
void grad_reg_inc_beta(T &g1, T &g2, const T &a, const T &b, const T &z, const T &digammaA, const T &digammaB, const T &digammaSum, const T &betaAB)
Computes the gradients of the regularized incomplete beta function.
fvar< T > inc_beta(const fvar< T > &a, const fvar< T > &b, const fvar< T > &x)
Definition inc_beta.hpp:19
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 > digamma(const fvar< T > &x)
Return the derivative of the log gamma function at the specified argument.
Definition digamma.hpp:23
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...
Scalar val_
The value of this variable.
Definition fvar.hpp:49
Scalar d_
The tangent (derivative) of this variable.
Definition fvar.hpp:61
This template class represents scalars used in forward-mode automatic differentiation,...
Definition fvar.hpp:40