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 T d_a;
21 T d_b;
22 const T beta_ab = beta(a.val_, b.val_);
23 grad_reg_inc_beta(d_a, d_b, a.val_, b.val_, x.val_, digamma(a.val_),
24 digamma(b.val_), digamma(a.val_ + b.val_), beta_ab);
25 T d_x = pow((1 - x.val_), b.val_ - 1) * pow(x.val_, a.val_ - 1) / beta_ab;
26 return fvar<T>(inc_beta(a.val_, b.val_, x.val_),
27 a.d_ * d_a + b.d_ * d_b + x.d_ * d_x);
28}
29
30template <typename T>
31inline fvar<T> inc_beta(double a, const fvar<T>& b, const fvar<T>& x) {
32 return inc_beta(fvar<T>(a), b, x);
33}
34template <typename T>
35inline fvar<T> inc_beta(const fvar<T>& a, double b, const fvar<T>& x) {
36 return inc_beta(a, fvar<T>(b), x);
37}
38template <typename T>
39inline fvar<T> inc_beta(const fvar<T>& a, const fvar<T>& b, double x) {
40 return inc_beta(a, b, fvar<T>(x));
41}
42
43template <typename T>
44inline fvar<T> inc_beta(double a, double b, const fvar<T>& x) {
45 return inc_beta(fvar<T>(a), fvar<T>(b), x);
46}
47template <typename T>
48inline fvar<T> inc_beta(const fvar<T>& a, double b, double x) {
49 return inc_beta(a, fvar<T>(b), fvar<T>(x));
50}
51template <typename T>
52inline fvar<T> inc_beta(double a, const fvar<T>& b, double x) {
53 return inc_beta(fvar<T>(a), b, fvar<T>(x));
54}
55
56} // namespace math
57} // namespace stan
58
59#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