Stan Math Library  2.20.0
reverse mode automatic differentiation
owens_t.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_FWD_SCAL_FUN_OWENS_T_HPP
2 #define STAN_MATH_FWD_SCAL_FUN_OWENS_T_HPP
3 
4 #include <stan/math/fwd/meta.hpp>
5 #include <stan/math/fwd/core.hpp>
10 #include <cmath>
11 
12 namespace stan {
13 namespace math {
14 
23 template <typename T>
24 inline fvar<T> owens_t(const fvar<T>& x1, const fvar<T>& x2) {
25  using std::exp;
26 
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_2)
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 * 2.0 * pi()));
35 }
36 
44 template <typename T>
45 inline fvar<T> owens_t(double x1, const fvar<T>& x2) {
46  using std::exp;
47 
48  T neg_x1_sq_div_2 = -square(x1) * 0.5;
49  T one_p_x2_sq = 1.0 + square(x2.val_);
50  return fvar<T>(
51  owens_t(x1, x2.val_),
52  x2.d_ * exp(neg_x1_sq_div_2 * one_p_x2_sq) / (one_p_x2_sq * 2.0 * pi()));
53 }
54 
62 template <typename T>
63 inline fvar<T> owens_t(const fvar<T>& x1, double x2) {
64  using std::exp;
65 
66  T neg_x1_sq_div_2 = -square(x1.val_) * 0.5;
67  return fvar<T>(owens_t(x1.val_, x2),
68  -x1.d_
69  * (erf(x2 * x1.val_ * INV_SQRT_2) * exp(neg_x1_sq_div_2)
70  * INV_SQRT_TWO_PI * 0.5));
71 }
72 
73 } // namespace math
74 } // namespace stan
75 #endif
const double INV_SQRT_TWO_PI
Definition: constants.hpp:142
T d_
The tangent (derivative) of this variable.
Definition: fvar.hpp:50
fvar< T > erf(const fvar< T > &x)
Definition: erf.hpp:15
fvar< T > square(const fvar< T > &x)
Definition: square.hpp:12
fvar< T > owens_t(const fvar< T > &x1, const fvar< T > &x2)
Return Owen&#39;s T function applied to the specified arguments.
Definition: owens_t.hpp:24
T val_
The value of this variable.
Definition: fvar.hpp:45
const double INV_SQRT_2
The value of 1 over the square root of 2, .
Definition: constants.hpp:31
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:11
double pi()
Return the value of pi.
Definition: constants.hpp:80
This template class represents scalars used in forward-mode automatic differentiation, which consist of values and directional derivatives of the specified template type.
Definition: fvar.hpp:41

     [ Stan Home Page ] © 2011–2018, Stan Development Team.