次のページを参考にしました。
【minimize入門】SEIRモデルでデータ解析する♬
1000 人の孤立した島に、1 人の感染者がいたらどうなるかというモデルです。パラメータの設定で結果はかなり変わります。
seir.py
#! /usr/bin/python
#
# seir.py
#
# Aug/26/2020
# ------------------------------------------------------------------
import sys
import numpy as np
from scipy.integrate import odeint
from scipy.optimize import minimize
import matplotlib.pyplot as plt
# ------------------------------------------------------------------
def seir_equation(vv,t,beta,sigma,gamma,N):
ss = vv[0]
ee = vv[1]
ii = vv[2]
#
yprime = np.zeros(4)
yprime[0] = -beta * ss * ii / N
yprime[1] = beta* ss * ii/N - sigma * ee
yprime[2] = sigma * ee - gamma * ii
yprime[3] = gamma * ii
#
return yprime
#
# ------------------------------------------------------------------
sys.stderr.write("*** start ***\n")
S_0 = 999.0
I_0 = 0.0
E_0 = 1.0
R_0 = 0.0
N = S_0 + E_0 + I_0 + R_0
beta = 6.87636378
sigma = 1. / 1.21965986
gamma = 1. / 2.01373496
ini_state=[S_0,E_0,I_0,R_0]
t_max = 14
dt = 0.01
tt=np.arange(0,t_max,dt)
#
plt.rcParams["font.family"] = "IPAGothic"
plt.title("SEIR モデル")
plt.plot(tt,odeint(seir_equation,ini_state,tt,args=(beta,sigma,gamma,N)))
plt.legend(['S: 未感染者','E: 潜伏者','I: 感染者','R: 回復者'])
#
plt.show()
sys.stderr.write("*** end ***\n")
# ------------------------------------------------------------------
Arch Linux で確認しました。
$ uname -a
Linux iwata 5.8.3-arch1-1 #1 SMP PREEMPT Fri, 21 Aug 2020 16:54:16 +0000 x86_64 GNU/Linux
$ python --version
Python 3.8.5