Stan Math Library  2.20.0
reverse mode automatic differentiation
Public Member Functions | Public Attributes | List of all members
stan::math::coupled_ode_system< F, var, var > Struct Template Reference

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< vartheta_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_
 

Detailed Description

template<typename F>
struct stan::math::coupled_ode_system< F, var, var >

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: $ \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:

\[ \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 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.

Template Parameters
Fbase 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.

Constructor & Destructor Documentation

◆ coupled_ode_system()

template<typename F >
stan::math::coupled_ode_system< F, var, var >::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 
)
inline

Construct a coupled ode system from the base system function, initial state of the base system, parameters, and a stream for messages.

Parameters
[in]fthe base ODE system functor
[in]y0the initial state of the base ode
[in]thetaparameters of the base ode
[in]xreal data
[in]x_intinteger data
[in,out]msgsstream for messages

Definition at line 411 of file coupled_ode_system.hpp.

Member Function Documentation

◆ initial_state()

template<typename F >
std::vector<double> stan::math::coupled_ode_system< F, var, var >::initial_state ( ) const
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.

Returns
the initial condition of the coupled system. This is a vector of length size() where the first N values are the initial condition of the base ODE and the next N*N elements correspond to the identity matrix which is the Jacobian of the integrated function at the initial time-point. The last N*M elements are all zero as these are the Jacobian wrt to the parameters at the initial time-point, which is zero.

Definition at line 521 of file coupled_ode_system.hpp.

◆ operator()()

template<typename F >
void stan::math::coupled_ode_system< F, var, var >::operator() ( const std::vector< double > &  z,
std::vector< double > &  dz_dt,
double  t 
) const
inline

Calculates the derivative of the coupled ode system with respect to time.

This method uses nested autodiff and is not thread safe.

Parameters
[in]zstate of the coupled ode system; this must be size size()
[out]dz_dta vector of size size() with the derivatives of the coupled system with respect to time
[in]ttime
Exceptions
exceptionif the base ode function does not return the expected number of derivatives, N.

Definition at line 442 of file coupled_ode_system.hpp.

◆ size()

template<typename F >
size_t stan::math::coupled_ode_system< F, var, var >::size ( ) const
inline

Returns the size of the coupled system.

Returns
size of the coupled system.

Definition at line 501 of file coupled_ode_system.hpp.

Member Data Documentation

◆ f_

template<typename F >
const F& stan::math::coupled_ode_system< F, var, var >::f_

Definition at line 388 of file coupled_ode_system.hpp.

◆ M_

template<typename F >
const size_t stan::math::coupled_ode_system< F, var, var >::M_

Definition at line 395 of file coupled_ode_system.hpp.

◆ msgs_

template<typename F >
std::ostream* stan::math::coupled_ode_system< F, var, var >::msgs_

Definition at line 397 of file coupled_ode_system.hpp.

◆ N_

template<typename F >
const size_t stan::math::coupled_ode_system< F, var, var >::N_

Definition at line 394 of file coupled_ode_system.hpp.

◆ size_

template<typename F >
const size_t stan::math::coupled_ode_system< F, var, var >::size_

Definition at line 396 of file coupled_ode_system.hpp.

◆ theta_

template<typename F >
const std::vector<var>& stan::math::coupled_ode_system< F, var, var >::theta_

Definition at line 390 of file coupled_ode_system.hpp.

◆ theta_nochain_

template<typename F >
std::vector<var> stan::math::coupled_ode_system< F, var, var >::theta_nochain_

Definition at line 391 of file coupled_ode_system.hpp.

◆ x_

template<typename F >
const std::vector<double>& stan::math::coupled_ode_system< F, var, var >::x_

Definition at line 392 of file coupled_ode_system.hpp.

◆ x_int_

template<typename F >
const std::vector<int>& stan::math::coupled_ode_system< F, var, var >::x_int_

Definition at line 393 of file coupled_ode_system.hpp.

◆ y0_

template<typename F >
const std::vector<var>& stan::math::coupled_ode_system< F, var, var >::y0_

Definition at line 389 of file coupled_ode_system.hpp.


The documentation for this struct was generated from the following file:

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