| Stan Math Library 2.11.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

squared_distance.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_SCAL_FUN_SQUARED_DISTANCE_HPP
2 #define STAN_MATH_REV_SCAL_FUN_SQUARED_DISTANCE_HPP
3
4 #include <stan/math/rev/core.hpp>
5 #include <stan/math/prim/scal/fun/squared_distance.hpp>
6
7 namespace stan {
8 namespace math {
9
10 class scal_squared_distance_vv_vari : public op_vv_vari {
11 public:
12 scal_squared_distance_vv_vari(vari* avi, vari* bvi) :
13 op_vv_vari(stan::math::squared_distance(avi->val_, bvi->val_),
14 avi, bvi) {
15 }
16 void chain() {
17 double diff = avi_->val_ - bvi_->val_;
18 avi_->adj_ += adj_ * 2.0 * diff;
19 bvi_->adj_ -= adj_ * 2.0 * diff;
20 }
21 };
22 class scal_squared_distance_vd_vari : public op_vd_vari {
23 public:
24 scal_squared_distance_vd_vari(vari* avi, double b) :
25 op_vd_vari(stan::math::squared_distance(avi->val_, b),
26 avi, b) {
27 }
28 void chain() {
29 avi_->adj_ += adj_ * 2 * (avi_->val_ - bd_);
30 }
31 };
32 class scal_squared_distance_dv_vari : public op_dv_vari {
33 public:
34 scal_squared_distance_dv_vari(double a, vari* bvi) :
35 op_dv_vari(stan::math::squared_distance(a, bvi->val_),
36 a, bvi) {
37 }
38 void chain() {
39 bvi_->adj_ -= adj_ * 2 * (ad_ - bvi_->val_);
40 }
41 };
42
46 inline var squared_distance(const stan::math::var& a,
47 const stan::math::var& b) {
48 return var(new scal_squared_distance_vv_vari(a.vi_, b.vi_));
49 }
53 inline var squared_distance(const stan::math::var& a,
54 const double& b) {
55 return var(new scal_squared_distance_vd_vari(a.vi_, b));
56 }
60 inline var squared_distance(const double& a,
61 const stan::math::var& b) {
62 return var(new scal_squared_distance_dv_vari(a, b.vi_));
63 }
64 }
65 }
66 #endif
stan::math::op_dv_vari
Definition: dv_vari.hpp:9
stan::math::op_vd_vari::avi_
vari * avi_
Definition: vd_vari.hpp:11
stan::math::scal_squared_distance_vd_vari::chain
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
Definition: squared_distance.hpp:28
core.hpp
stan
Definition: log_sum_exp.hpp:8
stan::math::scal_squared_distance_vd_vari::scal_squared_distance_vd_vari
scal_squared_distance_vd_vari(vari *avi, double b)
Definition: squared_distance.hpp:24
stan::math::vari
The variable implementation base class.
Definition: vari.hpp:30
stan::math::scal_squared_distance_vv_vari
Definition: squared_distance.hpp:10
stan::math::op_dv_vari::ad_
double ad_
Definition: dv_vari.hpp:11
stan::math::scal_squared_distance_vd_vari
Definition: squared_distance.hpp:22
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:31
stan::math::scal_squared_distance_vv_vari::scal_squared_distance_vv_vari
scal_squared_distance_vv_vari(vari *avi, vari *bvi)
Definition: squared_distance.hpp:12
stan::math::squared_distance
stan::math::fvar< T > squared_distance(const Eigen::Matrix< stan::math::fvar< T >, R, C > &v1, const Eigen::Matrix< double, R, C > &v2)
Returns the squared distance between the specified vectors of the same dimensions.
Definition: squared_distance.hpp:30
stan::math::vari::val_
const double val_
The value of this variable.
Definition: vari.hpp:38
stan::math::op_vd_vari::bd_
double bd_
Definition: vd_vari.hpp:12
squared_distance.hpp
stan::math::var::vi_
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:43
stan::math::op_vv_vari::bvi_
vari * bvi_
Definition: vv_vari.hpp:12
stan::math::scal_squared_distance_vv_vari::chain
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
Definition: squared_distance.hpp:16
stan::math::scal_squared_distance_dv_vari::chain
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
Definition: squared_distance.hpp:38
stan::math::scal_squared_distance_dv_vari::scal_squared_distance_dv_vari
scal_squared_distance_dv_vari(double a, vari *bvi)
Definition: squared_distance.hpp:34
stan::math::vari::adj_
double adj_
The adjoint of this variable, which is the partial derivative of this variable with respect to the ro...
Definition: vari.hpp:44
stan::math::op_vv_vari::avi_
vari * avi_
Definition: vv_vari.hpp:11
stan::math::op_dv_vari::bvi_
vari * bvi_
Definition: dv_vari.hpp:12
stan::math::op_vv_vari
Definition: vv_vari.hpp:9
stan::math::scal_squared_distance_dv_vari
Definition: squared_distance.hpp:32
stan::math::op_vd_vari
Definition: vd_vari.hpp:9

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