Skip to content

Instantly share code, notes, and snippets.

@bbbales2
Created September 8, 2017 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bbbales2/52e3daff2a46d18e152aaac7b3ea913a to your computer and use it in GitHub Desktop.
Save bbbales2/52e3daff2a46d18e152aaac7b3ea913a to your computer and use it in GitHub Desktop.
Forward mode Jacobian
for(int i = 0; i < y.size(); i++) {
if(i > 0)
y_var[i - 1].d_ = 0.0;
y_var[i].d_ = 1.0;
vector<fvar<double> > dy_dt_var = f_(t, y_var, thetavar, x_, x_int_, msgs_);
if(i == 0) {
for(int j = 0; j < y.size(); j++) {
dy_dt(j) = dy_dt_var[j].val();
}
}
for(int j = 0; j < y.size(); j++)
Jy(j, i) = dy_dt_var[j].tangent();
}
y_var[y.size() - 1].d_ = 0.0;
for(int i = 0; i < theta_.size(); i++) {
if(i > 0)
thetavar[i - 1].d_ = 0.0;
thetavar[i].d_ = 1.0;
vector<fvar<double> > dy = f_(t, y_var, thetavar, x_, x_int_, msgs_);
for(int j = 0; j < dy.size(); j++)
Jtheta(j, i) = dy[j].tangent();
}
@bbbales2
Copy link
Author

bbbales2 commented Sep 8, 2017

This goes in: stan/math/rev/mat/functor/ode_system.hpp in the:

template <typename Derived1, typename Derived2>
      inline void jacobian(double t, const std::vector<double>& y,
                           Eigen::MatrixBase<Derived1>& dy_dt,
                           Eigen::MatrixBase<Derived2>& Jy,
                           Eigen::MatrixBase<Derived2>& Jtheta)

function signature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment