Stan  2.5.0
probability, sampling & optimization
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
owens_t.hpp
Go to the documentation of this file.
1 #ifndef STAN__AGRAD__FWD__FUNCTIONS__OWENS_T_HPP
2 #define STAN__AGRAD__FWD__FUNCTIONS__OWENS_T_HPP
3 
4 #include <math.h>
6 #include <stan/meta/traits.hpp>
10 
11 namespace stan {
12  namespace agrad {
13 
14  template <typename T>
15  inline
16  fvar<T>
17  owens_t(const fvar<T>& x1, const fvar<T>& x2) {
18  using stan::math::owens_t;
19  using stan::math::pi;
22  using stan::math::square;
23  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 
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 
37  template <typename T>
38  inline
39  fvar<T>
40  owens_t(const double x1, const fvar<T>& x2) {
41  using stan::math::owens_t;
42  using stan::math::pi;
43  using stan::math::square;
44  using std::exp;
45 
46  T neg_x1_sq_div_2 = -square(x1) * 0.5;
47  T one_p_x2_sq = 1.0 + square(x2.val_);
48 
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 
54  template <typename T>
55  inline
56  fvar<T>
57  owens_t(const fvar<T>& x1, const double x2) {
58  using stan::math::owens_t;
59  using stan::math::pi;
60  using stan::math::square;
63  using std::exp;
65 
66  T neg_x1_sq_div_2 = -square(x1.val_) * 0.5;
67 
68  return fvar<T>(owens_t(x1.val_, x2),
69  -x1.d_ * (erf(x2 * x1.val_ * INV_SQRT_2)
70  * exp(neg_x1_sq_div_2)
71  * INV_SQRT_TWO_PI * 0.5));
72  }
73 
74  }
75 }
76 #endif
T square(const T x)
Return the square of the specified argument.
Definition: square.hpp:22
const double INV_SQRT_TWO_PI
Definition: constants.hpp:150
fvar< T > erf(const fvar< T > &x)
Definition: erf.hpp:17
fvar< T > square(const fvar< T > &x)
Definition: square.hpp:15
boost::math::tools::promote_args< T1, T2 >::type owens_t(const T1 &h, const T2 &a)
The Owen's T function of h and a.
Definition: owens_t.hpp:64
fvar< T > owens_t(const fvar< T > &x1, const fvar< T > &x2)
Definition: owens_t.hpp:17
const double INV_SQRT_2
The value of 1 over the square root of 2, .
Definition: constants.hpp:26
double pi()
Return the value of pi.
Definition: constants.hpp:77
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:16

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