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, double, var > Struct Template Reference

The coupled_ode_system template specialization for known initial values and unknown parameters. More...

#include <coupled_ode_system.hpp>

Public Member Functions

 coupled_ode_system (const F &f, const std::vector< double > &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< double > & y0_dbl_
 
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, double, var >

The coupled_ode_system template specialization for known initial values and unknown parameters.

This coupled ode system has N + N * M 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 M states correspond to the sensitivities of the parameters with respect to the first base system equation:

\[ \frac{d x_{N + m}}{dt} = \frac{d}{dt} \frac{\partial x_1}{\partial \theta_m} \]

for $ m \in {1, \ldots, M} $].

The next M states correspond to the sensitivites 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<double> y, std::vector<var> theta, std::vector<double> x, std::vector<int>x_int, std::ostream* msgs)

Definition at line 59 of file coupled_ode_system.hpp.

Constructor & Destructor Documentation

◆ coupled_ode_system()

template<typename F >
stan::math::coupled_ode_system< F, double, var >::coupled_ode_system ( const F &  f,
const std::vector< double > &  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 83 of file coupled_ode_system.hpp.

Member Function Documentation

◆ initial_state()

template<typename F >
std::vector<double> stan::math::coupled_ode_system< F, double, var >::initial_state ( ) const
inline

Returns the initial state of the coupled system.

The initial state of the coupled ode system is the same as the base ode system. This is because the initial values are known.

There are N + N * M coupled states, where N is the number of base ode system states and M is the number of parameters. The first N correspond to the initial values provided. The next N * M states are all 0.

Returns
the initial condition of the coupled system, a vector of size N + N * M.

Definition at line 181 of file coupled_ode_system.hpp.

◆ operator()()

template<typename F >
void stan::math::coupled_ode_system< F, double, 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 114 of file coupled_ode_system.hpp.

◆ size()

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

Returns the size of the coupled system.

Returns
size of the coupled system.

Definition at line 164 of file coupled_ode_system.hpp.

Member Data Documentation

◆ f_

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

Definition at line 60 of file coupled_ode_system.hpp.

◆ M_

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

Definition at line 67 of file coupled_ode_system.hpp.

◆ msgs_

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

Definition at line 69 of file coupled_ode_system.hpp.

◆ N_

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

Definition at line 66 of file coupled_ode_system.hpp.

◆ size_

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

Definition at line 68 of file coupled_ode_system.hpp.

◆ theta_

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

Definition at line 62 of file coupled_ode_system.hpp.

◆ theta_nochain_

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

Definition at line 63 of file coupled_ode_system.hpp.

◆ x_

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

Definition at line 64 of file coupled_ode_system.hpp.

◆ x_int_

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

Definition at line 65 of file coupled_ode_system.hpp.

◆ y0_dbl_

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

Definition at line 61 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.