| Stan Math Library 2.6.3 probability, sampling & optimization

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros
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 namespace stan {
12 namespace math {
13
14 namespace {
15 class owens_t_vv_vari : public op_vv_vari {
16 public:
17 owens_t_vv_vari(vari* avi, vari* bvi) :
18 op_vv_vari(boost::math::owens_t(avi->val_, bvi->val_), avi, bvi) {
19 }
20 void chain() {
21 const double neg_avi_sq_div_2 = -square(avi_->val_) * 0.5;
22 const double one_p_bvi_sq = 1.0 + square(bvi_->val_);
23
24 avi_->adj_ += adj_ * ::erf(bvi_->val_ * avi_->val_ * INV_SQRT_2)
25 * std::exp(neg_avi_sq_div_2) * INV_SQRT_TWO_PI * -0.5;
26 bvi_->adj_ += adj_ * std::exp(neg_avi_sq_div_2 * one_p_bvi_sq)
27 / (one_p_bvi_sq * 2.0 * pi());
28 }
29 };
30
31 class owens_t_vd_vari : public op_vd_vari {
32 public:
33 owens_t_vd_vari(vari* avi, double b) :
34 op_vd_vari(boost::math::owens_t(avi->val_, b), avi, b) {
35 }
36 void chain() {
37 avi_->adj_ += adj_ * ::erf(bd_ * avi_->val_ * INV_SQRT_2)
38 * std::exp(-square(avi_->val_) * 0.5)
39 * INV_SQRT_TWO_PI * -0.5;
40 }
41 };
42
43 class owens_t_dv_vari : public op_dv_vari {
44 public:
45 owens_t_dv_vari(double a, vari* bvi) :
46 op_dv_vari(boost::math::owens_t(a, bvi->val_), a, bvi) {
47 }
48 void chain() {
49 const double one_p_bvi_sq = 1.0 + square(bvi_->val_);
50 bvi_->adj_ += adj_ * std::exp(-0.5 * square(ad_) * one_p_bvi_sq)
51 / (one_p_bvi_sq * 2.0 * pi());
52 }
53 };
54 }
55
66 inline var owens_t(const var& h, const var& a) {
67 return var(new owens_t_vv_vari(h.vi_, a.vi_));
68 }
69
80 inline var owens_t(const var& h, double a) {
81 return var(new owens_t_vd_vari(h.vi_, a));
82 }
83
94 inline var owens_t(double h, const var& a) {
95 return var(new owens_t_dv_vari(h, a.vi_));
96 }
97
98 }
99 }
100 #endif
stan::math::INV_SQRT_TWO_PI
const double INV_SQRT_TWO_PI
Definition: constants.hpp:166
core.hpp
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:32
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::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
stan::math::var::vi_
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:44
constants.hpp
stan::math::pi
double pi()
Return the value of pi.
Definition: constants.hpp:86

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