Stan Math Library  2.12.0
reverse mode automatic differentiation
decouple_ode_states.hpp
Go to the documentation of this file.
1 #ifndef STAN_MATH_REV_ARR_FUN_DECOUPLE_ODE_STATES_HPP
2 #define STAN_MATH_REV_ARR_FUN_DECOUPLE_ODE_STATES_HPP
3 
4 #include <stan/math/rev/core.hpp>
7 #include <vector>
8 
9 namespace stan {
10  namespace math {
11 
33  template <typename T_initial, typename T_param>
34  inline
35  std::vector<std::vector<typename stan::return_type<T_initial,
36  T_param>::type> >
37  decouple_ode_states(const std::vector<std::vector<double> >& y,
38  const std::vector<T_initial>& y0,
39  const std::vector<T_param>& theta) {
40  using std::vector;
41 
42  vector<typename stan::return_type<T_initial, T_param>::type> vars;
43  typedef stan::is_var<T_initial> initial_var;
44  typedef stan::is_var<T_param> param_var;
45 
46  const size_t N = y0.size();
47  const size_t M = theta.size();
48  const size_t S = (initial_var::value ? N : 0)
49  + (param_var::value ? M : 0);
50 
51  vars.reserve(S);
52  if (initial_var::value)
53  vars.insert(vars.end(), y0.begin(), y0.end());
54  if (param_var::value)
55  vars.insert(vars.end(), theta.begin(), theta.end());
56 
57  vector<var> temp_vars(N);
58  vector<double> temp_gradients(S);
59  vector<vector<var> > y_return(y.size());
60 
61  for (size_t i = 0; i < y.size(); ++i) {
62  for (size_t j = 0; j < N; ++j) {
63  for (size_t k = 0; k < S; ++k) {
64  temp_gradients[k] = y[i][N + N * k + j];
65  }
66  temp_vars[j] = precomputed_gradients(y[i][j],
67  vars, temp_gradients);
68  }
69  y_return[i] = temp_vars;
70  }
71  return y_return;
72  }
73 
83  template <>
84  inline
85  std::vector<std::vector<double> >
86  decouple_ode_states(const std::vector<std::vector<double> >& y,
87  const std::vector<double>& y0,
88  const std::vector<double>& theta) {
89  return y;
90  }
91 
92  }
93 }
94 #endif
var precomputed_gradients(const double value, const std::vector< var > &operands, const std::vector< double > &gradients)
This function returns a var for an expression that has the specified value, vector of operands...
Metaprogram to calculate the base scalar return type resulting from promoting all the scalar types of...
Definition: return_type.hpp:19
std::vector< std::vector< typename stan::return_type< T_initial, T_param >::type > > decouple_ode_states(const std::vector< std::vector< double > > &y, const std::vector< T_initial > &y0, const std::vector< T_param > &theta)
Takes sensitivity output from integrators and returns results in precomputed_gradients format...

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