| 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_REV_SCAL_FUN_OWENS_T_HPP
2 #define STAN_MATH_REV_SCAL_FUN_OWENS_T_HPP
3
4 #include <math.h>
5 #include <stan/math/rev/core.hpp>
6 #include <stan/math/prim/scal/fun/constants.hpp>
7 #include <stan/math/prim/scal/fun/square.hpp>
8 #include <boost/math/special_functions/owens_t.hpp>
9 #include <cmath>
10
11 #ifdef _MSC_VER
12 #include <boost/math/special_functions/erf.hpp>
13 using boost::math::erf;
14 #endif
15
16 namespace stan {
17 namespace math {
18
19 namespace {
20 class owens_t_vv_vari : public op_vv_vari {
21 public:
22 owens_t_vv_vari(vari* avi, vari* bvi) :
23 op_vv_vari(boost::math::owens_t(avi->val_, bvi->val_), avi, bvi) {
24 }
25 void chain() {
26 const double neg_avi_sq_div_2 = -square(avi_->val_) * 0.5;
27 const double one_p_bvi_sq = 1.0 + square(bvi_->val_);
28
29 avi_->adj_ += adj_ * ::erf(bvi_->val_ * avi_->val_ * INV_SQRT_2)
30 * std::exp(neg_avi_sq_div_2) * INV_SQRT_TWO_PI * -0.5;
31 bvi_->adj_ += adj_ * std::exp(neg_avi_sq_div_2 * one_p_bvi_sq)
32 / (one_p_bvi_sq * 2.0 * pi());
33 }
34 };
35
36 class owens_t_vd_vari : public op_vd_vari {
37 public:
38 owens_t_vd_vari(vari* avi, double b) :
39 op_vd_vari(boost::math::owens_t(avi->val_, b), avi, b) {
40 }
41 void chain() {
42 avi_->adj_ += adj_ * ::erf(bd_ * avi_->val_ * INV_SQRT_2)
43 * std::exp(-square(avi_->val_) * 0.5)
44 * INV_SQRT_TWO_PI * -0.5;
45 }
46 };
47
48 class owens_t_dv_vari : public op_dv_vari {
49 public:
50 owens_t_dv_vari(double a, vari* bvi) :
51 op_dv_vari(boost::math::owens_t(a, bvi->val_), a, bvi) {
52 }
53 void chain() {
54 const double one_p_bvi_sq = 1.0 + square(bvi_->val_);
55 bvi_->adj_ += adj_ * std::exp(-0.5 * square(ad_) * one_p_bvi_sq)
56 / (one_p_bvi_sq * 2.0 * pi());
57 }
58 };
59 }
60
71 inline var owens_t(const var& h, const var& a) {
72 return var(new owens_t_vv_vari(h.vi_, a.vi_));
73 }
74
85 inline var owens_t(const var& h, double a) {
86 return var(new owens_t_vd_vari(h.vi_, a));
87 }
88
99 inline var owens_t(double h, const var& a) {
100 return var(new owens_t_dv_vari(h, a.vi_));
101 }
102
103 }
104 }
105 #endif
stan::math::INV_SQRT_TWO_PI
const double INV_SQRT_TWO_PI
Definition: constants.hpp:164
core.hpp
boost
Reimplementing boost functionality.
Definition: boost_fpclassify.hpp:7
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::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:30
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::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
stan::math::var::vi_
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:42
constants.hpp
stan::math::pi
double pi()
Return the value of pi.
Definition: constants.hpp:85

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