StochasticModel< FP, Comp, Pop, Params, Flows > Class Template Reference

CPP API: mio::StochasticModel< FP, Comp, Pop, Params, Flows > Class Template Reference
mio::StochasticModel< FP, Comp, Pop, Params, Flows > Class Template Reference

A CompartmentalModel with an additional get_noise member. More...

#include <stochastic_model.h>

Inheritance diagram for mio::StochasticModel< FP, Comp, Pop, Params, Flows >:
Collaboration diagram for mio::StochasticModel< FP, Comp, Pop, Params, Flows >:

Public Types

using Base = std::conditional_t< std::is_same_v< Flows, void >, CompartmentalModel< FP, Comp, Pop, Params >, FlowModel< FP, Comp, Pop, Params, Flows > >
 

Public Member Functions

virtual void get_noise (Eigen::Ref< const Eigen::VectorX< FP >>, Eigen::Ref< const Eigen::VectorX< FP >>, FP, Eigen::Ref< Eigen::VectorX< FP >>) const
 Calculate random changes to the population at a certain time point. More...
 
RandomNumberGenerator & get_rng () const
 Access the model's RNG. More...
 
FP sample_standard_normal_distribution () const
 Sample a standard normal distributed value from the model's RNG. More...
 
auto white_noise (Eigen::Index size) const
 Sample a vector of independent standard normal distributed values from the model's RNG. More...
 

Private Attributes

RandomNumberGenerator m_rng
 RNG for generating white noise in the get_noise implementation. More...
 

Detailed Description

template<typename FP, class Comp, class Pop, class Params, class Flows = void>
class mio::StochasticModel< FP, Comp, Pop, Params, Flows >

A CompartmentalModel with an additional get_noise member.

Member Typedef Documentation

◆ Base

template<typename FP , class Comp , class Pop , class Params , class Flows = void>
using mio::StochasticModel< FP, Comp, Pop, Params, Flows >::Base = std::conditional_t<std::is_same_v<Flows, void>, CompartmentalModel<FP, Comp, Pop, Params>, FlowModel<FP, Comp, Pop, Params, Flows> >

Member Function Documentation

◆ get_noise()

template<typename FP , class Comp , class Pop , class Params , class Flows = void>
virtual void mio::StochasticModel< FP, Comp, Pop, Params, Flows >::get_noise ( Eigen::Ref< const Eigen::VectorX< FP >>  ,
Eigen::Ref< const Eigen::VectorX< FP >>  ,
FP  ,
Eigen::Ref< Eigen::VectorX< FP >>   
) const
inlinevirtual

Calculate random changes to the population at a certain time point.

This function calculates the random noise part of an SDE model. In general, it represents the result of the deterministic noise matrix multiplied by a white noise vector.

For infectious disease models, the noise matrix usually maps noise contributions from each flow to their respective compartments. In that case, the white noise vector has size #flows. The resulting noise vector must have the same size as the state vector y. This is due to the fact that the integration of SDE models must happen on populations, not flows, as the applied noise can occassionally push compartments into negative values. This can be mitigated by removing negative values and rescaling the population (see map_to_nonnegative), but this mitigation can not (in general) be applied to flows. The noise must still be applied per flow, so both inflow and outflow use the same random value. Otherwise, transitions between compartments would no longer preserve the total population count.

Reimplemented in mio::ssirs::Model< FP >, mio::ssir::Model< FP >, and mio::sseirvv::Model< FP >.

◆ get_rng()

template<typename FP , class Comp , class Pop , class Params , class Flows = void>
RandomNumberGenerator& mio::StochasticModel< FP, Comp, Pop, Params, Flows >::get_rng ( ) const
inline

Access the model's RNG.

◆ sample_standard_normal_distribution()

template<typename FP , class Comp , class Pop , class Params , class Flows = void>
FP mio::StochasticModel< FP, Comp, Pop, Params, Flows >::sample_standard_normal_distribution ( ) const
inline

Sample a standard normal distributed value from the model's RNG.

For a vector of random values, use white_noise. Note that the value is always drawn as a double, and then converted to FP.

Returns
A random value.

◆ white_noise()

template<typename FP , class Comp , class Pop , class Params , class Flows = void>
auto mio::StochasticModel< FP, Comp, Pop, Params, Flows >::white_noise ( Eigen::Index  size) const
inline

Sample a vector of independent standard normal distributed values from the model's RNG.

Parameters
sizeThe size of the vector. Useful for vector arithmetic. For single random values, use sample_standard_normal_distribution.
Returns
A random vector (expression calling sample_standard_normal_distribution for each entry).

Member Data Documentation

◆ m_rng

template<typename FP , class Comp , class Pop , class Params , class Flows = void>
RandomNumberGenerator mio::StochasticModel< FP, Comp, Pop, Params, Flows >::m_rng
mutableprivate

RNG for generating white noise in the get_noise implementation.