Automatic Differentiation
 
Loading...
Searching...
No Matches
owens_t.hpp
Go to the documentation of this file.
1#ifndef STAN_MATH_FWD_FUN_OWENS_T_HPP
2#define STAN_MATH_FWD_FUN_OWENS_T_HPP
3
10#include <cmath>
11
12namespace stan {
13namespace math {
14
24template <typename T>
25inline fvar<T> owens_t(const fvar<T>& x1, const fvar<T>& x2) {
26 using std::exp;
27
28 T neg_x1_sq_div_2 = -square(x1.val_) * 0.5;
29 T one_p_x2_sq = 1.0 + square(x2.val_);
30 return fvar<T>(owens_t(x1.val_, x2.val_),
31 -x1.d_
32 * (erf(x2.val_ * x1.val_ * INV_SQRT_TWO)
33 * exp(neg_x1_sq_div_2) * INV_SQRT_TWO_PI * 0.5)
34 + x2.d_ * exp(neg_x1_sq_div_2 * one_p_x2_sq)
35 / (one_p_x2_sq * TWO_PI));
36}
37
46template <typename T>
47inline fvar<T> owens_t(double x1, const fvar<T>& x2) {
48 using std::exp;
49
50 T neg_x1_sq_div_2 = -square(x1) * 0.5;
51 T one_p_x2_sq = 1.0 + square(x2.val_);
52 return fvar<T>(
53 owens_t(x1, x2.val_),
54 x2.d_ * exp(neg_x1_sq_div_2 * one_p_x2_sq) / (one_p_x2_sq * TWO_PI));
55}
56
65template <typename T>
66inline fvar<T> owens_t(const fvar<T>& x1, double x2) {
67 using std::exp;
68
69 T neg_x1_sq_div_2 = -square(x1.val_) * 0.5;
70 return fvar<T>(owens_t(x1.val_, x2),
71 -x1.d_
72 * (erf(x2 * x1.val_ * INV_SQRT_TWO) * exp(neg_x1_sq_div_2)
73 * INV_SQRT_TWO_PI * 0.5));
74}
75
76} // namespace math
77} // namespace stan
78#endif
fvar< T > erf(const fvar< T > &x)
Definition erf.hpp:15
static constexpr double INV_SQRT_TWO
The value of 1 over the square root of 2, .
static constexpr double INV_SQRT_TWO_PI
The value of 1 over the square root of , .
fvar< T > owens_t(const fvar< T > &x1, const fvar< T > &x2)
Return Owen's T function applied to the specified arguments.
Definition owens_t.hpp:25
static constexpr double TWO_PI
Twice the value of , .
Definition constants.hpp:62
fvar< T > square(const fvar< T > &x)
Definition square.hpp:12
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 ...
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