All Projects → paulvangentcom → Python_corona_simulation

paulvangentcom / Python_corona_simulation

Licence: gpl-3.0
An agent-based simulation of corona and other viruses in python

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Python corona simulation

sbml-test-suite
The SBML Test Suite is a conformance testing system. It allows developers and users to test the degree and correctness of the SBML support provided in a software package.
Stars: ✭ 21 (-91.95%)
Mutual labels:  simulation
multiphysics
Interactive Multiphysics Simulation for Everyone
Stars: ✭ 41 (-84.29%)
Mutual labels:  simulation
computational-economy
An agent-based computational economy with macroeconomic equilibria from microeconomic behaviors
Stars: ✭ 67 (-74.33%)
Mutual labels:  simulation
openfluid
OpenFLUID framework and applications
Stars: ✭ 19 (-92.72%)
Mutual labels:  simulation
machine-learning-and-simulation
All the handwritten notes 📝 and source code files 🖥️ used in my YouTube Videos on Machine Learning & Simulation (https://www.youtube.com/channel/UCh0P7KwJhuQ4vrzc3IRuw4Q)
Stars: ✭ 93 (-64.37%)
Mutual labels:  simulation
utopia
Utopia is a comprehensive modelling framework for complex and evolving systems. Docs @ https://docs.utopia-project.org — NOTE: This repository is a READ-ONLY-MIRROR of the actual development repository; please open issues and MRs there:
Stars: ✭ 12 (-95.4%)
Mutual labels:  simulation
amodeus
Autonomous Mobility-on-Demand Extremely Useful Simulation
Stars: ✭ 44 (-83.14%)
Mutual labels:  simulation
Growthnodes
A Blender plugin for generative content creation and simulation of organic growth processes on polygonal surfaces.
Stars: ✭ 257 (-1.53%)
Mutual labels:  simulation
RAWSim-O
A simulation framework for Robotic Mobile Fulfillment Systems
Stars: ✭ 82 (-68.58%)
Mutual labels:  simulation
lewis
Let's write intricate simulators!
Stars: ✭ 17 (-93.49%)
Mutual labels:  simulation
elasty
A research-oriented elastic body simulator
Stars: ✭ 173 (-33.72%)
Mutual labels:  simulation
rpl-attacks
RPL attacks framework for simulating WSN with a malicious mote based on Contiki
Stars: ✭ 56 (-78.54%)
Mutual labels:  simulation
simplu3D
A library to generate buildings from local urban regulations.
Stars: ✭ 18 (-93.1%)
Mutual labels:  simulation
HELICS
Hierarchical Engine for Large-scale Infrastructure Co-Simulation (HELICS)
Stars: ✭ 76 (-70.88%)
Mutual labels:  simulation
orkid
Orkid Media Engine (C++/Lua/Python3/Linux/MacOs/OpenVR/Qt5)
Stars: ✭ 20 (-92.34%)
Mutual labels:  simulation
SimNDT
Ultrasonic NDT Simulator with engine core based on the Elastodynamic Finite Integration Technique (EFIT)
Stars: ✭ 34 (-86.97%)
Mutual labels:  simulation
SmartTrafficIntersection
Another AI toy project, of a traffic intersection controlled by a Reinforcement Learning AI agent to optimize traffic flow in an intersection of vehicles or pedestrians
Stars: ✭ 30 (-88.51%)
Mutual labels:  simulation
Omnetpp
OMNeT++ Discrete Event Simulator
Stars: ✭ 259 (-0.77%)
Mutual labels:  simulation
ros-docker-images
🐳 Bring ROS to any Linux distributions.
Stars: ✭ 15 (-94.25%)
Mutual labels:  simulation
Adroit
ShadowHand / ADROIT MuJoCo models
Stars: ✭ 30 (-88.51%)
Mutual labels:  simulation

Python COVID-19 ('Corona Virus') Simulation

covid-19 sim!

After seeing this article in the Washington Post I started wondering how such simulations might be done in Python, and indeed if I could expand upon the idea and make it more realistic.

For a moment I thought about writing the simualation itself in pure Python, with matplotlib as visualisation tool. However for large interacting populations, required computations scale quickly. Speeding up means reducing the operations to vector and matrix computations, something that can be done extremely efficiently through NumPy, which uses both a fast backend written in C, as well as makes use of hardware acceleration features like SIMD (single instruction, multiple data), which enables many operations on data arrays in relatively few clock cycles.

Aside from that, I've worked with NumPy a lot but felt there was still much to learn, so the challenge became: build such a simulation and improve upon it using only NumPy for the computations and matplotlib for the visualisation.

Simulation runs

Index

For reproducibility of all simulations, numpy's seed has been set to '100' unless otherwise specified

Summary video

A video highlighting some of the scenarios can be viewed here

Simple Infection Simulation

As a first step I built a simulation of a population of randomly moving people. The people stay within the world bounds and each tick there's a 2% chance of them changing heading and speed. There's a 3% chance of becoming sick when getting close to an infected person, and a 2% chance of a fatal ending. Click the image to view the video

image of the simuation

See simple_simulation.py for the code.

As you can see the virus managed to spread really quickly and almost got infected. In the end there were 44 fatalities, which is expected with a mortality rate of 2%.

Simulating Age Effects and Health Care Capacity

Reality is of course more complex. Let's incorporate increasing risks with age, as well as a simple representation of a limited capacity healthcare system. Both affect mortality during a pandemic: the elderly are vulnerable, and once the healthcare system becomes overwhelmed a lot of people are at increased risk of dying due to lack of treatment. The following parameters are active (all are or course settable):

  • the population's age follows a gaussian with a mean 55, SD of 1/3 the mean, and max of 105
  • population consists of 2000 individuals
  • there is a 3% chance of becoming infected when being near an infected person
  • baseline mortality is 2%
  • mortality chances start increasing at age 55, going up exponentially up to 10% at age 75 and beyond
  • healthcare capacity is 300 beds
  • when in medical treatment: mortality chance is halved
  • when not in medial treatment: mortality chance increases threefold.
    • note that this affects the elderly disproportionally as their baseline risk is already higher to start with.

Case 'Business As Usual'

See simulation.py for the code and settable parameters.

The first simuation run shows a population that simply keeps doing their normal thing and moving around. Click the image to view the video.

As you can see in the simulation still below, the healthcare system becomes completely overwhelmed, leading to 215 fatalities (10.75% of the population).

image of the simuation

Case 'Reduced Interaction'

The second simulation has the same settings, but to simulate people staying at home whenever possible and only going out when they have to, mobilty is greatly reduced. Click the image to view the video.

As you can see in this simulation, while at some point healthcare capacity was overasked, the effects on mortality remain low at 58 fatal endings in this run (2.9%). That's almost 4x less fatalities.

image of the simuation

Case 'Lock-Down'

Let's simulate a lock-down once 5% of the population is infected. To simulate this, we will make 90% of the people stop moving once locked-down, the remaining 10% will move with substantially reduced speed to simulate them being more cautious. This 10% represents the professions that are considered critical to society: these people will still be on the move and in contact with other people even in a lock-down. Another part of the 10% comes from people being people, meaning no lock-down will be perfect as there will always be those breaking quarantine. Click the image to view the video.

image of the simuation

Notice that once locked-down, the number of infections still increases for some time. This happens because of some of the healthy people will be locked into the same household with infected people, and thus become infected relatively quickly as well. If one of the moving population members (perhaps a mail man or someone delivering groceries) infects one of a cluster of people locked down together, the disease might spread. This leads to small and isolated outbreaks, which are contained very well through the lock-down.

However, if the lock down is lifted and a new case is introduced, a potential deadly situation quickly develops if no adequeate measures are taken:

image of the simuation

In such a situation repeated lock-downs seem inevitable if the infection keeps returning.

Case 'Self-Isolation'

Another approach is self-isolation: instructing people who have symptoms to stay at home. This was the initial approach the Dutch government had taken and is the approach in many countries that are not locked down. How effective is such a measure, especially given that not everybody will (or can) follow it? It turns out people can be infectious to others without manifesting symptoms, which further complicates such a 'stay home if you feel ill' scenario.

In the simulation, people who are infected will self-isolate. Those traveling to the isolation area can not infect others anymore, to simulate that these people are aware of their infection and will take precautions not to infect others. Click the image to view the video.

image of the simuation

Self-Isolation in Detail

The picture here is more complex, as factors such as population density and the percentage of people that break the voluntary quarantaine have a large effect. Let's run the simulation with three population densities ('high': 2000 people on a 1x1 area, 'medium': 2000 people on a 1.5x1.5 area, and 'low': 2000 people on 2x2 area), and let's simulate different compliance percentages. Because the situation is based on randomness, let's do a monte carlo simulation with 100 iterations for each setting, so that we can be reasonably confident in our estimates:

High population density:

high density graph

Medium population density:

medium density graph

Low population density:

medium density graph

This illustrates the interaction between the density of the population (and thus how many people you come across per time unit), and the percentage of infectious people present in the population. This is what you would expect, as both of these factors affect your odds of running into an infected person. Notice how the plots show a clear 'tipping point': after 'n' number of infections, the virus spread starts accelerating. The peak amounf ot infections strongly depends on how many people obey the self-isolation rules. However, reports have been going around that even without symptoms you can still be contagious, and remain contagious for quite some time after recovering, which makes such a self-isolation scenario risky in the case of COVID-19.

logo

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].