![]() |
Stan Math Library
2.20.0
reverse mode automatic differentiation
|
The coupled_ode_system
template specialization for unknown initial values and unknown parameters.
More...
#include <coupled_ode_system.hpp>
Public Member Functions | |
coupled_ode_system (const F &f, const std::vector< var > &y0, const std::vector< var > &theta, const std::vector< double > &x, const std::vector< int > &x_int, std::ostream *msgs) | |
Construct a coupled ode system from the base system function, initial state of the base system, parameters, and a stream for messages. More... | |
void | operator() (const std::vector< double > &z, std::vector< double > &dz_dt, double t) const |
Calculates the derivative of the coupled ode system with respect to time. More... | |
size_t | size () const |
Returns the size of the coupled system. More... | |
std::vector< double > | initial_state () const |
Returns the initial state of the coupled system. More... | |
Public Attributes | |
const F & | f_ |
const std::vector< var > & | y0_ |
const std::vector< var > & | theta_ |
std::vector< var > | theta_nochain_ |
const std::vector< double > & | x_ |
const std::vector< int > & | x_int_ |
const size_t | N_ |
const size_t | M_ |
const size_t | size_ |
std::ostream * | msgs_ |
The coupled_ode_system
template specialization for unknown initial values and unknown parameters.
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: .
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:
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 theta. The parameter vector theta is 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 parameter vector theta 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 using a dedicated loop.
F | base ode system functor. Must provide operator()(double t, std::vector<var> y, std::vector<var> theta, std::vector<double> x, std::vector<int>x_int, std::ostream* msgs) |
Definition at line 387 of file coupled_ode_system.hpp.
|
inline |
Construct a coupled ode system from the base system function, initial state of the base system, parameters, and a stream for messages.
[in] | f | the base ODE system functor |
[in] | y0 | the initial state of the base ode |
[in] | theta | parameters of the base ode |
[in] | x | real data |
[in] | x_int | integer data |
[in,out] | msgs | stream for messages |
Definition at line 411 of file coupled_ode_system.hpp.
|
inline |
Returns the initial state of the coupled system.
Because the starting state is unknown, the coupled system incorporates the initial conditions as parameters. At the initial time the Jacobian of the integrated function is the identity matrix. In addition the coupled system includes the Jacobian of the integrated function wrt to the parameters. This Jacobian is zero at the initial time-point.
Definition at line 521 of file coupled_ode_system.hpp.
|
inline |
Calculates the derivative of the coupled ode system with respect to time.
This method uses nested autodiff and is not thread safe.
[in] | z | state of the coupled ode system; this must be size size() |
[out] | dz_dt | a vector of size size() with the derivatives of the coupled system with respect to time |
[in] | t | time |
exception | if the base ode function does not return the expected number of derivatives, N. |
Definition at line 442 of file coupled_ode_system.hpp.
|
inline |
Returns the size of the coupled system.
Definition at line 501 of file coupled_ode_system.hpp.
const F& stan::math::coupled_ode_system< F, var, var >::f_ |
Definition at line 388 of file coupled_ode_system.hpp.
const size_t stan::math::coupled_ode_system< F, var, var >::M_ |
Definition at line 395 of file coupled_ode_system.hpp.
std::ostream* stan::math::coupled_ode_system< F, var, var >::msgs_ |
Definition at line 397 of file coupled_ode_system.hpp.
const size_t stan::math::coupled_ode_system< F, var, var >::N_ |
Definition at line 394 of file coupled_ode_system.hpp.
const size_t stan::math::coupled_ode_system< F, var, var >::size_ |
Definition at line 396 of file coupled_ode_system.hpp.
const std::vector<var>& stan::math::coupled_ode_system< F, var, var >::theta_ |
Definition at line 390 of file coupled_ode_system.hpp.
std::vector<var> stan::math::coupled_ode_system< F, var, var >::theta_nochain_ |
Definition at line 391 of file coupled_ode_system.hpp.
const std::vector<double>& stan::math::coupled_ode_system< F, var, var >::x_ |
Definition at line 392 of file coupled_ode_system.hpp.
const std::vector<int>& stan::math::coupled_ode_system< F, var, var >::x_int_ |
Definition at line 393 of file coupled_ode_system.hpp.
const std::vector<var>& stan::math::coupled_ode_system< F, var, var >::y0_ |
Definition at line 389 of file coupled_ode_system.hpp.