前提
SEIRモデルを用いて過去の新型コロナウイルスの感染者数のシミュレーションを行なっています。
実現したいこと
SEIRモデルを用いて過去の新型コロナウイルスの感染者数(厚生労働省オープンデータを元に)を最小二乗法でフィッティングを行なっています。
発生している問題・エラーメッセージ
発生している問題としてはフィッティングを行なった際に曲線が曲がってしまうことです。
曲がらないように綺麗な曲線を描くためにはどのようなことを行えばいいのか教えて頂きたいです。
該当のソースコード
Python
1import numpy as np 2import matplotlib.pyplot as plt 3from scipy.integrate import odeint 4from scipy import optimize 5import csv 6 7# loading csv-file 8f = open("./COVID-3rd-wave-five.csv", "r", encoding="UTF-8", errors="", newline="" ) 9fcsv = csv.reader(f, delimiter=",", doublequote=True, lineterminator="\r\n", quotechar='"', skipinitialspace=True) 10 11next(f) # skip to the header of the csv-file 12 13cases = [] 14for row in fcsv: 15 cases.append(int(row[1])) 16 17Tokyo = 14000000 # the population of Tokyo in 2020 18normalized_cases = np.array(cases, dtype = float)/Tokyo 19days = len(cases) 20t = np.arange(days) 21# initial values 22I0 = normalized_cases[0]; S0 = 1.0 - I0; E0 = 0; R0 = 0.0 23 24# SIR differential equation 25# S = SEIR[0], E = SEIR[1], I = SEIR[2], R = SEIR[3] 26def SEIReq(SEIR, t, beta, ipusilon, gamma): 27 dSdt = -beta*SEIR[0]*SEIR[2] 28 dEdt = beta*SEIR[0]*SEIR[2] - ipusilon*SEIR[1] 29 dIdt = ipusilon*SEIR[1] - gamma*SEIR[2] 30 dRdt = gamma*SEIR[2] 31 32 return [dSdt, dEdt, dIdt, dRdt] 33 34def I(t, beta, ipusilon, gamma): 35 SEIRlist = odeint(SEIReq, (S0, E0, I0, R0), t, args = (beta, ipusilon, gamma)) 36 return SEIRlist[:,2] 37 38p0 =[1, 1, 1] 39optparams, cov = optimize.curve_fit(I, t, normalized_cases,p0) 40print('R0=',optparams[0]/optparams[2]) 41print(optparams[0]) 42print(optparams[1]) 43print(optparams[2]) 44fitted = I(t, *optparams) 45 46plt.scatter(t, cases) 47plt.plot(t, fitted*Tokyo) 48plt.xlabel('the number of days from 2020/12/1') 49plt.ylabel('the number of confirmed cases in Tokyo') 50plt.show() 51f.close() # close the csv-file
試したこと
色々な期間を用いてフィッティングを行いましたがどのパターンでも最初の方で曲線が折れています。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
未だ未解決です。どなたかお力添えいただけませんか。

あなたの回答
tips
プレビュー