Model Class Reference

CPP API: mio::isecir::Model Class Reference

#include <model.h>

Collaboration diagram for mio::isecir::Model:

Public Member Functions

bool check_constraints (ScalarType dt) const
 Checks constraints on model parameters and initial data. More...
 
ScalarType get_global_support_max (ScalarType dt) const
 Getter for the global support_max, i.e. More...
 
int get_initialization_method_compartments () const
 Returns the index of the automatically selected initialization method. More...
 
size_t get_num_agegroups () const
 Getter for number of age groups. More...
 
int get_state_flat_index (Eigen::Index state_idx, AgeGroup agegroup) const
 Returns a flat index for the TimeSeries populations which contains values for the InfectionStates. More...
 
int get_transition_flat_index (Eigen::Index transition_idx, AgeGroup agegroup) const
 Returns a flat index for the TimeSeries transitions which contains values for the InfectionTransitions. More...
 
 Model (TimeSeries< ScalarType > &&transitions_init, CustomIndexArray< ScalarType, AgeGroup > N_init, CustomIndexArray< ScalarType, AgeGroup > deaths_init, size_t num_agegroups, CustomIndexArray< ScalarType, AgeGroup > total_confirmed_cases_init=CustomIndexArray< ScalarType, AgeGroup >())
 Constructor to create an IDE-SECIR model. More...
 
void set_tol_for_support_max (ScalarType new_tol)
 Setter for the tolerance used to calculate the maximum support of the TransitionDistributions. More...
 

Public Attributes

ParameterSet parameters {AgeGroup(m_num_agegroups)}
 ParameterSet of Model Parameters. More...
 
TimeSeries< ScalarTypepopulations
 TimeSeries containing points of time and the corresponding number of. More...
 
CustomIndexArray< ScalarType, AgeGrouptotal_confirmed_cases
 CustomIndexArray that contains the total number of confirmed cases at time t0 for every AgeGroup. More...
 
TimeSeries< ScalarTypetransitions
 TimeSeries containing points of time and the corresponding number of individuals transitioning from. More...
 

Private Types

using ParameterSet = Parameters
 

Private Member Functions

void compute_compartment_from_flows (ScalarType dt, Eigen::Index idx_InfectionState, AgeGroup group, Eigen::Index idx_IncomingFlow, int idx_TransitionDistribution1, int idx_TransitionDistribution2=0)
 Compute the compartment specified in idx_InfectionState at the current time – only using historic flow values and disrespecting potential, previous compartment value. More...
 
void compute_flow (Eigen::Index idx_InfectionTransitions, Eigen::Index idx_IncomingFlow, ScalarType dt, AgeGroup group)
 Computes size of a flow for the current last time value in transitions. More...
 
void compute_flow (Eigen::Index idx_InfectionTransitions, Eigen::Index idx_IncomingFlow, ScalarType dt, Eigen::Index current_time_index, AgeGroup group)
 Computes size of a flow. More...
 
void compute_forceofinfection (ScalarType dt, bool initialization=false)
 Computes force of infection for the current last time in transitions. More...
 
void compute_susceptibles (ScalarType dt)
 Computes number of Susceptibles for the current last time in populations. More...
 
void flows_current_timestep (ScalarType dt)
 Sets all required flows for the current last timestep in transitions. More...
 
void initial_compute_compartments (ScalarType dt)
 Computes the values of compartments at initialization. More...
 
void initial_compute_compartments_infection (ScalarType dt)
 Computes the values of the infection compartments subset at initialization. More...
 
void set_transitiondistributions_derivative (ScalarType dt)
 Setter for the vector m_transitiondistributions_derivative that contains the approximated derivative for all TransitionDistributions for all necessary time points. More...
 
void set_transitiondistributions_in_forceofinfection (ScalarType dt)
 Setter for the vector m_transitiondistributions_in_forceofinfection. More...
 
void set_transitiondistributions_support_max (ScalarType dt)
 Setter for the vector m_transitiondistributions_support_max that contains the support_max for all TransitionDistributions. More...
 
void update_compartment_from_flow (InfectionState infectionState, std::vector< InfectionTransition > const &IncomingFlows, std::vector< InfectionTransition > const &OutgoingFlows, AgeGroup group)
 Updates the values of one compartment using flows. More...
 
void update_compartments ()
 Updates the values of all compartments except Susceptible at initialization. More...
 

Private Attributes

CustomIndexArray< ScalarType, AgeGroupm_forceofinfection
 Force of infection term needed for numerical scheme. More...
 
int m_initialization_method {0}
 Gives the index of the method used for the initialization of the model. More...
 
CustomIndexArray< ScalarType, AgeGroupm_N
 Vector containing the total population size of the considered region for every AgeGroup. More...
 
size_t m_num_agegroups
 Number of Age Groups. More...
 
ScalarType m_tol {1e-10}
 Tolerance used to calculate the maximum support of the TransitionDistributions. More...
 
CustomIndexArray< std::vector< std::vector< ScalarType > >, AgeGroupm_transitiondistributions_derivative
 CustomIndexArray. More...
 
CustomIndexArray< std::vector< std::vector< ScalarType > >, AgeGroupm_transitiondistributions_in_forceofinfection
 CustomIndexArray. More...
 
CustomIndexArray< std::vector< ScalarType >, AgeGroupm_transitiondistributions_support_max
 CustomIndexArray. More...
 

Friends

template<typename EntryType >
IOResult< void > set_initial_flows (Model &model, const ScalarType dt, const std::vector< EntryType > rki_data, const Date date, const CustomIndexArray< ScalarType, AgeGroup > scale_confirmed_cases)
 
class Simulation
 

Member Typedef Documentation

◆ ParameterSet

Constructor & Destructor Documentation

◆ Model()

mio::isecir::Model::Model ( TimeSeries< ScalarType > &&  transitions_init,
CustomIndexArray< ScalarType, AgeGroup N_init,
CustomIndexArray< ScalarType, AgeGroup deaths_init,
size_t  num_agegroups,
CustomIndexArray< ScalarType, AgeGroup total_confirmed_cases_init = CustomIndexArray<ScalarTypeAgeGroup>() 
)

Constructor to create an IDE-SECIR model.

Parameters
[in,out]transitions_initTimeSeries with the initial values of the number of individuals, which transit within one timestep dt from one compartment to another. Possible transitions are specified in InfectionTransitions. Considered time points should have the distance dt. The last time point determines the start time t0 of the simulation. The time history must reach a certain point in the past so that the simulation can be performed. A warning is displayed if the condition is violated.
[in]N_initA vector, containing the populations of the considered region, for every AgeGroup.
[in]deaths_initA vector, containing the total number of deaths at time t0, for every AgeGroup.
[in]num_agegroupsThe number of AgeGroups.
[in]total_confirmed_cases_initA vector, containing the total confirmed cases at time t0 can be set if it should be used for initialization, for every AgeGroup.

Member Function Documentation

◆ check_constraints()

bool mio::isecir::Model::check_constraints ( ScalarType  dt) const

Checks constraints on model parameters and initial data.

Returns
Returns true if one (or more) constraint(s) are not satisfied, otherwise false.

◆ compute_compartment_from_flows()

void mio::isecir::Model::compute_compartment_from_flows ( ScalarType  dt,
Eigen::Index  idx_InfectionState,
AgeGroup  group,
Eigen::Index  idx_IncomingFlow,
int  idx_TransitionDistribution1,
int  idx_TransitionDistribution2 = 0 
)
private

Compute the compartment specified in idx_InfectionState at the current time – only using historic flow values and disrespecting potential, previous compartment value.

The computation is meaningful for all compartments except Susceptible, Recovered and #Death and mostly needed for initialization. For Susceptible, Recovered and Dead, use corresponding alternative functions.

Parameters
[in]dtTime discretization step size.
[in]idx_InfectionStateSpecifies the considered InfectionState
[in]groupThe AgeGroup for which we want to compute.
[in]idx_IncomingFlowSpecifies the index of the incoming flow to InfectionState in transitions.
[in]idx_TransitionDistribution1Specifies the index of the first relevant TransitionDistribution, related to a flow from the considered InfectionState to any other InfectionState. This index is also used for related probability.
[in]idx_TransitionDistribution2Specifies the index of the second relevant TransitionDistribution, related to a flow from the considered InfectionState to any other InfectionState (in most cases to Recovered). Related probability is calculated via 1-probability[idx_TransitionDistribution1]. Sometimes the second index is not needed, e.g., if probability[idx_TransitionDistribution1]=1.

◆ compute_flow() [1/2]

void mio::isecir::Model::compute_flow ( Eigen::Index  idx_InfectionTransitions,
Eigen::Index  idx_IncomingFlow,
ScalarType  dt,
AgeGroup  group 
)
private

Computes size of a flow for the current last time value in transitions.

Computes size of one flow from InfectionTransition, specified in idx_InfectionTransitions, for the current last time value in transitions.

Parameters
[in]idx_InfectionTransitionsSpecifies the considered flow from InfectionTransition.
[in]idx_IncomingFlowIndex of the flow in InfectionTransition, which goes to the considered starting compartment of the flow specified in idx_InfectionTransitions. Size of considered flow is calculated via the value of this incoming flow.
[in]dtTime step to compute flow for.
[in]groupThe Age Group for which we want to compute the flow.

◆ compute_flow() [2/2]

void mio::isecir::Model::compute_flow ( Eigen::Index  idx_InfectionTransitions,
Eigen::Index  idx_IncomingFlow,
ScalarType  dt,
Eigen::Index  current_time_index,
AgeGroup  group 
)
private

Computes size of a flow.

Computes size of one flow from InfectionTransition, specified in idx_InfectionTransitions, for the time index current_time_index.

Parameters
[in]idx_InfectionTransitionsSpecifies the considered flow from InfectionTransition.
[in]idx_IncomingFlowIndex of the flow in InfectionTransition, which goes to the considered starting compartment of the flow specified in idx_InfectionTransitions. Size of considered flow is calculated via the value of this incoming flow.
[in]dtTime step to compute flow for.
[in]current_time_indexThe time index the flow should be computed for.
[in]groupThe Age group for which we want to compute the flow.

◆ compute_forceofinfection()

void mio::isecir::Model::compute_forceofinfection ( ScalarType  dt,
bool  initialization = false 
)
private

Computes force of infection for the current last time in transitions.

Computed value is stored in m_forceofinfection.

Parameters
[in]dtTime discretization step size.
[in]initializationIf true we are in the case of the initialization of the model. For this we need forceofinfection at time point t0-dt and not at the current last time (given by transitions) as in the other time steps.

◆ compute_susceptibles()

void mio::isecir::Model::compute_susceptibles ( ScalarType  dt)
private

Computes number of Susceptibles for the current last time in populations.

Number is computed using previous number of Susceptibles and the force of infection (also from previous timestep). Number is stored at the matching index in populations.

Parameters
[in]dtTime discretization step size.

◆ flows_current_timestep()

void mio::isecir::Model::flows_current_timestep ( ScalarType  dt)
private

Sets all required flows for the current last timestep in transitions.

New values are stored in transitions. Most values are computed via the function compute_flow().

Parameters
[in]dtTime step.

◆ get_global_support_max()

ScalarType mio::isecir::Model::get_global_support_max ( ScalarType  dt) const

Getter for the global support_max, i.e.

the maximum of support_max over all TransitionDistributions.

This determines how many initial values we need for the transitions. It may be possible to run the simulation with fewer time points than the value of the global support_max, but this number ensures that it is possible.

Parameters
[in]dtTime step size.
Returns
Global support_max.

◆ get_initialization_method_compartments()

int mio::isecir::Model::get_initialization_method_compartments ( ) const
inline

Returns the index of the automatically selected initialization method.

The initialization method is selected automatically based on the different values that need to be set beforehand. Infection compartments are always computed through historic flow. Initialization methods for Susceptible and Recovered are tested in the following order: 1.) If a positive number for the total number of confirmed cases is set, Recovered is set according to that value and Susceptibles are derived. 2.) If Susceptibles are set, Recovered will be derived. 3.) If Recovered are set directly, Susceptibles are derived. 4.) If none of the above is set with positive value, the force of infection is used as in Messina et al (2021) to set the Susceptibles.

Returns
Index representing the initialization method.

◆ get_num_agegroups()

size_t mio::isecir::Model::get_num_agegroups ( ) const
inline

Getter for number of age groups.

Returns
Returns number of age groups.

◆ get_state_flat_index()

int mio::isecir::Model::get_state_flat_index ( Eigen::Index  state_idx,
AgeGroup  agegroup 
) const
inline

Returns a flat index for the TimeSeries populations which contains values for the InfectionStates.

In the TimeSeries we store a vector for each time point. In this vector we store values for the different InfectionStates for every AgeGroup. This function is used to get the right index in this vector for a specific AgeGroup and InfectionState.

Parameters
[in]state_idxIndex at which InfectionState we want to evaluate.
[in]agegroupThe agegroup for which we want to evaluate.

◆ get_transition_flat_index()

int mio::isecir::Model::get_transition_flat_index ( Eigen::Index  transition_idx,
AgeGroup  agegroup 
) const
inline

Returns a flat index for the TimeSeries transitions which contains values for the InfectionTransitions.

In the TimeSeries we store a vector for each time point. In this vector we store values for the different InfectionTransitions for every AgeGroup. This function is used to get the right index in this vector for a specific AgeGroup and InfectionTransition.

Parameters
[in]transition_idxIndex determining which InfectionTransition we want to evaluate.
[in]agegroupThe agegroup for which we want to evaluate.

◆ initial_compute_compartments()

void mio::isecir::Model::initial_compute_compartments ( ScalarType  dt)
private

Computes the values of compartments at initialization.

The initialization method is selected automatically based on the different values that need to be set beforehand. Infection compartments are always computed through historic flows. Initialization methods for Susceptible and Recovered are tested in the following order: 1.) If a positive number for the total number of confirmed cases is set, Recovered is set according to that value and Susceptibles are derived. 2.) If Susceptibles are set, Recovered will be derived. 3.) If Recovered are set directly, Susceptibles are derived. 4.) If none of the above is set with positive value, the force of infection is used as in Messina et al (2021) to set the Susceptibles.

The function calculate_compartments_initialization() is used in every method for the compartments Exposed, InfectedNoSymptoms, InfectedSymptoms, InfectedSevere and InfectedCritical. In addition, the force of infection is calculated for start time t_0.

Parameters
[in]dtTime discretization step size.

◆ initial_compute_compartments_infection()

void mio::isecir::Model::initial_compute_compartments_infection ( ScalarType  dt)
private

Computes the values of the infection compartments subset at initialization.

The values for the compartments Exposed, InfectedNoSymptoms, InfectedSymptoms, InfectedSevere and InfectedCritical for time t_0 are calculated using the initial data in form of flows. Calculated values are stored in populations.

Parameters
[in]dtTime discretization step size.

◆ set_tol_for_support_max()

void mio::isecir::Model::set_tol_for_support_max ( ScalarType  new_tol)
inline

Setter for the tolerance used to calculate the maximum support of the TransitionDistributions.

Parameters
[in]new_tolNew tolerance.

◆ set_transitiondistributions_derivative()

void mio::isecir::Model::set_transitiondistributions_derivative ( ScalarType  dt)
private

Setter for the vector m_transitiondistributions_derivative that contains the approximated derivative for all TransitionDistributions for all necessary time points.

The derivative is approximated using a backwards difference scheme. The number of necessary time points for each TransitionDistribution is determined using m_transitiondistributions_support_max.

Parameters
[in]dtTime step size.

◆ set_transitiondistributions_in_forceofinfection()

void mio::isecir::Model::set_transitiondistributions_in_forceofinfection ( ScalarType  dt)
private

Setter for the vector m_transitiondistributions_in_forceofinfection.

When computing the force of infection, we evaluate the survival functions of the TransitionDistributions InfectedNoSymptomsToInfectedSymptoms, InfectedNoSymptomsToRecovered, InfectedSymptomsToInfectedSevere and InfectedSymptomsToRecovered, weighted by the corresponding TransitionProbabilities, at the same time points. Here, we compute these contributions to the force of infection term and store them in the vector m_transitiondistributions_in_forceofinfection so that we can access this vector for all following computations.

Parameters
[in]dtTime step size.

◆ set_transitiondistributions_support_max()

void mio::isecir::Model::set_transitiondistributions_support_max ( ScalarType  dt)
private

Setter for the vector m_transitiondistributions_support_max that contains the support_max for all TransitionDistributions.

This determines how many summands are required when calculating flows, the force of infection or compartments.

Parameters
[in]dtTime step size.

◆ update_compartment_from_flow()

void mio::isecir::Model::update_compartment_from_flow ( InfectionState  infectionState,
std::vector< InfectionTransition > const &  IncomingFlows,
std::vector< InfectionTransition > const &  OutgoingFlows,
AgeGroup  group 
)
private

Updates the values of one compartment using flows.

New value is stored in populations. The value is calculated using the compartment size in the previous time step and the related flows of the current time step. Therefore the flows of the current time step should be calculated before using this function.

◆ update_compartments()

void mio::isecir::Model::update_compartments ( )
private

Updates the values of all compartments except Susceptible at initialization.

New values are stored in populations. The values are calculated using the compartment size in the previous time step and the related flows of the current time step. Therefore the flows of the current time step should be calculated before using this function.

Friends And Related Function Documentation

◆ set_initial_flows

template<typename EntryType >
IOResult<void> set_initial_flows ( Model model,
const ScalarType  dt,
const std::vector< EntryType >  rki_data,
const Date  date,
const CustomIndexArray< ScalarType, AgeGroup scale_confirmed_cases 
)
friend

◆ Simulation

friend class Simulation
friend

Member Data Documentation

◆ m_forceofinfection

CustomIndexArray<ScalarType, AgeGroup> mio::isecir::Model::m_forceofinfection
private

Force of infection term needed for numerical scheme.

◆ m_initialization_method

int mio::isecir::Model::m_initialization_method {0}
private

Gives the index of the method used for the initialization of the model.

◆ m_N

CustomIndexArray<ScalarType, AgeGroup> mio::isecir::Model::m_N
private

Vector containing the total population size of the considered region for every AgeGroup.

◆ m_num_agegroups

size_t mio::isecir::Model::m_num_agegroups
private

Number of Age Groups.

◆ m_tol

ScalarType mio::isecir::Model::m_tol {1e-10}
private

Tolerance used to calculate the maximum support of the TransitionDistributions.

◆ m_transitiondistributions_derivative

CustomIndexArray<std::vector<std::vector<ScalarType> >, AgeGroup> mio::isecir::Model::m_transitiondistributions_derivative
private

◆ m_transitiondistributions_in_forceofinfection

CustomIndexArray<std::vector<std::vector<ScalarType> >, AgeGroup> mio::isecir::Model::m_transitiondistributions_in_forceofinfection
private

◆ m_transitiondistributions_support_max

CustomIndexArray<std::vector<ScalarType>, AgeGroup> mio::isecir::Model::m_transitiondistributions_support_max
private

◆ parameters

ParameterSet mio::isecir::Model::parameters {AgeGroup(m_num_agegroups)}

◆ populations

TimeSeries<ScalarType> mio::isecir::Model::populations

TimeSeries containing points of time and the corresponding number of.

◆ total_confirmed_cases

CustomIndexArray<ScalarType, AgeGroup> mio::isecir::Model::total_confirmed_cases

CustomIndexArray that contains the total number of confirmed cases at time t0 for every AgeGroup.

◆ transitions

TimeSeries<ScalarType> mio::isecir::Model::transitions

TimeSeries containing points of time and the corresponding number of individuals transitioning from.