We simulated the spread of COVID-19 infection using the SIR model in Python. We created each of the 47 prefectures for the model and visualized it with a heat map.
github page https://github.com/chihina/analysis_covid_19_python
Visualized video (Some watermarks are included for editing with free software. I'm sorry !!) https://www.youtube.com/watch?v=7XvPKcasL1U
Interpreter: python 3.71 Special library: folium == 0.11.0 Others such as matplotlib and numpy.
The ordinary differential equations of the SIR model are as follows. (Simply speaking, β represents the infection rate and γ represents the recovery rate.)
\frac{dS}{dt}(t) = -\beta S(t)I(t)\\
\frac{dI}{dt}(t) = \beta S(t)I(t) - \gamma I(t)\\
\frac{dR}{dt}(t) = \gamma I(t)\\
S (susceptible) ... Susceptible (potentially infected)
I (Infected) ... Infected person
R (Recovered) ... Immune carrier (or quarantine)
\frac{dS}{dt}(t) = -\beta S(t)I(t)\\
The left side represents the rate of change of susceptibility carriers per unit time. This is expressed by multiplying the susceptibility carrier and the immune carrier by the infection rate.
In other words, S is reduced by the number of infected people per unit time.
\frac{dI}{dt}(t) = \beta S(t)I(t) - \gamma I(t)\\
The left side shows the rate of change of infected persons per unit time. The first term on the right side is the one that appeared earlier. The second term on the right side shows the person who recovers per unit time.
In other words, it is the number of people who get infected per unit time minus those who recover.
\frac{dR}{dt}(t) = \gamma I(t)\\
The left side shows the rate of change of the immune carrier per unit time. The right side is the same as the previous one, showing the person who recovers per unit time.
In other words, R increases by the amount of people who recover per unit time.
Considering the SIR model described so far for 47 prefectures, it is meaningless because each one becomes independent. Therefore, the influence term due to the infection status of other prefectures is added using the population ratio data. Did.
\frac{dS}{dt}(t) = -\beta S(t)I(t) - I_{pref} × PR_{pref} × 0.1\\
\frac{dI}{dt}(t) = \beta S(t)I(t) - \gamma I(t) + I_{pref} × PR_{pref} × 0.1 \\
\frac{dR}{dt}(t) = \gamma I(t)\\
I_{pref} × PR_{pref} × 0.1
The first letter expresses the situation of infected people other than the prefecture you are thinking about at that time.
The second letter indicates the population ratio of Tokyo in the prefecture you are thinking of at that time.
Therefore, according to this section, if the number of infected people increases in other prefectures, the number of infected people will increase in their own prefectures. By using the information on the population ratio, the population is large in Tokyo, Osaka, Aichi, etc. I am trying to make the influence of the prefecture stronger.
I will solve the improved SIR model with python. Originally it was easy to implement using scipy, but I implemented it steadily for understanding. For details, see the code and ask a question Please!!
Implementation method: 4th-order Runge-Kutta method
There are many explanations about the Runge-Kutta method, so please search for "4th-order Runge-Kutta method".
Draw a time series heatmap with python folium https://sammi-baba.hatenablog.com/entry/2018/12/25/074017
After creating the infected person information for each prefecture with the pandas dataframe, I referred to. I read and used what I exported to csv. Please see the actual video uploaded to youtube !!
Visualized video (Some watermarks are included for editing with free software. I'm sorry !!) https://www.youtube.com/watch?v=7XvPKcasL1U
I couldn't get a perfect grasp of the current infection situation, but I have a relatively simple ODE. I was very surprised to be able to reproduce the spread of infection to some extent.
If you have any questions about more detailed content, please do not hesitate to contact us !!
I referred to the following articles and statistical data. Thank you.
[1] Draw a time series heatmap with python folium https://sammi-baba.hatenablog.com/entry/2018/12/25/074017
[2] Population estimation As of October 1, 2017 Population estimation census site (e-stat) https://www.e-stat.go.jp/dbview?sid=0003215844
[3] Data of Japan github page (accessed July 28, 2020) https://www.e-stat.go.jp/dbview?sid=0003215844
Recommended Posts