forked from jupyter-book/jupyter-book
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
2,841 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
--- | ||
title: 'Scaling model' | ||
permalink: 'chapters/deleo1996/intro' | ||
previouschapter: | ||
url: chapters/sis/js_observable | ||
title: 'Javascript using Observable' | ||
nextchapter: | ||
url: chapters/deleo1996/julia | ||
title: 'Julia' | ||
redirect_from: | ||
- 'chapters/deleo1996/intro' | ||
--- | ||
|
||
## Basic microparasite model | ||
|
||
*Author*: Christopher Davis | ||
|
||
*Date*: 2018-10-02 | ||
|
||
### Description | ||
|
||
A basic microparasite model of susceptibles and infecteds with the force of infection density dependent. $\beta_{\text{min}}$ is the minimum value of the transmission rate $\beta$, such that the disease will spread. | ||
|
||
### Equations | ||
|
||
$$ | ||
\frac{dS(t)}{dt} = (\nu - \mu)\left(1- \frac{S(t)}{K}\right) S(t)- \beta S(t) I(t)\\ | ||
\frac{dI(t)}{dt} = \beta S(t) I(t)- (\mu +\ \alpha) I(t)\\ | ||
$$ | ||
|
||
### References | ||
|
||
- [De Leo GA, Dobson AP (February, 1996). "Allometry and simple epidemic models for microparasites". Nature. 379(6567):720](https://doi.org/10.1038/379720a0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
--- | ||
interact_link: notebooks/deleo1996/julia.ipynb | ||
title: 'Julia' | ||
permalink: 'chapters/deleo1996/julia' | ||
previouschapter: | ||
url: chapters/deleo1996/intro | ||
title: 'Scaling model' | ||
nextchapter: | ||
url: chapters/deleo1996/python | ||
title: 'Python' | ||
redirect_from: | ||
- 'chapters/deleo1996/julia' | ||
--- | ||
|
||
### De Leo et al. scaling model in Julia | ||
|
||
*Author*: Christopher Davis | ||
|
||
*Date*: 2018-10-02 | ||
|
||
|
||
{:.input_area} | ||
```julia | ||
using DifferentialEquations | ||
``` | ||
|
||
|
||
{:.input_area} | ||
```julia | ||
micro_1 = @ode_def Micro1 begin | ||
dS = r*(1-S/K)*S - β*S*I | ||
dI = β*S*I-(μ+α)*I | ||
end β r μ K α | ||
``` | ||
|
||
|
||
|
||
|
||
{:.output_data_text} | ||
``` | ||
(::Micro1) (generic function with 4 methods) | ||
``` | ||
|
||
|
||
|
||
|
||
{:.input_area} | ||
```julia | ||
w = 1; | ||
m = 10; | ||
β = 0.0247*m*w^0.44; | ||
r = 0.6*w^-0.27; | ||
μ = 0.4*w^-0.26; | ||
K = 16.2*w^-0.7; | ||
α = (m-1)*μ; | ||
``` | ||
|
||
|
||
{:.input_area} | ||
```julia | ||
parms = [β,r,μ,K,α]; | ||
init = [K,1.]; | ||
tspan = (0.0,10.0); | ||
``` | ||
|
||
|
||
{:.input_area} | ||
```julia | ||
sir_prob = ODEProblem(micro_1,init,tspan,parms) | ||
``` | ||
|
||
|
||
|
||
|
||
{:.output_data_text} | ||
``` | ||
DiffEqBase.ODEProblem with uType Array{Float64,1} and tType Float64. In-place: true | ||
timespan: (0.0, 10.0) | ||
u0: [16.2, 1.0] | ||
``` | ||
|
||
|
||
|
||
|
||
{:.input_area} | ||
```julia | ||
sir_sol = solve(sir_prob); | ||
``` | ||
|
||
#### Visualisation | ||
|
||
|
||
{:.input_area} | ||
```julia | ||
using Plots | ||
``` | ||
|
||
|
||
{:.input_area} | ||
```julia | ||
plot(sir_sol,xlabel="Time",ylabel="Number") | ||
``` | ||
|
||
|
||
|
||
|
||
![svg](../../images/chapters/deleo1996/julia_10_0.svg) | ||
|
||
|
||
|
||
#### Threshold criterion for transmission rate | ||
|
||
|
||
{:.input_area} | ||
```julia | ||
m = [5,10,20,40] | ||
ws = 10.^linspace(-3,3,601) | ||
βs = zeros(601,4) | ||
for i = 1:4 | ||
βs[:,i] = 0.0247*m[i]*ws.^0.44 | ||
end | ||
plot(ws,βs,xlabel="Weight",ylabel="\\beta_min", xscale=:log10,yscale=:log10, label=["m = 5" "m = 10" "m = 20" "m = 40"],lw=3) | ||
``` | ||
|
||
|
||
|
||
|
||
![svg](../../images/chapters/deleo1996/julia_12_0.svg) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
--- | ||
interact_link: notebooks/deleo1996/python.ipynb | ||
title: 'Python' | ||
permalink: 'chapters/deleo1996/python' | ||
previouschapter: | ||
url: chapters/deleo1996/julia | ||
title: 'Julia' | ||
nextchapter: | ||
url: chapters/deleo1996/r_desolve | ||
title: 'R using deSolve' | ||
redirect_from: | ||
- 'chapters/deleo1996/python' | ||
--- | ||
|
||
### Python using SciPy | ||
|
||
*Author*: Christopher Davis | ||
|
||
*Date*: 2018-10-02 | ||
|
||
|
||
{:.input_area} | ||
```python | ||
import numpy as np | ||
from scipy.integrate import ode, solve_ivp | ||
``` | ||
|
||
|
||
{:.input_area} | ||
```python | ||
def micro_1(times,init,parms): | ||
beta, r, mu, K, alpha = parms | ||
S,I = init | ||
# ODEs | ||
dS = r*(1-S/K)*S - beta*S*I | ||
dI = beta*S*I-(mu + alpha)*I | ||
return [dS,dI] | ||
``` | ||
|
||
|
||
{:.input_area} | ||
```python | ||
w = 1 | ||
m = 10 | ||
beta = 0.0247*m*w**0.44 | ||
r = 0.6*w**-0.27 | ||
mu = 0.4*w**-0.26 | ||
K = 16.2*w**-0.7 | ||
alpha = (m-1)*mu | ||
``` | ||
|
||
|
||
{:.input_area} | ||
```python | ||
parms = [beta,r,mu,K,alpha] | ||
init = [K,1.] | ||
times = np.linspace(0,10,101) | ||
``` | ||
|
||
|
||
{:.input_area} | ||
```python | ||
sir_sol = solve_ivp(fun=lambda t, y: micro_1(t, y, parms), t_span=[min(times),max(times)], y0=init, t_eval=times) | ||
``` | ||
|
||
#### Visualisation | ||
|
||
|
||
{:.input_area} | ||
```python | ||
import matplotlib.pyplot as plt | ||
``` | ||
|
||
|
||
{:.input_area} | ||
```python | ||
plt.plot(sir_sol.t,sir_sol.y[0],color="red",linewidth=2, label = "S(t)") | ||
plt.plot(sir_sol.t,sir_sol.y[1],color="blue",linewidth=2, label = "I(t)") | ||
plt.xlabel("Time") | ||
plt.ylabel("Number") | ||
plt.legend() | ||
``` | ||
|
||
|
||
|
||
|
||
{:.output_data_text} | ||
``` | ||
<matplotlib.legend.Legend at 0x7f776a919198> | ||
``` | ||
|
||
|
||
|
||
|
||
![png](../../images/chapters/deleo1996/python_9_1.png) | ||
|
||
|
||
#### Threshold criterion for transmission rate | ||
|
||
|
||
{:.input_area} | ||
```python | ||
m = [5,10,20,40] | ||
ws = 10**np.linspace(-3,3,601) | ||
betas = np.zeros((601,4)) | ||
for i in range(4): | ||
betas[:,i] = 0.0247*m[i]*ws**0.44 | ||
plt.loglog(ws,betas) | ||
plt.xlabel("Weight") | ||
plt.ylabel(r'$\beta_{min}$') | ||
plt.legend(("m = 5", "m = 10", "m = 20", "m = 40")) | ||
``` | ||
|
||
|
||
|
||
|
||
{:.output_data_text} | ||
``` | ||
<matplotlib.legend.Legend at 0x7f7769b707f0> | ||
``` | ||
|
||
|
||
|
||
|
||
![png](../../images/chapters/deleo1996/python_11_1.png) | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.