[PYTHON] Simple simulation of virus infection

Introduction

The following article was published in The Washington Post on March 14, 2020.

The Japanese version is below.

*** Why can outbreaks such as coronaviruses spread so rapidly and how can they "flatten the curve" ***
https://www.washingtonpost.com/graphics/2020/health/corona-simulation-japanese/

Using the simple principle of ball-to-ball contact, An article that introduces how the number of people infected with the virus increases and decreases. I think it was very easy to understand.

By the way, some people have reproduced it in Python (Jupyter Lab).

*** I made COVID19_simulator with JupyterLab ***
https://qiita.com/yasubei/items/ca48528daac456e339d3

I made it myself

By the way, I'm ...

I wanted to manipulate various parameters and simulate myself, so Ignore the bounce when the balls collide and consider the overlapping of the balls as an infection so that the process is lighter.

*** I made a Python version (using the module pygame) *** and *** HTML & JavaScript version ***.

Both are basically the same process, but there are differences in the drawing mechanism, so The JavaScript version, which runs on a web browser, is considerably faster than the Python version.

Since the initial position and movement amount of the ball are determined using random numbers, the execution result changes every time. As for the first infected ball, only one of all the balls placed on the leftmost side is selected.

With the default parameter (300 balls) The Python version will converge in about 10 to 15 seconds, and the JavaScript version will converge in about 5 to 10 seconds.

One movement and drawing of all the balls is called a turn.

Etc. can be freely specified.

During execution

Is displayed at the bottom of the screen, The graph showing the transition of the number of infected balls and the number of recovered balls is It is displayed in real time.

If you want to see the movement slowly, try increasing the display weight.

Even under the same conditions, the result will be different each time. It may be interesting to repeat the execution many times and check the appearance ratio of the drawn chart.

Demo

The HTML & JavaScript version is also placed at the following URL, and anyone can execute it. It's a good idea to play around with different parameters. (It can also be executed from a smartphone.)

ScreenShot.png

2020/04/25 postscript

*** IHASHI28 Educational ch. *** also introduced an example of simulation results.

Recommended Posts

Simple simulation of virus infection
Simulation of complete gacha
A simple sample of pivot_table.
Simple FPS measurement of python
Simulation of the contents of the wallet
Implementation of a simple particle filter
Explanation and implementation of simple perceptron