[PYTHON] I tried to predict the behavior of the new coronavirus with the SEIR model.

1.First of all

The number of people infected with the new coronavirus pneumonia (Covid-19) that occurred in Wuhan, Hubei Province, China in December 2019 is increasing in Japan as well. Understanding the process by which infectious diseases such as influenza, AIDS, SARS, etc. spread within the human population is to confirm the effects of health policies such as vaccination settings and isolation of infected individuals. Is also important. In the previous article, I explained the SIR model, but I will introduce the SEIR model that considers the incubation period of infectious diseases. I will introduce the process of calculating this model with Python and the calculation result of how the new coronavirus spreads using this SEIR model.

Addendum: I tried to make it GUI based on the contents of this article.

** GUI simulation of new coronavirus (SEIR model) ** https://qiita.com/kotai2003/items/f6cf36e9c22c3e776dee

2. Infectious disease prediction model (SEIR model)

In the SEIR model, the total population is classified into the following groups, and the population increase / decrease of each group with respect to time is expressed by a differential equation.

--S (Susceptible): No immunity to infectious diseases. Infectable person --E (Exposed): Those who have an infectious disease during the incubation period --I (Infectious): A person who becomes ill due to infection and can be transmitted to a person who can be infected (S). Infected person --R (Removed): Those who have recovered from the onset of illness and acquired immunity. Or those who died without being able to recover from the onset of illness. (It is called Removed because it is excluded from the system of this model.)

SEIR-model.png

The population increase / decrease of each group is expressed by the following differential equation.


\begin{align}

\frac{dS}{dt} &= -\beta \frac{SI}{N} \\
\frac{dE}{dt} &=  \beta \frac{SI}{N}  -\epsilon E \\
\frac{dI}{dt} &=  \epsilon E -\gamma I \\
\frac{dR}{dt} &=  \gamma I \\

\end{align} 
\begin{align}
S &:What can be infected, can be infected without immunity\quad \text{(Susceptible)} \\
E &:Infectious disease during the incubation period\quad \text{(Infectious)} \\
I &:Those who have an infectious disease, those who can be infected by contact(S)Infects the disease\quad \text{(Infectious)} \\
R &:Those who died after infection or who acquired immunity\quad 
\text{(Removed)} \\
N &:Total population, S+E+I+R
\end{align}
\begin{align}
\beta &:Infection rate\quad \text{(The infectious rate)}  \\
\epsilon &:Rate of getting infection after exposure\quad \text{(The rate at which an exposed person becomes infective)} \quad [1/day] \\
\gamma &:Exclusion rate\quad \text{(The Recovery rate)} \quad [1/day] \\
\end{align}
\begin{align}
\ l_p &:Infection waiting time\text{(latency period [day])}\quad \epsilon= \frac{1}{l_p} \\
\ i_p &:Infection period\text{(Infectious period [day])}\quad \gamma= \frac{1}{i_p} \\
\end{align}

Prerequisites for this SIR model --A person who has acquired immunity will never be infected and will not lose immunity. --There is no inflow or outflow from the outside in the total population. No one died from any cause other than birth and infection.

3. SEIR model calculation

The SIR model is solved using numerical integration. Here, we use the odeint function that solves the Runge-Kutta equation of Python's Scipy module.

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

Next, write the differential equation of the SIR model in a form that can be calculated by odeint. Here, v [0], v [1], v [2], v [3] correspond to S, E, I, R, respectively.

# Define differential equation of SEIR model

'''
dS/dt = -beta * S * I / N
dE/dt = beta* S * I / N - epsilon * E
dI/dt = epsilon * E - gamma * I
dR/dt = gamma * I

[v[0], v[1], v[2], v[3]]=[S, E, I, R]

dv[0]/dt = -beta * v[0] * v[2] / N
dv[1]/dt = beta * v[0] * v[2] / N - epsilon * v[1]
dv[2]/dt = epsilon * v[1] - gamma * v[2]
dv[3]/dt = gamma * v[2]

'''


def SEIR_EQ(v, t, beta, epsilon, gamma, N ):
    return [-beta * v[0] * v[2] / N ,beta * v[0] * v[2] / N - epsilon * v[1],
            epsilon * v[1] - gamma * v[2],gamma * v[2]]

Then, define each parameter and initial conditions required for numerical integration. Let's assume that for a population of 1,000, there is one person with an early infection during the incubation period. Set the infection rate to 1, the infection waiting time to 2 days, and the infection period to 7.4 days.

# parameters
t_max = 100 #days
dt = 0.01

# initial_state
S_0 = 99
E_0 = 1
I_0 = 0
R_0 = 0
N_pop = S_0 + E_0 + I_0 + R_0
ini_state = [S_0, E_0, I_0, R_0]  # [S[0],E,[0], I[0], R[0]]


#Infection rate
beta_const = 1 #Infection rate

#Rate of getting infection after exposure
latency_period = 2 #days
epsilon_const = 1/latency_period

#Recovery rate and quarantine rate
infectious_period = 7.4 #days
gamma_const = 1/infectious_period

Store the numerical integration result in result and plot this result on the time axis.

# numerical integration
times = np.arange(0, t_max, dt)
args = (beta_const, epsilon_const, gamma_const, N_pop)

# Numerical Solution using scipy.integrate
# Solver SEIR model
result = odeint(SEIR_EQ, ini_state, times, args)
# plot
plt.plot(times, result)
plt.legend(['Susceptible', 'Exposed', 'Infectious', 'Removed'])
plt.title("SEIR model  COVID-19")
plt.xlabel('time(days)')
plt.ylabel('population')
plt.grid()

plt.show()

Figure_1.png

From this graph, it can be said that in a population of 100 people, one person (Exposed (0)) has an infection during the incubation period, and finally 100 people (Removed (100)) experience the infection. That is. It can be seen that the peak of infected people (Infectious) occurs around 18 days, after which the infection converges. In this way, it is possible to evaluate the effects of infectious diseases on the population with parameters related to infectious diseases.

4. Coronavirus prediction

Currently, many research papers have been published to estimate SEIR parameters from the cases of new coronavirus cases. This time, I will calculate the SEIR model with the parameter estimates published in the paper published on February 16. (Reference 2)

Parameter Mainland China (excluding Hubei) Hubei (excluding Wuhan) Wuhan
Population N(million) 1340 45 14
Infection rate[beta] 1.0 1.0 1.0
Latency period (days) 2 2 2
infectious_period (days) 6.6 7.2 7.4
E_0 696 592 318
I_0 652 515 389

The calculation result is shown. Note that each has a different population figure on the vertical axis. The first graph is a forecast of the spread of infection in mainland China, excluding Hubei. China-mainland.png

The second graph is a forecast of the spread of infection in Hubei Province, excluding Wuhan. hubei.png

The third graph is a prediction of the spread of Wuhan infection. Wuhan.png

With this parameter, the number of infected people peaks in 30 to 40 days, and eventually almost 100% of the population will experience infection (Removed (100)). I was really surprized. Probably, the prediction result is based on the worst case. I think it is necessary to pay attention to each step in this coronavirus.

5. References

  1. SEIR and SEIR models https://institutefordiseasemodeling.github.io/Documentation/general/model-seir.html

  2. Epidemic analysis of COVID-19 in China by dynamical modeling https://arxiv.org/abs/2002.06563

  3. Introduction of papers that predicted the epidemic of coronavirus in 2015 https://qiita.com/kotai2003/private/a44ca921314d17cc62e3

Recommended Posts

I tried to predict the behavior of the new coronavirus with the SEIR model.
I tried to predict the number of domestically infected people of the new corona with a mathematical model
I tried to automatically send the literature of the new coronavirus to LINE with Python
I tried to visualize the characteristics of new coronavirus infected person information with wordcloud
GUI simulation of the new coronavirus (SEIR model)
I tried to predict the price of ETF
I tried to predict the infection of new pneumonia using the SIR model: ☓ Wuhan edition ○ Hubei edition
I tried to streamline the standard role of new employees with Python
I tried to create a model with the sample of Amazon SageMaker Autopilot
I tried to find the entropy of the image with python
I tried to find the average of the sequence with TensorFlow
I tried to make something like a chatbot with the Seq2Seq model of TensorFlow
I tried to predict the number of people infected with coronavirus in Japan by the method of the latest paper in China
I tried to predict the number of people infected with coronavirus in consideration of the effect of refraining from going out
I tried to automate the watering of the planter with Raspberry Pi
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 tabulate the number of deaths per capita of COVID-19 (new coronavirus) by country
I tried to predict the sales of game software with VARISTA by referring to the article of Codexa
I tried to predict next year with AI
Since the stock market crashed due to the influence of the new coronavirus, I tried to visualize the performance of my investment trust with Python.
I tried to touch the API of ebay
I tried to correct the keystone of the image
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 predict Titanic survival with PyCaret
I tried to analyze the negativeness of Nono Morikubo. [Compare with Posipa]
I tried to visualize the text of the novel "Weathering with You" with WordCloud
I tried to visualize the model with the low-code machine learning library "PyCaret"
I tried to get the movie information of TMDb API with Python
I tried to vectorize the lyrics of Hinatazaka46!
I tried to get and analyze the statistical data of the new corona with Python: Data of Johns Hopkins University
I tried to predict the deterioration of the lithium ion battery using the Qore SDK
I tried to predict the horses that will be in the top 3 with LightGBM
I tried to easily visualize the tweets of JAWS DAYS 2017 with Python + ELK
I tried to predict the presence or absence of snow by machine learning.
The story of making soracom_exporter (I tried to monitor SORACOM Air with Prometheus)
I tried to display the infection condition of coronavirus on the heat map of seaborn
I tried to learn the sin function with chainer
python beginners tried to predict the number of criminals
I tried to extract features with SIFT of OpenCV
I tried to summarize the basic form of GPLVM
I tried to predict the J-League match (data analysis)
I tried to solve the soma cube with python
I tried to visualize the spacha information of VTuber
I tried to solve the problem with Python Vol.1
I tried to classify the voices of voice actors
I tried to summarize the string operations of Python
I tried to predict the victory or defeat of the Premier League using the Qore SDK
I tried to put out the frequent word ranking of LINE talk with Python
I tried to automate the article update of Livedoor blog with Python and selenium.
The theory that the key to controlling infection with the new coronavirus is hyperdispersion of susceptibility
I tried to summarize the new coronavirus infected people in Ichikawa City, Chiba Prefecture
I tried to visualize the running data of the racing game (Assetto Corsa) with Plotly
I tried to compare the processing speed with dplyr of R and pandas of 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 "gamma correction" of the image with Python + OpenCV
I tried to simulate how the infection spreads with Python
I tried to analyze the whole novel "Weathering with You" ☔️
I tried to get the location information of Odakyu Bus