Stan Math Library  2.20.0
reverse mode automatic differentiation
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 <stan/math/rev/meta.hpp>
5 #include <stan/math/rev/core.hpp>
10 #include <cmath>
11 
12 namespace stan {
13 namespace math {
14 
15 namespace internal {
16 class owens_t_vv_vari : public op_vv_vari {
17  public:
19  : op_vv_vari(owens_t(avi->val_, bvi->val_), avi, bvi) {}
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 
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(owens_t(avi->val_, b), avi, b) {}
35  void chain() {
36  avi_->adj_ += adj_ * erf(bd_ * avi_->val_ * INV_SQRT_2)
38  * -0.5;
39  }
40 };
41 
42 class owens_t_dv_vari : public op_dv_vari {
43  public:
44  owens_t_dv_vari(double a, vari* bvi)
45  : op_dv_vari(owens_t(a, bvi->val_), a, bvi) {}
46  void chain() {
47  const double one_p_bvi_sq = 1.0 + square(bvi_->val_);
48  bvi_->adj_ += adj_ * std::exp(-0.5 * square(ad_) * one_p_bvi_sq)
49  / (one_p_bvi_sq * 2.0 * pi());
50  }
51 };
52 } // namespace internal
53 
64 inline var owens_t(const var& h, const var& a) {
65  return var(new internal::owens_t_vv_vari(h.vi_, a.vi_));
66 }
67 
78 inline var owens_t(const var& h, double a) {
79  return var(new internal::owens_t_vd_vari(h.vi_, a));
80 }
81 
92 inline var owens_t(double h, const var& a) {
93  return var(new internal::owens_t_dv_vari(h, a.vi_));
94 }
95 
96 } // namespace math
97 } // namespace stan
98 #endif
const double INV_SQRT_TWO_PI
Definition: constants.hpp:142
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
Definition: owens_t.hpp:35
owens_t_vv_vari(vari *avi, vari *bvi)
Definition: owens_t.hpp:18
owens_t_dv_vari(double a, vari *bvi)
Definition: owens_t.hpp:44
The variable implementation base class.
Definition: vari.hpp:30
fvar< T > erf(const fvar< T > &x)
Definition: erf.hpp:15
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:33
friend class var
Definition: vari.hpp:32
const double val_
The value of this variable.
Definition: vari.hpp:38
fvar< T > square(const fvar< T > &x)
Definition: square.hpp:12
fvar< T > owens_t(const fvar< T > &x1, const fvar< T > &x2)
Return Owen&#39;s T function applied to the specified arguments.
Definition: owens_t.hpp:24
owens_t_vd_vari(vari *avi, double b)
Definition: owens_t.hpp:33
const double INV_SQRT_2
The value of 1 over the square root of 2, .
Definition: constants.hpp:31
fvar< T > exp(const fvar< T > &x)
Definition: exp.hpp:11
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:45
double pi()
Return the value of pi.
Definition: constants.hpp:80
double adj_
The adjoint of this variable, which is the partial derivative of this variable with respect to the ro...
Definition: vari.hpp:44
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
Definition: owens_t.hpp:20
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
Definition: owens_t.hpp:46

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