[PYTHON] Day 71 I tried to predict how long this self-restraint will continue with the SIR model

I calculated the SIR model.

How long will the new corona epidemic continue? Yesterday's NHK Special "New Coronavirus Border Offense and Defense-Report from the Frontline of Prevention of Infection Spread-" I calculated it with reference to.

What is SIR model?

An equation used to calculate epidemics-convergence of infectious diseases.

Implement the SIR model in Python

The code implemented in Python was on scipython.com, so I used it.

The SIR epidemic model

SIR.py


import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

# Total population, N.
N = 1000
# Initial number of infected and recovered individuals, I0 and R0.
I0, R0 = 1, 0
# Everyone else, S0, is susceptible to infection initially.
S0 = N - I0 - R0
# Contact rate, beta, and mean recovery rate, gamma, (in 1/days).
beta, gamma = 0.2, 1./10 
# A grid of time points (in days)
t = np.linspace(0, 160, 160)

# The SIR model differential equations.
def deriv(y, t, N, beta, gamma):
    S, I, R = y
    dSdt = -beta * S * I / N
    dIdt = beta * S * I / N - gamma * I
    dRdt = gamma * I
    return dSdt, dIdt, dRdt

# Initial conditions vector
y0 = S0, I0, R0
# Integrate the SIR equations over the time grid, t.
ret = odeint(deriv, y0, t, args=(N, beta, gamma))
S, I, R = ret.T

# Plot the data on three separate curves for S(t), I(t) and R(t)
fig = plt.figure(facecolor='w')
ax = fig.add_subplot(111, axis_bgcolor='#dddddd', axisbelow=True)
ax.plot(t, S/1000, 'b', alpha=0.5, lw=2, label='Susceptible')
ax.plot(t, I/1000, 'r', alpha=0.5, lw=2, label='Infected')
ax.plot(t, R/1000, 'g', alpha=0.5, lw=2, label='Recovered with immunity')
ax.set_xlabel('Time /days')
ax.set_ylabel('Number (1000s)')
ax.set_ylim(0,1.2)
ax.yaxis.set_tick_params(length=0)
ax.xaxis.set_tick_params(length=0)
ax.grid(b=True, which='major', c='w', lw=2, ls='-')
legend = ax.legend()
legend.get_frame().set_alpha(0.5)
for spine in ('top', 'right', 'bottom', 'left'):
    ax.spines[spine].set_visible(False)
plt.show()

In case of influenza

First, let's take a look at the influenza that was set as an example.

Influenza (no immunity)

N  =1000 #The population of 1000 is per school, company, neighborhood association?
I0 =1    #Infected person. At first one person.
R0 =0    #A person who has recovered and acquired immunity. 0 people at first
S0 =N - I0 - R0 #People who are not immune and are susceptible to infection. First N-I0-R0 people
beta =0.2       #Number of people infected per day
gamma =1./10    #Recovery rate
t =160          #period(Days) 

One infected person infects 0.2 people a day. The infection period is 10 days. Once you recover and gain immunity, you will not be infected after this contact. When the immunity is more than half, it will converge.

i0.png

From one carrier to the peak, 67 days, 15.3%, 153 people were infected and converged. It's like this when the class is closed due to the flu.

Influenza (20% immunity)

Consider the case of getting immunized by vaccination before the flu season. The first is when an influenza epidemic occurs where 20% of people have acquired immunity.

# Initial number of infected and recovered individuals, I0 and R0.
#I0, R0 = 1, 0
I0, R0 = 1, (N*0.2)

i2.png

Only 20% of people have immunity, and the epidemic has been suppressed considerably. The vaccine is amazing.

Influenza (50% immunity)

The Influenza vaccine regular vaccination rate in 2019 was 50%.

# Initial number of infected and recovered individuals, I0 and R0.
#I0, R0 = 1, 0
I0, R0 = 1, (N*0.5)

i1.png

It is completely suppressed. It's safe if this happens.

For COVID-19

Consider the case of the new corona. Assuming a city of 10 million people such as Tokyo and Wuhan, the infection period was set to 3 weeks (21 days). Other properties are the same as influenza.

COVID-19 (no immunity)

N  =10000000 #Population 10 million(Assuming Tokyo and Wuhan)|
I0 =1        #Infected person. At first one person.
R0 =0        #A person who has recovered and acquired immunity. 0 people at first
S0 =N - I0 - R0 #People who are not immune and are susceptible to infection. First N-I0-R0 people
beta =0.2       #Number of people infected per day
gamma =1./21    #Reciprocal of the number of days required for recovery
t =160          #period(Days) 

c0.png

With only 21 days of infection, the peak number of infected people was 42%, or 4.2 million, and the virus has evolved into a vicious virus. Of these, 20% develop and 1% die ... 840,000 people will be affected, 42,000 will die, and it will be resolved in 228 days.

It's hell.

After seeing this graph, it went down for a few days.

However, when I saw this tweet, I thought that there might be hope.

Impact survey results ... In Heinsberg County, where the first outbreak of the new corona occurred in Germany, an immunological survey was conducted on about 500 people, and it was said that about 15% of the people had been infected. The number of infected people per 100,000 population in Heinsberg's PCR test was 604.4, and the known sensitivity rate was only 0.6%. https://twitter.com/R3000C/status/1248594913589002240

COVID-19 (immunity 15%)

In Japan today, 15% of people are infected. 89 days until 15% of people become infected.

Lock down on the 89th day to stop the epidemic.

Suppose that after one month everyone recovers and 15% have immunity. Release the lockdown. The epidemic is rekindling, but ...

c1.png

The curve of the second wave was loosened by 15% immunity.

Just before the peak again, we will lock down with an infection rate of 15%. This time it was the 119th day.

After a month, everyone recovers and gains immunity, with a total of 30% having immunity.

COVID-19 (30% immunity)

c2.png

The third wave peaks in 178 days. The infection rate is up to 20%. It took 149 days to reach an infection rate of 15%.

COVID-19 (immunity 45%)

The fourth wave has a peak of 252 days and an infection rate of up to 11%.

c3.png

If you come to this point, you will be able to overcome it with loose self-restraint.

How long will this self-restraint last?

15% infection → lockdown → recovery → release in 3 sets (89 days + 30 days) + (119 days + 30 days) + (149 days + 30 days) = 447 days

It will be necessary to devise a way to survive for 447 days, but the number of victims will be small.

If it is a strategy to infect the economy while turning the economy, 99% of the lives will not be different and it will take 228 days. Some people may not be able to withstand the temptation of the devil.

Wuhan City lifted the blockade on April 7. Even if the second wave comes, it should not be as large as this time. I am concerned about the immunity acquisition rate. Thorough management can help keep the epidemic down. In that case, Wuhan City will be the first city in the world to recover, and will SF be the future?

And the vaccine. With this, the situation will be overturned at once. Hand wash, gargle, social distance. The curve is suppressed sharply. Then inspection. If half of the population can get immunity, it can be completely suppressed.

It's going to be a long battle.

Recommended Posts

Day 71 I tried to predict how long this self-restraint will continue with the SIR model
I tried to predict the behavior of the new coronavirus with the SEIR model.
I tried to predict the horses that will be in the top 3 with LightGBM
I tried to simulate how the infection spreads with Python
I tried to predict the infection of new pneumonia using the SIR model: ☓ Wuhan edition ○ Hubei edition
I tried to predict the number of domestically infected people of the new corona with a mathematical model
I tried to visualize the model with the low-code machine learning library "PyCaret"
I tried to predict next year with AI
I tried to predict Titanic survival with PyCaret
I tried to predict the price of ETF
I tried to create a model with the sample of Amazon SageMaker Autopilot
I tried to learn the sin function with chainer
I tried to predict the J-League match (data analysis)
I tried to solve the soma cube with python
I tried to solve the problem with Python Vol.1
I tried to find out how to streamline the work flow with Excel x Python ②
I tried to make something like a chatbot with the Seq2Seq model of TensorFlow
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 predict and submit Titanic survivors with Kaggle
I tried to find the entropy of the image with python
I tried to analyze the whole novel "Weathering with You" ☔️
I tried to find the average of the sequence with TensorFlow
[Introduction to SIR model] Predict the end time of each country with COVID-19 data fitting ♬
How to write offline real time I tried to solve the problem of F02 with Python
I tried to notify the train delay information with LINE Notify
Sentiment analysis with natural language processing! I tried to predict the evaluation from the review text
I tried to predict Boston real estate prices with PyCaret
I tried to divide the file into folders with Python
I tried to divide with a deep learning language model
I tried to predict the sales of game software with VARISTA by referring to the article of Codexa
I tried to implement SSD with PyTorch now (model edition)
I tried to summarize how to use the EPEL repository again
I tried to find out how to streamline the work flow with Excel × Python, my article summary ★
I tried to describe the traffic in real time with WebSocket
I tried to solve the ant book beginner's edition with python
I tried to automate the watering of the planter with Raspberry Pi
I tried to process the image in "sketch style" with OpenCV
I tried to get started with Bitcoin Systre on the weekend
I tried to predict by letting RNN learn the sine wave
I tried to process the image in "pencil style" with OpenCV
I tried to expand the size of the logical volume with LVM
I tried to improve the efficiency of daily work with Python
I tried to move the ball
I tried to estimate the interval.
[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 how to improve the accuracy of my own Neural Network
765 I tried to identify the three professional families by CNN (with Chainer 2.0.0)
I tried to make a calculator with Tkinter so I will write it
I tried to get the authentication code of Qiita API with Python.
I tried to automatically extract the movements of PES players with software
I tried to learn the angle from sin and cos with chainer
I tried with the top 100 PyPI packages> I tried to graph the packages installed on Python
I tried to analyze the negativeness of Nono Morikubo. [Compare with Posipa]
I tried to streamline the standard role of new employees with Python
I tried to visualize the text of the novel "Weathering with You" with WordCloud