Skip to content

Commit 392611c

Browse files
committed
markdown
1 parent dd95c85 commit 392611c

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

lectures/sir_model.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ kernelspec:
4545

4646
我们将使用以下标准导入:
4747

48-
```{code-cell}
48+
```{code-cell} ipython3
4949
import matplotlib.pyplot as plt
5050
import matplotlib as mpl
5151
FONTPATH = "fonts/SourceHanSerifSC-SemiBold.otf"
@@ -59,7 +59,7 @@ from numpy import exp
5959

6060
最后,我们使用SciPy的数值例程odeint来求解微分方程。
6161

62-
```{code-cell}
62+
```{code-cell} ipython3
6363
from scipy.integrate import odeint
6464
```
6565

@@ -148,20 +148,20 @@ $\sigma$和$\gamma$都被视为固定的、由生物学决定的参数。
148148

149149
首先我们将人口规模设置为与美国相匹配。
150150

151-
```{code-cell}
151+
```{code-cell} ipython3
152152
pop_size = 3.3e8
153153
```
154154

155155
接下来我们按照上述方法固定参数。
156156

157-
```{code-cell}
157+
```{code-cell} ipython3
158158
γ = 1 / 18
159159
σ = 1 / 5.2
160160
```
161161

162162
现在我们构建一个函数来表示{eq}`dfcv`中的$F$
163163

164-
```{code-cell}
164+
```{code-cell} ipython3
165165
def F(x, t, R0=1.6):
166166
"""
167167
状态向量的时间导数。
@@ -189,7 +189,7 @@ def F(x, t, R0=1.6):
189189

190190
初始条件设置为
191191

192-
```{code-cell}
192+
```{code-cell} ipython3
193193
# initial conditions of s, e, i
194194
i_0 = 1e-7
195195
e_0 = 4 * i_0
@@ -198,13 +198,13 @@ s_0 = 1 - i_0 - e_0
198198

199199
用向量形式表示的初始条件是
200200

201-
```{code-cell}
201+
```{code-cell} ipython3
202202
x_0 = s_0, e_0, i_0
203203
```
204204

205205
我们使用odeint在一系列时间点 `t_vec`上通过数值积分求解时间路径。
206206

207-
```{code-cell}
207+
```{code-cell} ipython3
208208
def solve_path(R0, t_vec, x_init=x_0):
209209
"""
210210
通过数值积分求解i(t)和c(t),
@@ -224,7 +224,7 @@ def solve_path(R0, t_vec, x_init=x_0):
224224

225225
我们要研究的时间段为550天,大约18个月:
226226

227-
```{code-cell}
227+
```{code-cell} ipython3
228228
t_length = 550
229229
grid_size = 1000
230230
t_vec = np.linspace(0, t_length, grid_size)
@@ -236,7 +236,7 @@ t_vec = np.linspace(0, t_length, grid_size)
236236

237237
我们在不同 `R0`值的假设下计算感染人数的时间路径:
238238

239-
```{code-cell}
239+
```{code-cell} ipython3
240240
R0_vals = np.linspace(1.6, 3.0, 6)
241241
labels = [f'$R0 = {r:.2f}$' for r in R0_vals]
242242
i_paths, c_paths = [], []
@@ -249,7 +249,7 @@ for r in R0_vals:
249249

250250
这是一些用于绘制时间路径的代码。
251251

252-
```{code-cell}
252+
```{code-cell} ipython3
253253
def plot_paths(paths, labels, times=t_vec):
254254
255255
fig, ax = plt.subplots()
@@ -264,7 +264,7 @@ def plot_paths(paths, labels, times=t_vec):
264264

265265
让我们绘制当前病例数占人口的比例。
266266

267-
```{code-cell}
267+
```{code-cell} ipython3
268268
plot_paths(i_paths, labels)
269269
```
270270

@@ -274,7 +274,7 @@ plot_paths(i_paths, labels)
274274

275275
以下是累计病例数(占总人口的比例):
276276

277-
```{code-cell}
277+
```{code-cell} ipython3
278278
plot_paths(c_paths, labels)
279279
```
280280

@@ -284,7 +284,7 @@ plot_paths(c_paths, labels)
284284

285285
以下是一个关于 `R0`随时间变化的函数规范。
286286

287-
```{code-cell}
287+
```{code-cell} ipython3
288288
def R0_mitigating(t, r0=3, η=1, r_bar=1.6):
289289
R0 = r0 * exp(- η * t) + (1 - exp(- η * t)) * r_bar
290290
return R0
@@ -298,14 +298,14 @@ def R0_mitigating(t, r0=3, η=1, r_bar=1.6):
298298

299299
我们考虑几个不同的速率:
300300

301-
```{code-cell}
301+
```{code-cell} ipython3
302302
η_vals = 1/5, 1/10, 1/20, 1/50, 1/100
303303
labels = [fr'$\eta = {η:.2f}$' for η in η_vals]
304304
```
305305

306306
以下是在这些不同速率下 `R0` 的时间路径:
307307

308-
```{code-cell}
308+
```{code-cell} ipython3
309309
fig, ax = plt.subplots()
310310
311311
for η, label in zip(η_vals, labels):
@@ -317,7 +317,7 @@ plt.show()
317317

318318
让我们计算感染者人数的时间路径:
319319

320-
```{code-cell}
320+
```{code-cell} ipython3
321321
i_paths, c_paths = [], []
322322
323323
for η in η_vals:
@@ -329,13 +329,13 @@ for η in η_vals:
329329

330330
以下是不同场景下的当前案例:
331331

332-
```{code-cell}
332+
```{code-cell} ipython3
333333
plot_paths(i_paths, labels)
334334
```
335335

336336
以下是累计病例数(占总人口的比例):
337337

338-
```{code-cell}
338+
```{code-cell} ipython3
339339
plot_paths(c_paths, labels)
340340
```
341341

@@ -350,7 +350,7 @@ plot_paths(c_paths, labels)
350350

351351
这里考虑的参数设置模型的初始状态为25,000个活跃感染者,以及75,000个已经接触病毒因此即将具有传染性的个体。
352352

353-
```{code-cell}
353+
```{code-cell} ipython3
354354
# 初始条件
355355
i_0 = 25_000 / pop_size
356356
e_0 = 75_000 / pop_size
@@ -360,7 +360,7 @@ x_0 = s_0, e_0, i_0
360360

361361
让我们计算路径:
362362

363-
```{code-cell}
363+
```{code-cell} ipython3
364364
R0_paths = (lambda t: 0.5 if t < 30 else 2,
365365
lambda t: 0.5 if t < 120 else 2)
366366
@@ -376,28 +376,28 @@ for R0 in R0_paths:
376376

377377
这是活跃感染病例数:
378378

379-
```{code-cell}
379+
```{code-cell} ipython3
380380
plot_paths(i_paths, labels)
381381
```
382382

383383
在这些场景下,死亡率会是怎样的呢?
384384

385385
假设1%的病例会导致死亡
386386

387-
```{code-cell}
387+
```{code-cell} ipython3
388388
ν = 0.01
389389
```
390390

391391
这是累计死亡人数:
392392

393-
```{code-cell}
393+
```{code-cell} ipython3
394394
paths = [path * ν * pop_size for path in c_paths]
395395
plot_paths(paths, labels)
396396
```
397397

398398
这是每日死亡率:
399399

400-
```{code-cell}
400+
```{code-cell} ipython3
401401
paths = [path * ν * γ * pop_size for path in i_paths]
402402
plot_paths(paths, labels)
403403
```

0 commit comments

Comments
 (0)