All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Groups
owens_t.hpp
Go to the documentation of this file.
#ifndef STAN_MATH_REV_SCAL_FUN_OWENS_T_HPP
#define STAN_MATH_REV_SCAL_FUN_OWENS_T_HPP
#include <math.h>
#include <stan/math/rev/core.hpp>
#include <stan/math/prim/scal/fun/constants.hpp>
#include <stan/math/prim/scal/fun/square.hpp>
#include <boost/math/special_functions/owens_t.hpp>
#include <cmath>
#ifdef _MSC_VER
#include <boost/math/special_functions/erf.hpp>
using boost::math::erf;
#endif
namespace stan {
namespace math {
namespace {
class owens_t_vv_vari : public op_vv_vari {
public:
owens_t_vv_vari(vari* avi, vari* bvi) :
op_vv_vari(boost::math::owens_t(avi->val_, bvi->val_), avi, bvi) {
}
void chain() {
const double neg_avi_sq_div_2 = -square(avi_->val_) * 0.5;
const double one_p_bvi_sq = 1.0 + square(bvi_->val_);
avi_->adj_ += adj_ * ::erf(bvi_->val_ * avi_->val_ * INV_SQRT_2)
* std::exp(neg_avi_sq_div_2) * INV_SQRT_TWO_PI * -0.5;
bvi_->adj_ += adj_ * std::exp(neg_avi_sq_div_2 * one_p_bvi_sq)
/ (one_p_bvi_sq * 2.0 * pi());
}
};
class owens_t_vd_vari : public op_vd_vari {
public:
owens_t_vd_vari(vari* avi, double b) :
op_vd_vari(boost::math::owens_t(avi->val_, b), avi, b) {
}
void chain() {
avi_->adj_ += adj_ * ::erf(bd_ * avi_->val_ * INV_SQRT_2)
* std::exp(-square(avi_->val_) * 0.5)
* INV_SQRT_TWO_PI * -0.5;
}
};
class owens_t_dv_vari : public op_dv_vari {
public:
owens_t_dv_vari(double a, vari* bvi) :
op_dv_vari(boost::math::owens_t(a, bvi->val_), a, bvi) {
}
void chain() {
const double one_p_bvi_sq = 1.0 + square(bvi_->val_);
bvi_->adj_ += adj_ * std::exp(-0.5 * square(ad_) * one_p_bvi_sq)
/ (one_p_bvi_sq * 2.0 * pi());
}
};
}
inline var owens_t(const var& h, const var& a) {
return var(new owens_t_vv_vari(h.vi_, a.vi_));
}
inline var owens_t(const var& h, double a) {
return var(new owens_t_vd_vari(h.vi_, a));
}
inline var owens_t(double h, const var& a) {
return var(new owens_t_dv_vari(h, a.vi_));
}
}
}
#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.