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
11#include <cmath>
12
13namespace stan {
14namespace math {
15
25template <typename T>
26inline fvar<T> owens_t(const fvar<T>& x1, const fvar<T>& x2) {
27 T neg_x1_sq_div_2 = -square(x1.val_) * 0.5;
28 T one_p_x2_sq = 1.0 + square(x2.val_);
29 return fvar<T>(owens_t(x1.val_, x2.val_),
30 -x1.d_
31 * (erf(x2.val_ * x1.val_ * INV_SQRT_TWO)
32 * exp(neg_x1_sq_div_2) * INV_SQRT_TWO_PI * 0.5)
33 + x2.d_ * exp(neg_x1_sq_div_2 * one_p_x2_sq)
34 / (one_p_x2_sq * TWO_PI));
35}
36
45template <typename T>
46inline fvar<T> owens_t(double x1, const fvar<T>& x2) {
47 T neg_x1_sq_div_2 = -square(x1) * 0.5;
48 T one_p_x2_sq = 1.0 + square(x2.val_);
49 return fvar<T>(
50 owens_t(x1, x2.val_),
51 x2.d_ * exp(neg_x1_sq_div_2 * one_p_x2_sq) / (one_p_x2_sq * TWO_PI));
52}
53
62template <typename T>
63inline fvar<T> owens_t(const fvar<T>& x1, double x2) {
64 T neg_x1_sq_div_2 = -square(x1.val_) * 0.5;
65 return fvar<T>(owens_t(x1.val_, x2),
66 -x1.d_
67 * (erf(x2 * x1.val_ * INV_SQRT_TWO) * exp(neg_x1_sq_div_2)
68 * INV_SQRT_TWO_PI * 0.5));
69}
70
71} // namespace math
72} // namespace stan
73#endif
fvar< T > erf(const fvar< T > &x)
Definition erf.hpp:16
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:26
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:15
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