| Stan Math Library 2.11.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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>
5 #include <stan/math/prim/scal/fun/constants.hpp>
6 #include <stan/math/prim/scal/fun/owens_t.hpp>
7 #include <stan/math/prim/scal/fun/square.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;
17 using stan::math::INV_SQRT_2;
18 using stan::math::INV_SQRT_TWO_PI;
19 using stan::math::square;
20 using std::exp;
21 using ::erf;
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;
52 using stan::math::INV_SQRT_2;
53 using stan::math::INV_SQRT_TWO_PI;
54 using std::exp;
55 using ::erf;
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
stan::math::INV_SQRT_TWO_PI
const double INV_SQRT_TWO_PI
Definition: constants.hpp:166
core.hpp
stan::math::fvar::d_
T d_
Definition: fvar.hpp:15
stan
Definition: log_sum_exp.hpp:8
square.hpp
stan::math::erf
fvar< T > erf(const fvar< T > &x)
Definition: erf.hpp:14
stan::math::square
fvar< T > square(const fvar< T > &x)
Definition: square.hpp:15
stan::math::owens_t
fvar< T > owens_t(const fvar< T > &x1, const fvar< T > &x2)
Definition: owens_t.hpp:14
stan::math::fvar::val_
T val_
Definition: fvar.hpp:14
stan::math::INV_SQRT_2
const double INV_SQRT_2
The value of 1 over the square root of 2, .
Definition: constants.hpp:27
stan::math::exp
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:10
owens_t.hpp
constants.hpp
stan::math::pi
double pi()
Return the value of pi.
Definition: constants.hpp:86
stan::math::fvar
Definition: fvar.hpp:13

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