Stan Math Library  2.11.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 stan::math::owens_t;
16  using stan::math::pi;
19  using stan::math::square;
20  using std::exp;
22 
23  T neg_x1_sq_div_2 = -square(x1.val_) * 0.5;
24  T one_p_x2_sq = 1.0 + square(x2.val_);
25  return fvar<T>(owens_t(x1.val_, x2.val_),
26  - x1.d_
27  * (erf(x2.val_ * x1.val_ * INV_SQRT_2)
28  * exp(neg_x1_sq_div_2) * INV_SQRT_TWO_PI * 0.5)
29  + x2.d_ * exp(neg_x1_sq_div_2 * one_p_x2_sq)
30  / (one_p_x2_sq * 2.0 * pi()));
31  }
32 
33  template <typename T>
34  inline fvar<T> owens_t(const double x1, const fvar<T>& x2) {
35  using stan::math::owens_t;
36  using stan::math::pi;
37  using stan::math::square;
38  using std::exp;
39 
40  T neg_x1_sq_div_2 = -square(x1) * 0.5;
41  T one_p_x2_sq = 1.0 + square(x2.val_);
42  return fvar<T>(owens_t(x1, x2.val_),
43  x2.d_ * exp(neg_x1_sq_div_2 * one_p_x2_sq)
44  / (one_p_x2_sq * 2.0 * pi()));
45  }
46 
47  template <typename T>
48  inline fvar<T> owens_t(const fvar<T>& x1, const double x2) {
49  using stan::math::owens_t;
50  using stan::math::pi;
51  using stan::math::square;
54  using std::exp;
56 
57  T neg_x1_sq_div_2 = -square(x1.val_) * 0.5;
58  return fvar<T>(owens_t(x1.val_, x2),
59  -x1.d_ * (erf(x2 * x1.val_ * INV_SQRT_2)
60  * exp(neg_x1_sq_div_2)
61  * INV_SQRT_TWO_PI * 0.5));
62  }
63 
64  }
65 }
66 #endif
const double INV_SQRT_TWO_PI
Definition: constants.hpp:166
fvar< T > erf(const fvar< T > &x)
Definition: erf.hpp:14
fvar< T > square(const fvar< T > &x)
Definition: square.hpp:15
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:27
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
double pi()
Return the value of pi.
Definition: constants.hpp:86

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