Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

We model a simple susceptible-infectious epidemic in which susceptible persons can get infected from infectious person and thereafter become infectious themselves. We use the model to investigate stochasticity and uncertainty.

Topics:

Objectives:

  • How do agent-based and differential equation models compare?

  • What is the impact of locality in agent-based models?

  • How do we quantify stochasticity in stochastic models?

Loading...
Loading...
Loading...
Loading...
Loading...

We are considering a disease that is transmitted through contact and renders an individual permanently infectious once infected. This simplified picture provides us with a so-called SI (susceptible-infectious) model and can be implemented at both the microscopic (e.g. agent-based) and macroscopic (e.g. system-dynamics / ordinary differential equation) scope. At first, we want to implement the model as an agent-based one.

Conceptual Modelling - Agent-Based Approach

The NN agents of the model represent persons and every agent i=1…Ni=1\dots N has one single binary state infected defining whether it is susceptible (ai(t)=Sa_i(t)=S) or infectious (ai(t)=Ia_i(t)=I) at time / model step tt. Furthermore, the agent has a fixed list of contacts (i.e. other agents) with whom he is in regular contact causing the spread of the pathogen. We want to leave the number and sampling strategy of the contacts open for the parametrisation. However, a fraction of x0x_0 randomly drawn agents will be initialised infectious whereas the others are created susceptible.

The model is updated in discrete time steps of length Δt\Delta t in which every agent selects one randomly drawn neighbor and has a contact with it. If the agent is infectious, there is probability α\alpha that the contact partner will be rendered infectious after the time step. The time-dynamics of the total number of infectious agents is the observable of the model.

Loading...

Monte-Carlo Simulation

Clearly one simulation run is not representative. In order to get an image of the underlying distribution we need to apply Monte-Carlo (MC) simulation and run the simulation several times.

computation time for 16 simulations (single threaded): 2.777491 seconds
Loading...

Since MC runs are (need to be) independent, we may use multi-threading/processing to do this efficiently. In the way this is done below, this only improves runtime if the computation time of one single simulation is long enough. Otherwise, multithreading creates too much overhead.

Note that we used joblib.Parallel and joblib.delayed because of the memory structure of Jupyter notebooks. Also note, that the results are only equivalent if the seeds are assigned to the simulation instances by the main file (as done here).

computation time for 16 simulations (multithreaded): 3.021276 seconds
  → multithreading 0.92 times faster!
Loading...

Uncertainty

The model is ineretly stochastic, meaning that it incorporates a native way to depict uncertainty. However, in case parameters or inputs are also uncertain, it is possible to add additional randomess.

Below we investigate the impact of additional uncertainty w.r. to the initial value and the parameter alpha in form of a triangular distributed random factor X∼Tri(0.7,1.0,1.3)X\sim Tri(0.7,1.0,1.3).

Loading...
Loading...

Prediction Intervals

In the following code cell there are two different approaches to calculate the prediction intervals of future simulation runs.

First, we look at the gaussian approach. For example, roughly 68% of the simulation results should fall in the interval [μ−σ,μ+σ][\mu-\sigma, \mu+\sigma] for every time step. By performing Monte-Carlo simulations, we can calculate the mean μ^\hat\mu and the standard deviation σ^\hat\sigma of the simulation results. However, this approach assumes that our simulation results are normally distributed. Without further statistical tests, this assumption cannot be made.

If we have no knowledge of the underlying distribution, we can still make predictions by looking at quantiles of our simulation results. Assuming we performed enough Monte-Carlo simulations, we can presume that the distribution of the results is representative of the real distribution. Therefore, if 95% of our simulation results lie in a specific interval, it is probable that this will be the case for future simulation runs as well.

Keep in mind that for both of these approaches the reliability of the prediction intervals depends on the number of Monte-Carlo simulations. The more simulations we perform, the more reliable the prediction intervals will be.

Loading...

Early Stopping

Depending on the complexity of the model, Monte-Carlo simulation can be very computationally expensive. It is therefore useful to stop the simulation as soon as the results are stable enough. For further details on the theory underlying this section, see Monte Carlo Simulation.

In the cell below, we start out with a warm-up period where 6 simulations runs are performed regardless of the stopping rule. Afterwards we calculate the necessary statistics after every simulation run and check if the stopping rule is satisfied. If it is, the Monte-Carlo simulation is stopped.

Elapsed time for N = 1000 and p = 0.95 (  63 runs): 5.723105 seconds
Elapsed time for N = 1000 and p = 0.90 (  36 runs): 2.882337 seconds
Elapsed time for N =  100 and p = 0.95 ( 521 runs): 4.237106 seconds
Elapsed time for N =  100 and p = 0.90 ( 351 runs): 2.753829 seconds
Elapsed time for N =   50 and p = 0.95 ( 949 runs): 3.713852 seconds
Elapsed time for N =   50 and p = 0.90 ( 640 runs): 2.036707 seconds
Loading...

Influence of Agent Count

Before we have a look at the influence varying agent-counts have on the simulations results we establish the mean-field model for the ABM approach using ordinary differential equations:

Let I(t)=∣{i:ai(t)=I}∣I(t)=|\{i:a_i(t)=I\}| denote the total number of susceptible agents and S(t)=∣{i:ai(t)=S}∣=N−I(t)S(t)=|\{i:a_i(t)=S\}|=N-I(t) the total number of infectious agents at time tt, then we may apply mean-field theory to derive the differential-equation-model pendent of the agent-based model by looking into the corresponding state-change probabilities of an agent per time. Let Nbh(i)Nbh(i) refer to all agents in the beighborhood of agent ii, then we find from the agent-based model that

P(S→I):=P(ai(t+1)=I∣ai(t)=S)=α⋅P(randomly drawn neighbour is infected)=α⋅P(∣{j:aj(t)=True,j∈Nbh(i)∣∣{j:j∈Nbh(i)}∣)P(S\rightarrow I):=P(a_i(t+1)=I|a_i(t)=S)=\alpha\cdot P(\text{randomly drawn neighbour is infected})=\alpha\cdot P\left(\frac{|\{j:a_j(t)=True,j\in Nbh(i)|}{|\{j:j\in Nbh(i)\}|}\right)

Under the assumption of homogeneous mixing, the likelihood of a neighboured agent to be infected can be approximated by the infection likelihood of an arbitrary agent in the model, which allows to reduce the probability calculation to the macroscopic states S,IS,I:

α⋅P(∣{j:aj(t)=I,j∈Nbh(i)∣∣{j:j∈Nbh(i)}∣)≈α⋅P(∣{j:aj(t)=I}∣∣{j}∣)=αI(t)N.\alpha\cdot P\left(\frac{|\{j:a_j(t)=I,j\in Nbh(i)|}{|\{j:j\in Nbh(i)\}|}\right)\approx \alpha\cdot P\left(\frac{|\{j:a_j(t)=I\}|}{|\{j\}|}\right)=\alpha \frac{I(t)}{N}.

Since the likelihood for the inverse state change P(I→S):=P(ai(t+1)=S∣ai(t)=I)P(I\rightarrow S):=P(a_i(t+1)=S|a_i(t)=I) is zero in the agent-based SI model, we get the mean field equations

dSdt(t)=I(t)P(I→S)−S(t)P(S→I)=−αS(t)I(t)N\frac{dS}{dt}(t)=I(t)P(I\rightarrow S)-S(t)P(S\rightarrow I)=-\alpha S(t)\frac{I(t)}{N}

dIdt(t)=S(t)P(S→I)−I(t)P(I→S)=αS(t)I(t)N\frac{dI}{dt}(t)=S(t)P(S\rightarrow I)-I(t)P(I\rightarrow S)=\alpha S(t)\frac{I(t)}{N}

which can be collapsed into a single equation with S(t)=N−I(t)S(t)=N-I(t) to

dIdt(t)=α(N−I(t))I(t)N.\frac{dI}{dt}(t)=\alpha (N-I(t))\frac{I(t)}{N}.
Loading...

In the following cell we keep the product of MC iterations and agent-count constant and find that increasing the agent-count and increasing the MC iterations have roughly the same effect on how well the mean from the ABM matches the mean-field model results.

Elapsed time for 400 simulations runs and N =   50 agents: 1.834374 seconds
Elapsed time for 200 simulations runs and N =  100 agents: 1.25758 seconds
Elapsed time for  20 simulations runs and N = 1000 agents: 1.409306 seconds
Elapsed time for   4 simulations runs and N = 5000 agents: 1.461782 seconds
Loading...

Influence of Neighbourhood

This time we fix the agent-count to 500 and perform 20 MC iterations. We only vary the neighbourhood from 500 down to 1. Looking at the influence of different neighbourhood we find that the more local effects the ABM has, the more the result diverges from the mean-field model.

Elapsed time for 20 simulations runs and 500 neighbour(s): 3.138742 seconds
Elapsed time for 20 simulations runs and  50 neighbour(s): 0.665406 seconds
Elapsed time for 20 simulations runs and   5 neighbour(s): 0.423097 seconds
Elapsed time for 20 simulations runs and   1 neighbour(s): 0.190452 seconds
Loading...

This development shows the importance of considering local effects and how relevant microscopic models are for this. The provided mean-field model can only depict a situation in which the population is homogeneously mixed and everyone can infect everyone else. While it is not (with reasonable effort) possible to refine the model to any local neighborhood smaller than NN, there is at least a way to construct a (better) mean-field model for the special case with neighborhood 1.

Mean-Field Model for Neighbourhood Size 1

We apply the same logic as for the derivation of the other mean-field model and investigate the likelihood for state changes:

P(S→I)=P(ai(t+1)=I∣ai(t)=S)=α⋅P(neighbour is infected).P(S\rightarrow I)=P(a_i(t+1)=I|a_i(t)=S)=\alpha\cdot P(\text{neighbour is infected}).

The key difference to the first mean-field model is, that the probability to the right does not scale with II but actually remains constant with value x0x_0. The intuition behind this is, that every new infectee can, at most, infect one other agent because the one-dimensional structure of the disease network. The mean-field model

dIdt(t)=αx0(N−I(t))\frac{dI}{dt}(t)=\alpha x_0(N-I(t))

results. We refer to the final section of this notebook for a formal derivation, or, alternatively to Bicher (2017) Chapter 5.3.3, where the mean-field equation is derived from an inifinite coupled system of differential equations.

As seen below, the model only matches the initial upswing of the curve. The reason for this is, that the contact network which is spanned by the agent-neighbour relations, has a high likelihood of not being fully connected or being a tree-structure rather than a linear-loop. This creates unreachable/uninfectable agents and earlier local saturation effects.

Elapsed time for 20 simulations runs and   1 neighbour(s): 0.192434 seconds
Loading...

Formal derivation of the Mean-Field Model for Neighbourhood Size 1

Key for finding the mean-field model is to quantify P(neighbour is infected)P(\text{neighbour is infected}). One way to evaluate this formally is to look at (agent,neighbour) tuples and their states: An agent can only get infectd if the corresponding tuple is in an (S,I)(S,I) state, if the tuple has state (S,S)(S,S) no infection is possible. Let furthermore SI(t),SS(t),IS(t),II(t)SI(t),SS(t),IS(t),II(t) stand for the total number of (agent,neighbour) tuples with states (S,I),(S,S),(I,S),(I,I)(S,I),(S,S),(I,S),(I,I) in the simulation at time tt, then

P(neighbour is infected)=SI(t)S(t).P(\text{neighbour is infected})=\frac{SI(t)}{S(t)}.

We now look at the expected evolution of this ration, when an infection occurs in the model. Clearly, quantity S(t)S(t) is reduced by one, however, there are two possibilities on what happens with the total number of (S,I)(S,I) tuples:

  • case 1: if the agent in the (S,I)(S,I) tuple in which the infection occurs is, itself, neighbour in an (S,S)(S,S) tuple, then the original tuple will become (I,I)(I,I) and the second one will become (S,I)(S,I). As a result, SI(t)SI(t) will remain unchanged.

  • case 2: if the agent in the (S,I)(S,I) tuple in which the infection occurs is, itself, neighbour in an (I,S)(I,S) tuple, then the original tuple will become (I,I)(I,I) and the second one will become (I,I)(I,I) as well. As a result, SI(t)SI(t) will decrease by one.

To compute the expected change of SI(t)/S(t)SI(t)/S(t), we furthermore need to evaluate the probabilities for cases 1 and 2, which can be done by contrasting the numbers of (I,S)(I,S) and (S,S)(S,S) tuples:

P(case 1)=SS(t)SS(t)+IS(t), P(case 2)=IS(t)SS(t)+IS(t).P(\text{case 1})=\frac{SS(t)}{SS(t)+IS(t)},\ P(\text{case 2})=\frac{IS(t)}{SS(t)+IS(t)}.

For symmetry reasons, the number of (S,I)(S,I) tuples is always equal to the number of (I,S)(I,S) tuples, and the sum of (S,I)(S,I) and (S,S)(S,S) tuples is equal to the total number of agents with state SS. Therefore

P(case 1)=SS(t)S(t), P(case 2)=SI(t)S(t).P(\text{case 1})=\frac{SS(t)}{S(t)},\ P(\text{case 2})=\frac{SI(t)}{S(t)}.

We put things together and evaluate the expected value XX of the ratio SI(t)/S(t)SI(t)/S(t) after an infection:

X=P(case 1)SI(t)S(t)−1+P(case 2)SI(t)−1S(t)−1X = P(\text{case 1})\frac{SI(t)}{S(t)-1}+P(\text{case 2})\frac{SI(t)-1}{S(t)-1}

=SS(t)S(t)SI(t)S(t)−1+SI(t)S(t)SI(t)−1S(t)−1=SI(t)S(t)SS(t)+SI(t)−1S(t)−1=SI(t)S(t)S(t)−1S(t)−1=SI(t)S(t)=\frac{SS(t)}{S(t)}\frac{SI(t)}{S(t)-1}+\frac{SI(t)}{S(t)}\frac{SI(t)-1}{S(t)-1}=\frac{SI(t)}{S(t)}\frac{SS(t)+SI(t)-1}{S(t)-1}=\frac{SI(t)}{S(t)}\frac{S(t)-1}{S(t)-1}=\frac{SI(t)}{S(t)}

As a result, the ratio remains constant in expectation and, as said, does not scale with the number of infected.

It remains to determine its value. This can be done by looking at the initial configuration of the model. Since x0⋅Nx_0\cdot N agents are initially rendered infectious and randomly picked from the population, the expected total number of (S,I)(S,I) pairs is precisely N⋅(1−x0)x0N\cdot (1-x_0)x_0 whereas the expected number of susceptible agents is N⋅(1−x0)N\cdot (1-x_0). As a result

E(SI(t)S(t))=SI(0)S(0)=x0.E\left(\frac{SI(t)}{S(t)}\right)=\frac{SI(0)}{S(0)}=x_0.

We finally put things together and setup the mean-field model:

dSdt(t)=−S(t)P(S→I)=−S(t)αSI(t)S(t)=−α⋅x0⋅S(t).\frac{dS}{dt}(t)=-S(t)P(S\rightarrow I)= -S(t)\alpha\frac{SI(t)}{S(t)}=-\alpha \cdot x_0\cdot S(t).

or

dIdt(t)=αx0(N−I(t)).\frac{dI}{dt}(t)=\alpha x_0(N-I(t)).
References
  1. Bicher, M. (2017). Classification of microscopic models with respect to aggregated system behaviour [Phdthesis]. Technische Universität Wien.