Skip to content

Commit

Permalink
50 / 55 : update with video and stackplot()
Browse files Browse the repository at this point in the history
Clean ipynb
  • Loading branch information
beachdweller committed May 15, 2024
1 parent b5eada7 commit ae8b60b
Showing 1 changed file with 122 additions and 68 deletions.
190 changes: 122 additions & 68 deletions 50_ode/55_Spread_of_disease.ipynb
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"private_outputs": true,
"provenance": [],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
Expand All @@ -28,18 +12,18 @@
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Simulating Spread of Disease<br>질병 전파 시뮬레이션\n"
],
"metadata": {}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Ref : David Smith and Lang Moore, \"The SIR Model for Spread of Disease - The Differential Equation Model,\" Convergence (December 2004), https://www.maa.org/press/periodicals/loci/joma/the-sir-model-for-spread-of-disease-the-differential-equation-model\n",
"\n"
],
"metadata": {}
]
},
{
"cell_type": "code",
Expand All @@ -56,26 +40,27 @@
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We would consider three types of people.<br>3종류의 사람들로 구분할 것이다.\n",
"* We would consider three types of people.<br>3종류의 사람들로 구분할 것이다.\n",
"\n"
],
"metadata": {}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"| variable<br>변수 | description<br>설명 |\n",
"|:-----:|:-----:|\n",
"| $s$ | the susceptible fraction of the population<br>감염될 수 있는 인구 비중 |\n",
"| $i$ | the infected fraction of the population<br>감염된 인구 비중 |\n",
"| $r$ | the recovered fraction of the population<br>회복된 인구 비중 |\n",
"\n"
],
"metadata": {}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"\\begin{align}\n",
Expand All @@ -85,49 +70,71 @@
"\\end{align}\n",
"$$\n",
"\n"
],
"metadata": {}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"| variable<br>변수 | value<br>값 | description<br>설명 |\n",
"|:---------------:|:---------------:|:---------------:|\n",
"| $b$ | 1/2 | transmission rate<br>전염률 |\n",
"| $k$ | 1/2 | recovery rate<br>회복률 |\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"| variable<br>변수 | value<br>값 |\n",
"|:---------------:|:---------------:|\n",
"| $b$ | 1/2 |\n",
"| $k$ | 1/3 |\n",
"* If these parameters change, what happens? Maybe simulations can show us.<br>이러한 매개변수들 값이 달라지면 어떻게 될 것인가? 시뮬레이션으로 확인해 보는 건 어떨까?\n",
"\n"
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"b = 0.5\n",
"k = 1.0/3\n",
"\n"
],
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"execution_count": null,
"outputs": []
"source": [
"* The following video illustrates how the susceptible, infected, and recovered populations change over time under different parameter values<br>아래 비디오에서 해당 SIR 모델이 매개변수에 따라 어떻게 다르게 거동하는지 관찰해 볼 수 있다.ㅠ\n",
"\n",
"[![video here](https://i.ytimg.com/vi/gxAaO2rsdIs/hqdefault.jpg)](https://youtu.be/gxAaO2rsdIs)\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Numerical Solution using `solve_ivp()`<br>`solve_ivp()` 수치해\n",
"\n"
],
"metadata": {}
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Slope function<br>기울기 함수\n",
"* Now let's implement the SIR model above and simulate.<br>이제 위 SIR 모델을 구현해 시험해 봅시다.\n",
"* Slope function<br>기울기 함수\n",
"\n"
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def dy_dt(t, y):\n",
" s = y[0]\n",
Expand All @@ -139,57 +146,59 @@
" k * i,\n",
" ))\n",
"\n"
],
"metadata": {},
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Simulation<br>시뮬레이션\n",
"* Simulation<br>시뮬레이션\n",
"\n"
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"delta_t = 1 # day\n",
"t_start = 0\n",
"t_end = 150 # day\n",
"\n",
"# Why the initial condition as follows?\n",
"# 왜 이러한 초기값을 사용하는가? \n",
"y0 = [1, 1.27e-6, 0]\n",
"\n",
"t_eval = np.arange(t_start, t_end, delta_t)\n",
"\n",
"sol = si.solve_ivp(dy_dt, (t_start, t_end), y0=y0, t_eval=t_eval)\n",
"\n"
],
"metadata": {},
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sol\n",
"\n"
],
"metadata": {},
"execution_count": null,
"outputs": []
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's plot.<br>그림으로 표시해 보자.\n",
"* Let's plot.<br>그림으로 표시해 보자.\n",
"\n"
],
"metadata": {}
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ylabels = ['s', 'i', 'r']\n",
"\n",
Expand All @@ -202,25 +211,70 @@
"\n",
"ax.set_xlabel('$t(sec)$');\n",
"\n"
],
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* What about stacking all three plots?<br>세 그래프를 수직으로 쌓아 보면 어떨까?\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"outputs": []
"metadata": {},
"outputs": [],
"source": [
"ylabels = ['s', 'i', 'r']\n",
"\n",
"plt.clf()\n",
"plt.stackplot(sol.t, sol.y)\n",
"plt.xlabel('$t(sec)$');\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"I hope your and everyone's hearlth<br>여러분 모두의 건강을 빕니다.\n",
"## I hope your and everyone's hearlth<br>여러분 모두의 건강을 빕니다.\n",
"\n"
],
"metadata": {}
]
},
{
"cell_type": "code",
"source": [],
"metadata": {},
"execution_count": null,
"outputs": []
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"colab": {
"include_colab_link": true,
"private_outputs": true,
"provenance": []
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.0"
}
]
},
"nbformat": 4,
"nbformat_minor": 4
}

0 comments on commit ae8b60b

Please sign in to comment.