A virus propagation simulation
About
This is a simulation of a simplified model of epidemic response which attempts to account for both dynamics of disease propagation, the saturation of the healthcare system, and the effect of policy responses. The default parameters and the choice of policies attempt to describe the current Covid-19 crisis.
The user interface allows users to choose when to set policies as a response to the development of the disease and to vary multiple parameters.
The simulation can be viewed as an educational tool, and allows to visualize the impact of the pandemic as a function of both policy choices and yet unknown characteristics of the disease. However please do read the disclaimer below.
Important disclaimer
I am not an epidemiologist and I am mostly using my undergraduate-level knowledge in this work. Some attempts by particle physicist to produce models for the coronavirus situation have been rather schlocky and have led to far too strong wrong conclusions resting wobbly grounds. This simulation is emphatically not a research project, and has no aspirations to predict the future. The modelling is simplistic and both the choice the model itself and default parameters reflect my own biases and lack of knowledge. For example different age groups are not modelled because I don’t really know what would look like (and don’t know that such policy has been applied particularly effectively anywhere in the world).
That said, I do believe this is an useful exercise for myself and hopefully others. Rather that making predictions for the future, I have tried to explain to myself the current policy debate and, hopefully in a way that can be useful to others.
I believe the utility of this project is twofold:
-
Ascertain that the outcome of the models are hugely dependent on parameters that are currently not well known, such as the proportion of undetected asymptomatic cases, or the long term immunity. Any certain claims coming from modelling should come with good explanations on how the parameters are fixed, and what the actual uncertainty on the conclusions is. Indeed different modelling efforts, including those done by dedicated teams from renowned organizations can reach vastly different conclusions, which in turn can greatly impact government action.
-
Serve as an education tool that allows public to recognize the merit and critically evaluate the need various public policy proposals.
The model
The simulation tracks the evolution of a set of agents, which could model the population of a city. Each agent is in one of the following states:
- Susceptible
- Infected (Undetected)
- Infected (Detected)
- Severe
- Unattended
- Immune (Undetected)
- Immune (Detected)
- Dead
The evolution proceeds in discrete time events, days. On each day, agents can transition between stated according to
The model is similar to commonly used simplified descriptions, but placing more emphasis in aspects that are relevant to the current crisis, such as hospital saturation or the propagation of the disease by asymptomatic carriers. It also used a complex network to model the disease propagation among different types of contacts. Many settings of the simulation can be controlled trough the Configure Simulation interface. In particular it allows to set probabilities for the various transitions as a function of time.
Note: Transition chances are parametrized as the probability of a given transition happening assuming no other transition has happened that day. When there are several possible transitions from one state to others (for example a Severe agent can become either Dead or Immune), the probability of no transition is fixed (as the product of probabilities of each of the possible transitions not happening). A random number then decides whether the agent stays in the same state or some of the possible transitions occur. If any transition does happen, the probability of each possible transition is proportional to the user entered setting.
For example if on a given day the probability of the transition Severe -> Immune is 80% (as entered by the user, that is, assuming no other transitions happen) and the probability Severe -> Dead is 20%, the actual transition probabilities are:
- Severe -> Severe (no transition): 16%
- Severe -> Immune: 67.2%
- Severe -> Dead: 16.8%
When probabilities are sufficiently small, the difference is negligible. For example if instead the independent transition probabilities are 8% for the Severe -> Immune transition and 2% for the Severe -> Dead transition, the actual probabilities are
- Severe -> Severe (no transition): 90.16%
- Severe -> Immune: 7.872%
- Severe -> Dead: 1.968%
This way of parametrizing has the advantage of allowing to think of probabilities of the various transitions as if they were independent and not having to worry that they e.g. add up to 100%.
The dynamics of each possible transition as well as the relevant settings that control them are described next.
Disease propagation
The probability of an Infected agent to transmit the disease to a Susceptible one depends on the number of days elapsed since the infection (which models the development of the disease), whether the agent is Detected or Undetected (which is assumed to make people behave differently) on the interactions with other agents.
The interactions leading to infection are modelled in terms of a set of networks (undirected graphs): Agents are arranged in three levels of networks:
- Household network
- Workplace network
- World network
The disease spreads from Infected (Detected or Undetected) to Susceptible agents that are connected to them by some of the networks.
Each agent is assigned to one household and one workplace, and it is connected to the unique World network, which models the random infection-risking interactions between the population. Each network is associated to different infectability strengths, for either Detected or Undetected Infected agents, expressed as a percentage of some max some maximum daily infectability. By default it is assumed that the infectability is strongest for Undetected agents in Household interactions (and the strength is set to 100% by convention), and the Household infectability decrease relatively little when a patient is known to be infected. Workplace and World infectability strengths are lower, and also decrease strongly when a patient is known to be infected. All strengths are tunable, and also can be influenced by policy choices.
Each household network is a fully connected graph. The distribution of household sizes can be controlled explicitly.
The size of each workplace follows a Binomial distribution where the average size of the workplaces is controlled by the user. This is the result of assigning each agent to a workplace at random, with equal probability, with the number of workplaces being chosen to reflect the mean size set by the user.
Each workplace network as well as the world network are Erdős–Rényi networks: That is, each pair of nodes is connected with an independent, constant, probability. By default Workplace connectivity is almost full, and World connectivity expressed in terms of the number of average daily interactions with random agents, is lower, yet high enough to ensure that the network is almost surely connected (that is there exists an indirect path in the World network between each pair of agents, implying that it is possible that every agent gets infected through the World network).
Currently all of the networks stay fixed throughout the simulation.
The infection rates are then computed as follow: On a given day, each Susceptible agent has a probability of getting becoming infected for each of the Infected agents it is connected to in all of the three networks. The infection probabilities are independent and the Susceptible agent becomes Infected (Undetected) if any single of its daily interactions results in an infection. The infection probability is the product of a factor dependent on the disease (specifically on the number of says since infection, and which can be set by the user) and a strength factor depending on the type of network that mediated the interaction (Household, Workplace or World) and whether the Infected agent was Detected or Undetected.
At the beginning of the simulation a few agents start off as Infected (Undetected), while the rest of the population is Susceptible. The disease then spreads across the networks.
Detection
Each Infected (Undetected) agent has a daily probability of becoming Detected spontaneously. This probability varies as a function of the number of says since infection and is settable by the user. This models people assuming they have contracted the disease, for example based on their symptoms. It is assumed that the disease evolution is not affected by whether the agent is Detected or Undetected, but however it their behaviour changes (for example they largely stop going to work) leading to a smaller risk of infecting others. This is parametrized by the infectability strengths explained above.
Immune agents are considered Detected if the agent’s previous infection was detected or if hospitalization was required. Currently the distinction between Detected and Undetected agents is only relevant for Contact tracing.
Disease evolution
Infected agents have a daily chance healing (thus becoming Immune) or worsen and require hospital assistance. These chances depend on the number of days elapsed since the agent became Infected. Agents that have worsened and can be attended in the hospital become Severe, and Unattended if hospitals are saturated, as described next. Severe patients have a daily chance of healing and becoming Immune and a daily chance of becoming Dead. The probabilities for each day since hospitalization can be set individually.
Hospital resources
Hospital resource scarcity is modelled by the total number of patients that can be hospitalized at once. If an agent requires hospitalization and the number of Severe patients matches this threshold, then the agent becomes Unattended. The next day unattended agents become Severe if there are hospital slots available or Dead otherwise.
Note: For simplicity Severe and Unattended agents are reported together in the user interface. Immune (Detected) and Immune (Undetected) agents are reported as immune.
Immunity loss
The simulation allows for the possibility of immune agents losing their immunity and becoming immune again. This is parametrized by a daily probability of becoming Susceptible as a function of the number of days since infection.
Policy choices
The simulation allows to estimate the effects of policies that influence the disease propagation and are implemented and shut down as a response to various events.
Specifically policies can be triggered on a specific day or, alternatively, when a specified number of agents reaches a given state either exceeds or falls below a threshold set by the user.
Optionally policies can also be cancelled, either after having been applied for a certain duration, or when a certain event is met.
The Make policy recurrent option causes the policy to be scheduled again after it has been shut down. It will become enacted when it’s trigger condition is met.
Several policies, including of the same kind can be in effect concurrently.
The policies are configurable through the set policies menu Set policies menu. The currently available policies are described next.
Shut workplace
A given percentage of workplaces shut down completely and workplace virus transition trough them is eliminated.
Concurrent applications of this policy cause the maximum number of workplaces implied by any of the policies to remain shut. For example if two Shut workplaces policies are active at the same time, one closing down 30% and the other 70%, then 70% of the workplaces will be closed.
Social distancing
The propagation of the disease is reduced for Workplace and World interactions by an amount set by the user. This affects only the propagation by Undetected agents, but not by Detected ones.
Concurrent applications of the policy will cause the reduction factors to be multiplied: For example, if two policies are active, one reducing some the propagation mode by 20% and the other reducing it by 10%, then the overall reduction will be 28%.
Enhanced self isolation
The propagation of the disease is reduced in interactions with Detected agents, by an amount set by the user.
Concurrent applications of the policy will cause the reduction factors to be multiplied: For example, if two policies are active, one reducing some the propagation mode by 20% and the other reducing it by 10%, then the overall reduction will be 28%.
Lockdown
Social contacts are reduced, resulting in a fraction of the World connections being disabled.
When this policy is reversed, the World graph will be reconstructed anew. Concurrent applications result in the maximum reduction factor being in place. The World graph will be renewed every time the policy changes.
Contact tracing
Reveal Infected agents among the contacts of each new Detected agent and in turn transform them into Detected. The maximum number of daily tests is limited and can be set by the user.
The tracing works by maintaining a queue of agents to be tested. Each appearance of a Detected agents causes their contacts to be added to the queue. Household contacts are given priority with respect to Workplace contacts, and both are given priority with respect to World contacts. Only Susceptible, Immune (Undetected) and Infected (Undetected) agents are added to the queue.
On each day, contacts are pulled from the queue in order of priority, until the queue is empty or the daily test limit is reached. Infected (Undetected) contacts that are selected will become Infected (Detected). Immune (Undetected) contacts become Immune (Detected). Their contacts are subsequently added to the queue, but not tested until the next day. Susceptible agents that get tested will not be tested again for three days.
The contacts that are not selected remain in the queue with the same priority. The size of the queue is limited to three times the maximum size. Higher priority contacts will evict lower priority ones when the maximum size is reached.
Concurrent applications of this policy result in the maximum number of tests adding up among those specified by each active policy.
Technical details
The code of the simulation can be found here:
https://github.com/Zaharid/virus_simulation/
The simulation runs entirely on the client browser and does not interact with a server or store any user data.
Test the effect of public health policies on a simple model
Explore the dependency on the assumptions
The simulation may consume your CPU resources.
Share the settings of this simulation