Second grade, I look to draw a graph of the spread of the virus SEIR

The most recent case is clear to everyone, had good Spring Festival, a student can go out and can honestly happy holiday home when a fat, or fat that has been! ! ! Write the code point every day, chase chase drama, take a look at study section review, the other is a brush B station. This does not, this afternoon brush complete guide to teach the knowledge we came second year. I suggest that you go to see

Links offer
Here Insert Picture Description

Focus here

Beginning catches our eye is his handsome face, along with a progress bar creep, mathematical formulas appear and various viral propagation models so I can not help thinking, I really was a college student? Junior learned this stuff? Haha, no kidding, the first pass may indeed look a bit ignorant, but after reading slowly can think about or understand, then due to the completion of a pilot from the hold reason code, so most of the time only his results in Figure screenshots this time, with time, just nothing to do about getting in the drawing up model.
Here Insert Picture Description
Here Insert Picture Description
Everyone watching the video, know the meaning of the parameters of the SEIR model, then the differential equation step by step according to the rate of change of generations into the calculated values obtained by tomorrow, finally drawn this map.
Here Insert Picture Description

Code

Obviously, using a complete guide matlab, matlab and I used a few times in addition to mathematical modeling, data analysis, basic've been writing like a python, so this is a python

import math
import numpy as np
import matplotlib
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['KaiTi']
plt.rcParams['axes.unicode_minus'] = False

# 首先还是设置一下参数,之后方便修改
N=10000        # 人口总数


E=[]           # 潜伏携带者
E.append(0)

I=[]           # 传染者
I.append(1)

S=[]           # 易感者
S.append(N-I[0])

R=[]           # 康复者
R.append(0)

r=20           # 传染者接触人数
b=0.03         # 传染者传染概率
a=0.1          # 潜伏者患病概率
r2=20          # 潜伏者接触人数
b2=0.03        # 潜伏者传染概率
y=0.1          # 康复概率


T=[i for i in range(0,160)]   # 时间

for i in range(0,len(T)-1):
    S.append(S[i]-r*b*S[i]*I[i]/N-r2*b2*S[i]*E[i]/N)
    E.append(E[i]+r*b*S[i]*I[i]/N-a*E[i]+r2*b2*S[i]*E[i]/N)
    I.append(I[i]+a*E[i]-y*I[i])
    R.append(R[i]+y*I[i])

def plot():
    plt.figure()
    plt.title("SEIR-病毒传播时间曲线")
    plt.plot(T,S,color='r',label='易感者')
    plt.plot(T, E, color='k', label='潜伏者')
    plt.plot(T, I, color='b', label='传染者')
    plt.plot(T, R, color='g', label='康复者')
    plt.grid(False)
    plt.legend()
    plt.xlabel("时间(天)")
    plt.ylabel("人数")
    plt.show()

plot()

Not very standardized, it would change the specification point

import math
import numpy as np
import matplotlib
import matplotlib.pyplot as plt

plt.rcParams['font.sans-serif'] = ['KaiTi']
plt.rcParams['axes.unicode_minus'] = False

def calc(T):
    for i in range(0, len(T) - 1):
        S.append(S[i] - r * b * S[i] * I[i] / N - r2 * b2 * S[i] * E[i] / N)
        E.append(E[i] + r * b * S[i] * I[i] / N - a * E[i] + r2 * b2 * S[i] * E[i] / N)
        I.append(I[i] + a * E[i] - y * I[i])
        R.append(R[i] + y * I[i])

def plot(T,S,E,I,R):
    plt.figure()
    plt.title("SEIR-病毒传播时间曲线")
    plt.plot(T,S,color='r',label='易感者')
    plt.plot(T, E, color='k', label='潜伏者')
    plt.plot(T, I, color='b', label='传染者')
    plt.plot(T, R, color='g', label='康复者')
    plt.grid(False)
    plt.legend()
    plt.xlabel("时间(天)")
    plt.ylabel("人数")
    plt.show()

if __name__ == '__main__':
    # 首先还是设置一下参数,之后方便修改
    N = 10000  # 人口总数
    E = []  # 潜伏携带者
    E.append(0)

    I = []  # 传染者
    I.append(1)

    S = []  # 易感者
    S.append(N - I[0])

    R = []  # 康复者
    R.append(0)

    r = 20  # 传染者接触人数
    b = 0.03  # 传染者传染概率
    a = 0.1  # 潜伏者患病概率
    r2 = 20  # 潜伏者接触人数
    b2 = 0.03  # 潜伏者传染概率
    y = 0.1  # 康复概率

    T = [i for i in range(0, 160)]  # 时间
    calc(T)
    plot(T,S,E,I,R)

That code is pretty much

At last

As a university student in Wuhan, Wuhan can still hope to recover as soon as possible over, Wuhan Come on, Come on, China! ! ! In addition we can also look up the information, with more accurate data to draw the model to see how the accuracy of the model in the end.

Published 85 original articles · won praise 55 · views 20000 +

Guess you like

Origin blog.csdn.net/shelgi/article/details/104108757