| Stan Math Library 2.11.0 reverse mode automatic differentiation

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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>
5 #include <stan/math/prim/scal/meta/return_type.hpp>
6 #include <stan/math/rev/scal/meta/is_var.hpp>
7 #include <vector>
8
9 namespace stan {
10
11 namespace math {
12
34 template <typename T_initial, typename T_param>
35 inline
36 std::vector<std::vector<typename stan::return_type<T_initial,
37 T_param>::type> >
38 decouple_ode_states(const std::vector<std::vector<double> >& y,
39 const std::vector<T_initial>& y0,
40 const std::vector<T_param>& theta) {
41 using std::vector;
42 using stan::math::var;
43 using stan::math::precomputed_gradients;
44
45 vector<typename stan::return_type<T_initial, T_param>::type> vars;
46 typedef stan::is_var<T_initial> initial_var;
47 typedef stan::is_var<T_param> param_var;
48
49 const size_t N = y0.size();
50 const size_t M = theta.size();
51 const size_t S = (initial_var::value ? N : 0)
52 + (param_var::value ? M : 0);
53
54 vars.reserve(S);
55 if (initial_var::value)
56 vars.insert(vars.end(), y0.begin(), y0.end());
57 if (param_var::value)
58 vars.insert(vars.end(), theta.begin(), theta.end());
59
60 vector<var> temp_vars(N);
61 vector<double> temp_gradients(S);
62 vector<vector<var> > y_return(y.size());
63
64 for (size_t i = 0; i < y.size(); ++i) {
65 for (size_t j = 0; j < N; ++j) {
66 for (size_t k = 0; k < S; ++k) {
67 temp_gradients[k] = y[i][N + N * k + j];
68 }
69 temp_vars[j] = precomputed_gradients(y[i][j],
70 vars, temp_gradients);
71 }
72 y_return[i] = temp_vars;
73 }
74 return y_return;
75 }
76
86 template <>
87 inline
88 std::vector<std::vector<double> >
89 decouple_ode_states(const std::vector<std::vector<double> >& y,
90 const std::vector<double>& y0,
91 const std::vector<double>& theta) {
92 return y;
93 }
94
95 }
96 }
97 #endif
stan::math::precomputed_gradients
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...
Definition: precomputed_gradients.hpp:98
core.hpp
stan
Definition: log_sum_exp.hpp:8
stan::is_var
Definition: is_var.hpp:7
stan::return_type
Metaprogram to calculate the base scalar return type resulting from promoting all the scalar types of...
Definition: return_type.hpp:19
stan::math::var
Independent (input) and dependent (output) variables for gradients.
Definition: var.hpp:31
return_type.hpp
stan::math::decouple_ode_states
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...
Definition: decouple_ode_states.hpp:38
is_var.hpp

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