SIR ModelΒΆ

SIR model is given by

\[\begin{split}&\frac{dS}{dt} = -\frac{\beta IS}{N},\\ &\frac{dI}{dt} = \frac{\beta IS}{N} - \gamma I,\\ &\frac{dR}{dt} = \gamma I.\end{split}\]

As a compartment model, the flow is defined from one compartment into another at a given rate potentially given with an interaction with another variable. Hence, all the dynamics can be summarized by

\[\text{origin} \rightarrow \text{target} : \text{flowrate}\cdot \text{origin}\]

and

\[\text{origin} \rightarrow \text{target} : \text{flowrate}\cdot\text{interaction}\cdot\text{origin}.\]

These can be more concisely summarized as

\[\begin{split}&\text{origin}.\text{target} = \text{flowrate}\\ &\text{origin}.\text{interaction}.\text{target} = \text{flowrate}\end{split}\]

Using this syntax with a struct, we can build an epimodel by:

gamma = 1;
beta_N = 1;

linear.infectious.recovered = gamma;

interaction.susceptible.infectious.infectious = beta_N;

sir_model = epimodel(linear, interaction);

The epimodel class parses and builds the dynamics matrix under the hood. To simulate the dynamics, we need to define a initial distribution.

init_dist.infectious = 1e-4;
init_dist.susceptible = 1 - 1e-4;
sir_model.set_initial_dist(init_dist);

The values that are not fed in are automatically filled in as zero. This is sufficient to simulate the model

sir_model.simulate(10);

where one feed in the length of the simulation (see simulate for one other implicit parameter). Simulation populates the results struct with the simulation results and also fills in time_knots of time of the variables. Hence, for example,

plot(sir_model.time_knots, sir_model.results.susceptible);
title('susceptible');

plots the number of susceptible people.