Stan Math Library  2.15.0
reverse mode automatic differentiation
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>
6 
7 namespace stan {
8  namespace math {
9 
11  public:
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  };
23  public:
26  avi, b) {
27  }
28  void chain() {
29  avi_->adj_ += adj_ * 2 * (avi_->val_ - bd_);
30  }
31  };
33  public:
36  a, bvi) {
37  }
38  void chain() {
39  bvi_->adj_ -= adj_ * 2 * (ad_ - bvi_->val_);
40  }
41  };
42 
46  inline var squared_distance(const var& a,
47  const var& b) {
48  return var(new scal_squared_distance_vv_vari(a.vi_, b.vi_));
49  }
53  inline var squared_distance(const var& a,
54  double b) {
55  return var(new scal_squared_distance_vd_vari(a.vi_, b));
56  }
60  inline var squared_distance(double a,
61  const var& b) {
62  return var(new scal_squared_distance_dv_vari(a, b.vi_));
63  }
64 
65  }
66 }
67 #endif
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
The variable implementation base class.
Definition: vari.hpp:30
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:30
friend class var
Definition: vari.hpp:32
const double val_
The value of this variable.
Definition: vari.hpp:38
fvar< T > squared_distance(const Eigen::Matrix< fvar< T >, R, C > &v1, const Eigen::Matrix< double, R, C > &v2)
Returns the squared distance between the specified vectors of the same dimensions.
vari * vi_
Pointer to the implementation of this variable.
Definition: var.hpp:42
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
void chain()
Apply the chain rule to this variable based on the variables on which it depends. ...
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 Home Page ] © 2011–2016, Stan Development Team.