LoginSignup
1
1

More than 3 years have passed since last update.

SIR モデルの日本語表示 (その 2)

Posted at

こちらで作成されるグラフを日本語化してみました。
感染病の数学予測モデルの紹介 (SIRモデル)

sir_may1302.png

sir02.py
#! /usr/bin/python

# ------------------------------------------------------------------
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import odeint
from scipy.optimize import minimize
import  sys

# ------------------------------------------------------------------
def SIR_EQ(v, t, beta, gamma):
    return [-beta*v[0]*v[1], beta * v[0] * v[1] - gamma * v[1], gamma * v[1]]

# ------------------------------------------------------------------
sys.stderr.write("*** start ***\n")
t_max = 160
dt = 0.01

beta_const = 0.2/1000
gamma_const = 0.1


#initial_state
S_0=999
I_0=1
R_0=0
ini_state = [S_0,I_0,R_0] #[S[0], I[0], R[0]]

#numerical integration
times =np.arange(0,t_max, dt)
args  =(beta_const, gamma_const)

#R0
N_total = S_0+I_0+R_0
R0 = N_total*beta_const *(1/gamma_const)
print(R0)
sys.stderr.write("*** ccc ***\n")

#Numerical Solution using scipy.integrate
#Solver SIR model
result = odeint(SIR_EQ, ini_state, times, args)
#
#
plt.rcParams["font.family"] = "TakaoExGothic"
# plt.rcParams["font.family"] = "IPAGothic"

plt.title("基本再生産数 : {}".format(format(R0,".3f")))
plt.xlabel('日数')
plt.ylabel('人数')
plt.plot(times,result)
plt.legend(['未感染者','感染者','回復者'])
plt.show()

sys.stderr.write("*** end ***\n")
# ------------------------------------------------------------------

フォントの指定は、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
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1