Skip to content

File agent-meat-state.hpp

FileList > epiworld > agent-meat-state.hpp

Go to the source code of this file

Sampling functions are getting big, so we keep them in a separate file. More...

  • #include "model-bones.hpp"
  • #include "agent-meat-virus-sampling.hpp"
  • #include "config.hpp"

Public Functions

Type Name
void default_update_exposed (Agent< TSeq > * p, Model< TSeq > * m)
void default_update_susceptible (Agent< TSeq > * p, Model< TSeq > * m)
UpdateFun< TSeq > new_state_update_transition (std::vector< std::string > param_names, std::vector< epiworld_fast_uint > target_states)
Factory function to create a state update function based on transition rates.

Detailed Description

Author:

George G. Vega Yon (g.vegayon en gmail)

Version:

0.1

Date:

2022-06-15

Copyright:

Copyright (c) 2022

Public Functions Documentation

function default_update_exposed

template<typename TSeq>
inline void default_update_exposed (
    Agent < TSeq > * p,
    Model < TSeq > * m
) 

function default_update_susceptible

template<typename TSeq>
inline void default_update_susceptible (
    Agent < TSeq > * p,
    Model < TSeq > * m
) 

function new_state_update_transition

Factory function to create a state update function based on transition rates.

template<typename TSeq>
inline UpdateFun < TSeq > new_state_update_transition (
    std::vector< std::string > param_names,
    std::vector< epiworld_fast_uint > target_states
) 

This function creates an UpdateFun that transitions agents between states using named model parameters as per-step transition probabilities. At each time step the generated function reads the current values of the parameters from the model and uses the roulette sampling algorithm to decide whether a transition occurs (and if so, to which target state).

The parameter names must correspond to parameters that have already been added to the model (via Model::add_param()). The target states are specified as integer state codes (the indices returned by Model::add_state()).

Template parameters:

  • TSeq Type of the sequence (default EPI_DEFAULT_TSEQ).

Parameters:

  • param_names Names of the model parameters that hold the transition rates. The i-th name gives the rate for transitioning to the i-th target state.
  • target_states Integer codes of the destination states, in the same order as param_names.

Returns:

An UpdateFun<TSeq> suitable for use with Model::add_state().

Exception:

  • std::logic_error if param_names and target_states differ in size, or if either is empty.

Example: SEIRD model

// E -> I transition
auto update_exposed = new_state_update_transition<int>(
    {"E->I transition rate"},
    {2}  // state code for Infected
);

// I -> R or I -> D transitions
auto update_infected = new_state_update_transition<int>(
    {"I->R transition rate", "I->D transition rate"},
    {3, 4}  // state codes for Recovered and Deceased
);

model.add_state("Susceptible", default_update_susceptible<int>);
model.add_state("Exposed",     update_exposed);
model.add_state("Infected",    update_infected);
model.add_state("Recovered");
model.add_state("Deceased");


The documentation for this class was generated from the following file epiworld-src/include/epiworld/agent-meat-state.hpp