Stan Math Library
4.8.1
Automatic Differentiation
|
The coupled_ode_system_impl
template specialization when the state or parameters are autodiff types.
This coupled ode system has N + (N + M) * N states where N is the size of the base ode system and M is the number of parameters.
For the coupled ode system, the first N states are the base system's states: \( \frac{d x_n}{dt} \).
The next N + M states correspond to the sensitivities of the initial conditions, then to the sensitivities of the parameters with respect to the to the first base system equation. Calling initial conditions \( y0 \) and parameters \( \theta \):
\[ \frac{d x_{N + n}}{dt} = \frac{d}{dt} \frac{\partial x_1}{\partial y0_n} \]
\[ \frac{d x_{N + N + m}}{dt} = \frac{d}{dt} \frac{\partial x_1}{\partial \theta_m} \]
The next N + M states correspond to the sensitivities of the initial conditions followed by the sensitivites of the parameters with respect to the second base system equation, and so on through the last base system equation.
Note: Calculating the sensitivity system requires the Jacobian of the base ODE RHS wrt to the parameters. The parameters are constant for successive calls to the exposed operator(). For this reason, the parameter vector theta is copied upon construction onto the nochain var autodiff tape which is used in the the nested autodiff performed in the operator() of this adaptor. Doing so reduces the size of the nested autodiff and speeds up autodiff. As a side effect, the parameters will remain on the nochain autodiff part of the autodiff tape being in use even after destruction of the given instance. Moreover, the adjoint zeroing for the nested system does not cover the theta parameter vector part of the nochain autodiff tape and is therefore set to zero separately.
F | base ode system functor. Must provide template<typename T_y, typename... T_args> operator()(double t, const Eigen::Matrix<T_y, Eigen::Dynamic, 1>& y,
std::ostream* msgs, const T_args&... args) |
Definition at line 69 of file coupled_ode_system.hpp.
#include <coupled_ode_system.hpp>
Public Member Functions | |
coupled_ode_system_impl (const F &f, const Eigen::Matrix< T_y0, Eigen::Dynamic, 1 > &y0, std::ostream *msgs, const Args &... args) | |
Construct a coupled ode system from the base system function, initial state of the base system, parameters, and a stream for messages. | |
void | operator() (const std::vector< double > &z, std::vector< double > &dz_dt, double t) |
Calculates the right hand side of the coupled ode system (the regular ode system with forward sensitivities). | |
size_t | size () const |
Returns the size of the coupled system. | |
std::vector< double > | initial_state () const |
Returns the initial state of the coupled system. | |
Public Attributes | |
const F & | f_ |
const Eigen::Matrix< T_y0, Eigen::Dynamic, 1 > & | y0_ |
std::tuple< decltype(deep_copy_vars(std::declval< const Args & >()))... > | local_args_tuple_ |
const size_t | num_y0_vars_ |
const size_t | num_args_vars |
const size_t | N_ |
Eigen::VectorXd | args_adjoints_ |
Eigen::VectorXd | y_adjoints_ |
std::ostream * | msgs_ |