Stan Math Library  2.12.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>
8 #include <cmath>
9 
10 namespace stan {
11  namespace math {
12 
13  template <typename T>
14  inline fvar<T> owens_t(const fvar<T>& x1, const fvar<T>& x2) {
15  using std::exp;
17 
18  T neg_x1_sq_div_2 = -square(x1.val_) * 0.5;
19  T one_p_x2_sq = 1.0 + square(x2.val_);
20  return fvar<T>(owens_t(x1.val_, x2.val_),
21  - x1.d_
22  * (erf(x2.val_ * x1.val_ * INV_SQRT_2)
23  * exp(neg_x1_sq_div_2) * INV_SQRT_TWO_PI * 0.5)
24  + x2.d_ * exp(neg_x1_sq_div_2 * one_p_x2_sq)
25  / (one_p_x2_sq * 2.0 * pi()));
26  }
27 
28  template <typename T>
29  inline fvar<T> owens_t(const double x1, const fvar<T>& x2) {
30  using std::exp;
31 
32  T neg_x1_sq_div_2 = -square(x1) * 0.5;
33  T one_p_x2_sq = 1.0 + square(x2.val_);
34  return fvar<T>(owens_t(x1, x2.val_),
35  x2.d_ * exp(neg_x1_sq_div_2 * one_p_x2_sq)
36  / (one_p_x2_sq * 2.0 * pi()));
37  }
38 
39  template <typename T>
40  inline fvar<T> owens_t(const fvar<T>& x1, const double x2) {
41  using std::exp;
43 
44  T neg_x1_sq_div_2 = -square(x1.val_) * 0.5;
45  return fvar<T>(owens_t(x1.val_, x2),
46  -x1.d_ * (erf(x2 * x1.val_ * INV_SQRT_2)
47  * exp(neg_x1_sq_div_2)
48  * INV_SQRT_TWO_PI * 0.5));
49  }
50 
51  }
52 }
53 #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)
Definition: owens_t.hpp:14
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.