| Stan Math Library 2.12.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 std::exp;
16 using ::erf;
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;
42 using ::erf;
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
stan::math::INV_SQRT_TWO_PI
const double INV_SQRT_TWO_PI
Definition: constants.hpp:164
core.hpp
stan::math::fvar::d_
T d_
Definition: fvar.hpp:14
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:14
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:13
stan::math::INV_SQRT_2
const double INV_SQRT_2
The value of 1 over the square root of 2, .
Definition: constants.hpp:26
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:85
stan::math::fvar
Definition: fvar.hpp:12

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