传染病动力学模型 SI => SIS => SIR => SEIR(python)

Parameter

# parameter
N = 10000 # Headcount
I = 1 # The Infected
S = N - I # Susceptible
E = 0 # Exposed
R = 0 # Recover
r = 10 # Number of people per infected person per day.
r2 = 10
B = 0.01 # Transmission probability
B2 = 0.01
Time = 350 # Day
v = 0.02 # Cure Rate
a = 0.1 # Conversion Rate

SI

# SI Model
# dI / dt =  r * B * I * S / N
# dS / dt = - r * B * I * S / N
# I(n) = I(n - 1) + r * B * I(n - 1) * S(n - 1) / N
# S(n) = S(n - 1) - r * B * I(n - 1) * S(n - 1) / N
TimeOfVirus = [1]
s_SI = [S]
i_SI = [I]
for day in range(1, Time):
    TimeOfVirus.append(day + 1)
    s_SI.append(s_SI[day - 1] - r * B * i_SI[day - 1] * s_SI[day - 1] / N)
    i_SI.append(i_SI[day - 1] + r * B * i_SI[day - 1] * s_SI[day - 1] / N)

传染病动力学模型 SI => SIS => SIR => SEIR(python)_第1张图片

SIS

# SIS Model
# dI / dt =  r * B * I * S / N
# dS / dt = - r * B * I * S / N
# I(n) = I(n - 1) + r * B * I(n - 1) * S(n - 1) / N - v * I
# S(n) = S(n - 1) - r * B * I(n - 1) * S(n - 1) / N + v * I
TimeOfVirus = [1]
s_SIS = [S]
i_SIS = [I]
for day in range(1, Time):
    TimeOfVirus.append(day + 1)
    s_SIS.append(s_SIS[day - 1] - r * B * i_SIS[day - 1] * s_SIS[day - 1] / N + v * i_SIS[day - 1])
    i_SIS.append(i_SIS[day - 1] + r * B * i_SIS[day - 1] * s_SIS[day - 1] / N - v * i_SIS[day - 1])

传染病动力学模型 SI => SIS => SIR => SEIR(python)_第2张图片

SIR

# SIR Model
# dS / dt = - r * B * I * S / N
# dI / dt = r * B * I * S / N - v * I
# dR / dt = v * I
# S(n) = S(n - 1) - r * B * I(n - 1) * S(n - 1) / N
# I(n) = I(n - 1) + r * B * I(n - 1) * S(n - 1) / N - v * I
# R(n) = R(n -1) + v * I(n - 1)
TimeOfVirus = [1]
s = [S]
i = [I]
R = [0]

for day in range(1, Time):
    TimeOfVirus.append(day + 1)
    s.append(s[day - 1] - r * B * i[day - 1] * s[day - 1] / N)
    i.append(i[day - 1] + r * B * i[day - 1] * s[day - 1] / N - v * i[day - 1])
    R.append(R[day - 1] + v * i[day - 1])

传染病动力学模型 SI => SIS => SIR => SEIR(python)_第3张图片

SEIR

# SEIR Model
# dS / dt = - r * B * I * S / N
# dE / dt = r * B * I * S / N - a * E
# dI / dt = a * E - v * I
# dR / dt = v * I
# S(n) = S(n - 1) - r * B * I(n - 1) * S(n - 1) / N
# E(n) = E(n - 1) + r * B * I(n -1) * S(n - 1) / N - a * E(n - 1)
# I(n) = I(n - 1) + a * E(n - 1) - v * I
# R(n) = R(n -1) + v * I(n - 1)
TimeOfVirus = [1]
ss = [S]
ee = [E]
ii = [I]
rr = [R]

for day in range(1, Time):
    TimeOfVirus.append(day + 1)
    ss.append(ss[day - 1] - r * B * ii[day - 1] * ss[day - 1] / N)
    ee.append(ee[day - 1] + r * B * ii[day - 1] * ss[day - 1] / N - a * ee[day - 1])
    ii.append(ii[day - 1] + a * ee[day - 1] - v * ii[day - 1])
    rr.append(rr[day - 1] + v * ii[day - 1])

传染病动力学模型 SI => SIS => SIR => SEIR(python)_第4张图片

New SEIR

# New SEIR Model
# dS / dt = - r * B * I * S / N - r2 * B2 * E * S / N
# dE / dt = r * B * I * S / N - a * E + r2 * B2 * E * S / N
# dI / dt = a * E - v * I
# dR / dt = v * I
# S(n) = S(n - 1) - r * B * I(n - 1) * S(n - 1) / N - r2 * B2 * E(n - 1) * S(n - 1) / N
# E(n) = E(n - 1) + r * B * I(n -1) * S(n - 1) / N - a * E(n - 1) + r2 * B2 * E(n - 1) * S(n - 1) / N
# I(n) = I(n - 1) + a * E(n - 1) - v * I
# R(n) = R(n -1) + v * I(n - 1)
TimeOfVirus = [1]
ss = [S]
ee = [E]
ii = [I]
rr = [R]

for day in range(1, Time):
    if day >= 60:
        r = 5
        r2 = 5
    TimeOfVirus.append(day + 1)
    ss.append(ss[day - 1] - r * B * ii[day - 1] * ss[day - 1] / N - r2 * B2 * ee[day - 1] * ss[day - 1] / N)
    ee.append(ee[day - 1] + r * B * ii[day - 1] * ss[day - 1] / N - a * ee[day - 1] + r2 * B2 * ee[day - 1] * ss[day - 1] / N)
    ii.append(ii[day - 1] + a * ee[day - 1] - v * ii[day - 1])
    rr.append(rr[day - 1] + v * ii[day - 1])

传染病动力学模型 SI => SIS => SIR => SEIR(python)_第5张图片

你可能感兴趣的:(Funny)