Public Member Functions | Public Attributes | List of all members
stan::math::coupled_ode_system< F, double, var > Struct Template Reference

#include "stan/math/rev/arr/functor/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)
 
void operator() (const std::vector< double > &z, std::vector< double > &dz_dt, double t) const
 
size_t size () const
 
std::vector< double > initial_state () const
 
std::vector< std::vector< var > > decouple_states (const std::vector< std::vector< double > > &y) const
 

Public Attributes

const Ff_
 
const std::vector< double > & y0_dbl_
 
const std::vector< var > & theta_
 
const std::vector< double > theta_dbl_
 
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 for known initial values and unknown parameters.

If the base ODE state is size N and there are M parameters, the coupled system has N + N * M states.

The first N states correspond to the base system's N 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} \]

The final M states correspond to the sensitivities with respect to the second base system equation, etc.

Template Parameters
Ftype of functor for the base ode system.

Definition at line 44 of file coupled_ode_system.hpp.

Constructor & Destructor Documentation

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 with the specified base ODE system, base initial state, parameters, data, and a message stream.

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 to which messages are printed.

Definition at line 68 of file coupled_ode_system.hpp.

72  : f_(f),
73  y0_dbl_(y0),
74  theta_(theta),
76  x_(x),
77  x_int_(x_int),
78  N_(y0.size()),
79  M_(theta.size()),
80  size_(N_ + N_ * M_),
81  msgs_(msgs) {}
T value_of(const fvar< T > &v)
Definition: value_of.hpp:16

Member Function Documentation

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

Returns the base ODE system state corresponding to the specified coupled system state.

Parameters
ycoupled states after solving the ode

Definition at line 179 of file coupled_ode_system.hpp.

References MECModelEnuComparisons::i, calib::j, M_, N_, stan::math::precomputed_gradients(), and submit_syst::y.

180  {
181  std::vector<var> temp_vars(N_);
182  std::vector<double> temp_gradients(M_);
183  std::vector<std::vector<var> > y_return(y.size());
184 
185  for (size_t i = 0; i < y.size(); i++) {
186  // iterate over number of equations
187  for (size_t j = 0; j < N_; j++) {
188  // iterate over parameters for each equation
189  for (size_t k = 0; k < M_; k++)
190  temp_gradients[k] = y[i][y0_dbl_.size() + y0_dbl_.size() * k + j];
191 
192  temp_vars[j] = precomputed_gradients(y[i][j], theta_, temp_gradients);
193  }
194  y_return[i] = temp_vars;
195  }
196  return y_return;
197  }
var precomputed_gradients(double value, const std::vector< var > &operands, const std::vector< double > &gradients)
const double j
Definition: BetheBloch.cxx:29
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. Because the initial values are known, the initial state of the coupled system is the same as the initial state of the base ODE system.

This initial state returned is of size size() where the first N (base ODE system size) parameters are the initial conditions of the base ode system and the rest of the initial condition elements are 0.

Returns
the initial condition of the coupled system.

Definition at line 166 of file coupled_ode_system.hpp.

References getGoodRuns4SAM::n, N_, and makeDatasetsPage::state.

166  {
167  std::vector<double> state(size_, 0.0);
168  for (size_t n = 0; n < N_; n++)
169  state[n] = y0_dbl_[n];
170  return state;
171  }
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

Assign the derivative vector with the system derivatives at the specified state and time.

The input state must be of size size(), and the output produced will be of the same size.

Parameters
[in]zstate of the coupled ode system.
[out]dz_dtpopulated with the derivatives of the coupled system at the specified state and time.
[in]ttime.
Exceptions
exceptionif the system function does not return the same number of derivatives as the state vector size.

y is the base ODE system state

Definition at line 100 of file coupled_ode_system.hpp.

References stan::math::check_size_match(), stan::math::e(), stan::math::grad(), MECModelEnuComparisons::i, calib::j, M_, N_, stan::math::recover_memory_nested(), stan::math::set_zero_all_adjoints_nested(), and stan::math::start_nested().

101  {
102  using std::vector;
103 
104  vector<double> grad(N_ + M_);
105 
106  try {
107  start_nested();
108 
109  vector<var> z_vars;
110  z_vars.reserve(N_ + M_);
111 
112  vector<var> y_vars(z.begin(), z.begin() + N_);
113  z_vars.insert(z_vars.end(), y_vars.begin(), y_vars.end());
114 
115  vector<var> theta_vars(theta_dbl_.begin(), theta_dbl_.end());
116  z_vars.insert(z_vars.end(), theta_vars.begin(), theta_vars.end());
117 
118  vector<var> dy_dt_vars = f_(t, y_vars, theta_vars, x_, x_int_, msgs_);
119 
120  check_size_match("coupled_ode_system", "dz_dt", dy_dt_vars.size(),
121  "states", N_);
122 
123  for (size_t i = 0; i < N_; i++) {
124  dz_dt[i] = dy_dt_vars[i].val();
126  dy_dt_vars[i].grad(z_vars, grad);
127 
128  for (size_t j = 0; j < M_; j++) {
129  // orders derivatives by equation (i.e. if there are 2 eqns
130  // (y1, y2) and 2 parameters (a, b), dy_dt will be ordered as:
131  // dy1_dt, dy2_dt, dy1_da, dy2_da, dy1_db, dy2_db
132  double temp_deriv = grad[N_ + j];
133  for (size_t k = 0; k < N_; k++)
134  temp_deriv += z[N_ + N_ * j + k] * grad[k];
135 
136  dz_dt[N_ + i + j * N_] = temp_deriv;
137  }
138  }
139  } catch (const std::exception& e) {
141  throw;
142  }
144  }
static void set_zero_all_adjoints_nested()
::xsd::cxx::tree::exception< char > exception
Definition: Database.h:225
void check_size_match(const char *function, const char *name_i, T_size1 i, const char *name_j, T_size2 j)
static void grad(vari *vi)
Definition: grad.hpp:30
const double j
Definition: BetheBloch.cxx:29
z
Definition: test.py:28
double e()
Definition: constants.hpp:89
static void recover_memory_nested()
static void start_nested()
template<typename F >
size_t stan::math::coupled_ode_system< F, double, var >::size ( void  ) const
inline

Returns the size of the coupled system.

Returns
size of the coupled system.

Definition at line 151 of file coupled_ode_system.hpp.

References size_.

Member Data Documentation

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

Definition at line 45 of file coupled_ode_system.hpp.

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

Definition at line 52 of file coupled_ode_system.hpp.

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

Definition at line 54 of file coupled_ode_system.hpp.

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

Definition at line 51 of file coupled_ode_system.hpp.

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

Definition at line 53 of file coupled_ode_system.hpp.

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

Definition at line 47 of file coupled_ode_system.hpp.

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

Definition at line 48 of file coupled_ode_system.hpp.

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

Definition at line 49 of file coupled_ode_system.hpp.

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

Definition at line 50 of file coupled_ode_system.hpp.

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

Definition at line 46 of file coupled_ode_system.hpp.


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