I tried to simulate how the infection spreads with Python

motivation

This time, I tried to simulate how the infection spreads as a starting point to correctly understand the contents mentioned by Mr. Merkel and Mr. Johnson and the contents announced by the Ministry of Health, Labor and Welfare.

Why Qiita?

At this time (April 1, 2020), some people may not want to do such a simulation, but I thought that people who read Qiita would understand the purpose and contents correctly. It may be erased when the time comes.

Contents?

The source is available on github. (https://github.com/ryos36/sim-covid-19). Please note that there is no medical or mathematical basis (especially statistics). Also, the result is just a simulation. If you change the parameters, the result will match what you want.

Contents of the program

The program is written in Python. There will be bugs as it hasn't been fully tested and made quite RAPID. I'm personally good at this point because I'm getting decent results. The parameters can be changed. For the time being, the explanation is given in Param.md (https://github.com/ryos36/sim-covid-19/blob/master/Param.md) on github. Maybe that's not enough. If you are interested, please read the source. I'm not currently going to explain the source.

The sauce is dirty

It's not classified (because int was likely to speed up, I haven't verified it), and there's a wasteful loop. The first half loop (updates), the second half loop (collecting statistics), the drawing loop, and the movement simulation loop can probably be achieved within one loop (if you think about it now, the simulation speed will increase. It will be quadrupled).

Simulation is slow

The simulation takes time because it is not aimed at speeding up. In the future, I would like to do intercity simulation, but if you do so, it is better to classify and organize properly. If you write it in CUDA, it will be faster.

Equal to no UI

It is not graphed and it is difficult to give parameters flexibly. Make it a web application by linking it with someone's JavaScript.

Do a simulation.

Before the simulation, I will list the information that seems to be motivating (sources that seem to be correct). --German Chancellor Merkel "60 to 70% of the total population is infected" (https://www.nikkei.com/article/DGXMZO56691720S0A310C2000000/) --British government to revise its own new corona "herd immunity" strategy (https://www.technologyreview.jp/nl/the-uk-is-scrambling-to-correct-its-coronavirus-strategy/)

There are probably two scenarios for COVID-19 infection. ――It will eventually converge like influenza ――60 to 70% infected (until) converges So, this time, I took the position that the infection spreads until the latter herd immunity is acquired.

Some people are simulating with something like a molecular model. (The original source seems to be the Washington Post)

Let's simulate easily

For the time being, it is flexible, so I tried to quantify and simulate the "rumors" that are flowing in the streets. The important parameters in this simulation are as follows.

What does this mean?

What this model means is simply how many people will eventually be infected from the two parameters of the R0 value and the population being simulated? It just represents. You can actually find out by calculation without simulating. If the population is 1920 * 1080 = 2073600, the infection rate is 80%, the severity rate is 5%, and the sickness rate is 5% (= 0.25% case fatality rate), 4147.2 people will be killed. Influenza hospitalization and case fatality rates seem to be even lower. (https://www.hosp.med.osaka-u.ac.jp/home/hp-infect/file/ictmon/ictmon162.pdf) If you assign an infection rate of 16% and a case fatality rate of 0.001% to the same population , 3.46 people. Apart from this simulation, it is the same for all infectious diseases that the victim is predicted with a certain probability. The first point that this simulation suggests is not the number of victims, but the duration. It takes more than 300 days to converge. I used the word suggestion, but it may be correct to say that the simulation was so designed rather than suggestion.

How do you estimate the number of victims?

From here on, it's a sensitive story. Even in the same event, the sacrifice that society must accept and the sacrifice that individuals cannot accept will be different. It also includes many emotional issues. For now, set it aside for simulation only. The number of beds was also taken into account in the simulation. We compare the number of bets set in advance (assuming 1/1000 of the population) with those who become severely ill, and increase the probability of losing the number of beds when the number of beds is insufficient. We are not simulating each person's symptoms. Let's compare and simulate the case where there are enough beds and the case where there are not enough beds. image.png

When the left is insufficient and the right is abundant. The orange color of the graph is the victim. Since the number of beds is small, the number of seriously ill people will decrease by returning home silently rather than being cured, which is a rather shocking simulation result. I would like you to talk only on the simulation.

Suppress long-distance travel

In this simulation, suppressing long-distance travel slows the spread of infection. This gentleman is a songwriter. Since the simulation is originally over 300 days, it will be gentle, but what it means is that the simulation period will take several years.

image.png

The graph above shows the number of severely ill people. By suppressing long-distance travel for 400 days (the period colored in red), we were able to create a situation where we could always secure the number of beds. The result is that it takes more than 700 days for complete convergence.

Is intermittent long-distance movement suppression (lockdown) effective?

The result (on simulation) that it seems effective to suppress long-distance travel is, but I would like to make it as comfortable as possible in my life. Let's simulate with the prediction that "it will be possible by suppressing long-distance movement intermittently."

image.png

The figure above is a graph of the number of infected people. Suppression for 7,14 days has little effect. There is a clear difference in the graph at 28 days. If we did it for 400 days in a row, it could be almost flat. It also begins to show that suppression after the spread of infection is less effective. Suppression should start a little earlier.

Comparison with Imperial-College-COVID19-NPI-modelling-16-03-2020.pdf

Let's compare it with Imperial-College-COVID19-NPI-modelling-16-03-2020.pdf. Next, I will borrow the figure from pdf.

image.png

This pdf suggests ** suppression ** for 4 weeks, with 6 weeks and 2 weeks at the beginning. Let's do the same thing in this simulation.

image.png

Evaluating the results has become very difficult. Blue is the number of seriously ill people, orange is the number of people who died, and gray is the suppression period. At the top of the three graphs, the suppression was too early. The bottom was late, but it worked. It seems that suppression should be performed at ** good timing ** for an appropriate period **, and in the simulation environment here, suppression should be performed so as to cover before and after the number of severely ill persons of about 0.3% of the population. It was like. In the real world, there are too many parameters and it can be quite difficult to get the right timing.

Simulation challenges

The simulation results depend on the programmatic structure. For example, calculate different results when the start point is in the middle and when it is at the left end. It may be that geographical factors are taken into consideration, but it is still a program issue. The actual cities are continuous and the population density is not uniform, so they should be taken into account when simulating.

image.png

If the starting point is in the middle as shown in the figure, the infection spreads quickly and the damage (simulation) increases.

It's just a simulation

Last but not least, this is just a simulation. What can i say? What can be verified? It's very difficult because the actual data cannot be found accurately.

Perhaps some people are beginning to call it a "long-term battle," so I think they are simulating with accurate data somewhere in a more mathematical and analytical way. If those programs and mathematical formulas are made public and verified by multiple researchers and programmers, it will be better understood at least in terms of simulation.

Intuitively, humans move but do not move frequently, so it seems difficult to fully incorporate such human behavior mathematically. In that sense, do these programmer-like simulations make sense?

A year later, the mere simulation was a simulation. I hope I can look back with a happy feeling.

Supplement

Immediately after the state of emergency (2020/4/10)

The figure is quoted from the Q & A (for the general public) regarding the new coronavirus. In the basic policy for measures against new coronavirus infection (February 25, 2nd year of Reiwa), the peak was explained as shown in the figure.

image.png

Perhaps it was supposed to be herd immunity. (I'm worried that the area of the mountain is different)

Information began to change a little after the state of emergency was declared. Information from the "Expert Meeting on Countermeasures against New Coronavirus Infections" is listed.

image.png

"We aim to reduce contact with people to at least 70% and as much as 80%." Then, as shown in the graph, the number of patients will decrease. This is not a simulation, and it seems that the number of R0 is multiplied by 0.2 (80% reduction) to show the number that it will be like this after the incubation period + the period until healing.

Looking at the achievements in Hokkaido (quoted from the Hokkaido Government), it seems that it will be flat. image.png

I would like to keep an eye on future trends.

Recommended Posts

I tried to simulate how the infection spreads with Python
I tried to touch the CSV file with Python
I tried to solve the soma cube with python
I tried to solve the problem with Python Vol.1
I tried to divide the file into folders with Python
I tried to find out how to streamline the work flow with Excel x Python ②
I tried to find out how to streamline the work flow with Excel x Python ④
I tried to find out how to streamline the work flow with Excel x Python ⑤
I tried to find out how to streamline the work flow with Excel x Python ①
I tried to find out how to streamline the work flow with Excel x Python ③
The 15th offline real-time I tried to solve the problem of how to write with python
I tried to solve the ant book beginner's edition with python
I tried to improve the efficiency of daily work with Python
How to write offline real time I tried to solve the problem of F02 with Python
I wrote a doctest in "I tried to simulate the probability of a bingo game with Python"
I tried "smoothing" the image with Python + OpenCV
I tried "differentiating" the image with Python + OpenCV
I tried to save the data with discord
I tried to get CloudWatch data with Python
I tried to output LLVM IR with Python
I tried "binarizing" the image with Python + OpenCV
I tried to automate sushi making with python
[Python] I tried to visualize the night on the Galactic Railroad with WordCloud!
I tried to refer to the fun rock-paper-scissors poi for beginners with Python
How to write offline real time I tried to solve E11 with python
I tried to get the authentication code of Qiita API with Python.
I tried with the top 100 PyPI packages> I tried to graph the packages installed on Python
I tried to streamline the standard role of new employees with Python
I tried to get the movie information of TMDb API with Python
How to write offline real time I tried to solve E12 with python
I tried to find out how to streamline the work flow with Excel × Python, my article summary ★
I tried fp-growth with python
I tried scraping with Python
I tried gRPC with Python
I tried scraping with python
I tried to learn the sin function with chainer
I tried to graph the packages installed in Python
I tried to summarize how to use matplotlib of python
[Introduction to Python] How to iterate with the range function?
I tried to implement Minesweeper on terminal with python
I tried to get started with blender python script_Part 01
I tried to draw a route map with Python
[Python] How to specify the download location with youtube-dl
I tried to get started with blender python script_Part 02
I tried to implement an artificial perceptron with python
I want to inherit to the back with python dataclass
[Python] I tried to graph the top 10 eyeshadow rankings
I tried to automatically generate a password with Python3
I tried to summarize how to use pandas in python
[Python] How to rewrite the table style with python-pptx [python-pptx]
I tried to analyze J League data with Python
I tried to simulate the dollar cost averaging method
I tried hitting the API with echonest's python client
I tried to summarize the string operations of Python
I tried to solve AOJ's number theory with Python
Let's simulate the transition of infection rate with respect to population density with python
I tried to easily visualize the tweets of JAWS DAYS 2017 with Python + ELK
I tried to automatically send the literature of the new coronavirus to LINE with Python
I tried "gamma correction" of the image with Python + OpenCV
I tried to analyze the whole novel "Weathering with You" ☔️
Python: How to use async with