次のページと同じことを日本語表示で行いました。
中学生でもわかるSIRモデル
sir01.py
#! /usr/bin/python
# ------------------------------------------------------------------
import matplotlib.pyplot as plt
import numpy as np
import sys
# ------------------------------------------------------------------
def next_state(beta,nu,ss, ii, rr):
beta_ss_ii = beta * ss * ii
delta_ss = - beta_ss_ii
delta_ii = beta_ss_ii - nu * ii
ss = ss + delta_ss
ii = ii + delta_ii
if ss < 0:
ss = 0
if 1.0 < ii:
ii = 1.0
rr = 1.0 - ss - ii
return ss, ii, rr
#
# ------------------------------------------------------------------
def main():
beta = 0.5
nu = 0.3
period = 100
sys.stderr.write("beta = %f\n" % beta)
sys.stderr.write("nu = %f\n" % nu)
results = []
ii = 0.01
rr = 0
ss = 1 - ii - rr
l_s = [ss]
l_i = [ii]
l_r = [rr]
results.append([ss,ii,rr])
r0 = beta*ss/nu
print(ss, ii, rr)
for t in range(period):
ss, ii, rr = next_state(beta,nu,ss, ii, rr)
results.append([ss,ii,rr])
l_s.append(ss)
l_i.append(ii)
l_r.append(rr)
print("R0:{}".format(r0))
plt.rcParams["font.family"] = "TakaoExGothic"
# plt.rcParams["font.family"] = "IPAGothic"
plt.figure()
plt.title("R0:{}".format(format(r0,".3f")))
plt.xlabel('時間')
plt.ylabel('比率')
x = np.linspace(0, 100, period+1)
plt.plot(x, l_s, label="未感染者")
plt.plot(x, l_i, label="感染者")
plt.plot(x, l_r, label="回復者")
plt.legend()
plt.show()
#
# ------------------------------------------------------------------
main()
# ------------------------------------------------------------------
フォントの指定は、TakaoExGothic でも IPAGothic でも大丈夫です。
Arch Linux で確認しました。
$ uname -a
Linux iwata 5.6.10-arch1-1 #1 SMP PREEMPT Sat, 02 May 2020 19:11:54 +0000 x86_64 GNU/Linux
$ python --version
Python 3.8.2