Stan Math Library  2.15.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/core.hpp>
9 #include <cmath>
10 
11 namespace stan {
12  namespace math {
13 
22  template <typename T>
23  inline fvar<T> owens_t(const fvar<T>& x1, const fvar<T>& x2) {
24  using std::exp;
25 
26  T neg_x1_sq_div_2 = -square(x1.val_) * 0.5;
27  T one_p_x2_sq = 1.0 + square(x2.val_);
28  return fvar<T>(owens_t(x1.val_, x2.val_),
29  - x1.d_
30  * (erf(x2.val_ * x1.val_ * INV_SQRT_2)
31  * exp(neg_x1_sq_div_2) * INV_SQRT_TWO_PI * 0.5)
32  + x2.d_ * exp(neg_x1_sq_div_2 * one_p_x2_sq)
33  / (one_p_x2_sq * 2.0 * pi()));
34  }
35 
43  template <typename T>
44  inline fvar<T> owens_t(double x1, const fvar<T>& x2) {
45  using std::exp;
46 
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>(owens_t(x1, x2.val_),
50  x2.d_ * exp(neg_x1_sq_div_2 * one_p_x2_sq)
51  / (one_p_x2_sq * 2.0 * pi()));
52  }
53 
61  template <typename T>
62  inline fvar<T> owens_t(const fvar<T>& x1, double x2) {
63  using std::exp;
64 
65  T neg_x1_sq_div_2 = -square(x1.val_) * 0.5;
66  return fvar<T>(owens_t(x1.val_, x2),
67  -x1.d_ * (erf(x2 * x1.val_ * INV_SQRT_2)
68  * exp(neg_x1_sq_div_2)
69  * INV_SQRT_TWO_PI * 0.5));
70  }
71 
72  }
73 }
74 #endif
const double INV_SQRT_TWO_PI
Definition: constants.hpp:164
fvar< T > erf(const fvar< T > &x)
Definition: erf.hpp:14
fvar< T > square(const fvar< T > &x)
Definition: square.hpp:14
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:23
const double INV_SQRT_2
The value of 1 over the square root of 2, .
Definition: constants.hpp:26
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
double pi()
Return the value of pi.
Definition: constants.hpp:85

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