Skip to content

Commit e5eabd4

Browse files
authored
Merge pull request #2 from Song921012/dev
Dev
2 parents e637347 + 64228ea commit e5eabd4

File tree

6 files changed

+211
-28
lines changed

6 files changed

+211
-28
lines changed

README.md

+63-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,66 @@
77
[![Build Status](https://ci.appveyor.com/api/projects/status/github/Song921012/MathepiaModels.jl?svg=true)](https://ci.appveyor.com/project/Song921012/MathepiaModels-jl)
88
[![Coverage](https://codecov.io/gh/Song921012/MathepiaModels.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/Song921012/MathepiaModels.jl)
99
[![Coverage](https://coveralls.io/repos/github/Song921012/MathepiaModels.jl/badge.svg?branch=main)](https://coveralls.io/github/Song921012/MathepiaModels.jl?branch=main)
10-
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
10+
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
11+
12+
MathepiaModels.jl is part of [Mathepia.jl: Spatial and temporal epidemiology data mining flow tools including data processing and analysis, model setup and simulation, inference and evaluation.](https://github.com/Song921012/Mathepia.jl)
13+
14+
It focuses on models setup, simulation and analysis. It is at very beginning stage. The followings are features will be included in the future.
15+
16+
Models will be designed to include
17+
- classical epidemic compartment models such as SIS, SIR, SEIR, SEIAR models and so on.
18+
- Network epidemic models
19+
- Agent based epidemic models
20+
- epidemic models with spatial and temporal heterogeneity, such as delayed, periodic, reaction diffusion epidemic models
21+
- models with neural networks embeded
22+
- models in some state-of-the-art references
23+
- users defined models
24+
25+
The ways to define epidemic models will include determinstic, stochastic methods.
26+
27+
Simulation will be designed to include
28+
- determinstic
29+
- stochastic
30+
31+
Analysis will be designed to include
32+
- Stability of disease free equilibria (DFE) and endemic equilibria (EE)
33+
- Calculation of basic reproduction number
34+
- Calculation of the peak of epidemic
35+
- Calculation of final epidemic size
36+
- Calculation of epidemicity
37+
- Calculation of herd immunity level
38+
- Calculation of time to extinction
39+
## Installation
40+
41+
The package can be installed with the Julia package manager.
42+
From the Julia REPL, type `]` to enter the Pkg REPL mode and run:
43+
44+
```
45+
pkg> add MathepiaModels
46+
```
47+
48+
Or, equivalently, via the `Pkg` API:
49+
50+
```julia
51+
julia> import Pkg; Pkg.add("MathepiaModels")
52+
```
53+
54+
## Documentation
55+
56+
- [**STABLE**](https://song921012.github.io/MathepiaModels.jl/stable/)
57+
- [**DEVEL**](https://song921012.github.io/MathepiaModels.jl/dev/)
58+
59+
60+
## Related Packages and Works
61+
62+
The other parts of [Mathepia.jl: Spatial and temporal epidemiology data mining flow tools](https://github.com/Song921012/Mathepia.jl) is as follows:
63+
- [MathepiaData.jl: Spatial and temporal data preprocessing and analysis](https://github.com/Song921012/MathepiaData.jl)
64+
- [MathepiaInference.jl: Bayesian inference tools.](https://github.com/Song921012/MathepiaInference.jl)
65+
- [MathepiaOptimal.jl: Optimization, optimal control and optimal transport tools](https://github.com/Song921012/MathepiaOptimal.jl)
66+
67+
MathepiaModels.jl is dependent on many packages from [SciML Open Source Scientific Machine Learning](https://github.com/SciML). They do a lot of excellent works and packages. Because of them, I find my idol [ChrisRackauckas](https://github.com/ChrisRackauckas), become to love julia and decide to do some contributions.
68+
69+
Other packages or works on epidemic models:
70+
71+
- [jangevaare/Pathogen.jl](https://github.com/jangevaare/Pathogen.jl)
72+
- [epirecipes/sir-julia: Various implementations of the classical SIR model in Julia](https://github.com/epirecipes/sir-julia)

src/MathepiaModels.jl

+3
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@ using Plots
55
include("Models/odecompartmentsmodel.jl")
66

77
export SIRbasic
8+
export SEIRbasic
9+
export SEIARbasic
10+
export SISbasic
811

912
end

src/Models/odecompartmentsmodel.jl

+85-7
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,97 @@ Define classic SIR(suspected-infected-recovered) model.
55
66
Parameters: (birth rate, natural death rate, disaese induced death rate, population, infection rate, recovery rate)
77
8-
``$$
8+
```math
99
\begin{aligned}
1010
& \frac{\rm{d}S}{\rm{dt}} = \Lambda -\beta S I/N - d S,\\
1111
&\frac{\rm{d}I}{\rm{dt}} = \beta S I/N - \gamma I - d I - \alpha I,\\
1212
&\frac{\rm{d}R}{\rm{dt}} = \gamma I - d R,\\
1313
\end{aligned}
14-
$$``
14+
```
1515
"""
16-
function SIRbasic(du, u, p,t)
17-
Λ,d,α,N,β,γ = p
18-
pop =>0&d>0) ? Λ/d : N
16+
function SIRbasic(du, u, p, t)
17+
Λ, d, α, N, β, γ = p
18+
pop = > 0 & d > 0) ? Λ / d : N
1919
S, I, R = u
20-
du[1] = Λ - β*S*I/pop - d*S
21-
du[2] = β*S*I/pop - γ * I - d*I -α * I
20+
du[1] = Λ - β * S * I / pop - d * S
21+
du[2] = β * S * I / pop - γ * I - d * I - α * I
2222
du[3] = γ * I - d * R
2323
end
24+
25+
26+
@doc raw"""
27+
SEIR(du,u,p,t)
28+
29+
Define classic SEIR(suspected-exposed-infected-recovered) model.
30+
31+
Parameters: (birth rate, natural death rate, disaese induced death rate, population, infection rate, recovery rate, incubation period,
32+
exposed decreasing infection ratio)
33+
34+
```math
35+
\begin{aligned}
36+
& \frac{\rm{d}S}{\rm{dt}} = \Lambda -\beta S (I+k_{E}E)/N - d S,\\
37+
&\frac{\rm{d}E}{\rm{dt}} = \beta S (I+k_{E}E)/N - \sigma E -d E,\\
38+
&\frac{\rm{d}I}{\rm{dt}} =\sigma E - \gamma I - d I - \alpha I,\\
39+
&\frac{\rm{d}R}{\rm{dt}} = \gamma I - d R,\\
40+
\end{aligned}
41+
```
42+
"""
43+
function SEIRbasic(du, u, p, t)
44+
Λ, d, α, N, β, γ, σ, ke = p
45+
pop => 0 & d > 0) ? Λ / d : N
46+
S, E, I, R = u
47+
du[1] = Λ - β * S * (I + ke * E) / pop - d * S
48+
du[2] = β * S * (I + ke * E) / pop - σ * E - d * E
49+
du[3] = σ * E - γ * I - d * I - α * I
50+
du[4] = γ * I - d * R
51+
end
52+
53+
@doc raw"""
54+
SEIAR(du,u,p,t)
55+
56+
Define classic SEIR(suspected-exposed-infected-asymptomatic-recovered) model.
57+
58+
Parameters: (birth rate, natural death rate, disaese induced death rate, population, infection rate, recovery rate, incubation period,
59+
exposed decreasing infection ratio, asymptomatic infection decreasing infection ratio, asymptomatic rate,recovery rate of asymptomatic)
60+
61+
```math
62+
\begin{aligned}
63+
& \frac{\rm{d}S}{\rm{dt}} = \Lambda -\beta S (I+k_{E}E+k_{A}A)/N - d S,\\
64+
&\frac{\rm{d}E}{\rm{dt}} = \beta S (I+k_{E}E++k_{A}A)/N - \sigma E -d E,\\
65+
&\frac{\rm{d}I}{\rm{dt}} =(1-\rho)\sigma E - \gamma I - d I - \alpha I,\\
66+
&\frac{\rm{d}A}{\rm{dt}} =\rho\sigma E - \gamma_{A} A - d A,\\
67+
&\frac{\rm{d}R}{\rm{dt}} = \gamma I +\gamma_{A} A - d R,\\
68+
\end{aligned}
69+
```
70+
"""
71+
function SEIARbasic(du, u, p, t)
72+
Λ, d, α, N, β, γ, σ, ke, ka, ρ, γA= p
73+
pop => 0 & d > 0) ? Λ / d : N
74+
S, E, I, A, R = u
75+
du[1] = Λ - β * S * (I + ke * E + ka * A) / pop - d * S
76+
du[2] = β * S * (I + ke * E + ka * A) / pop - σ * E - d * E
77+
du[3] = (1-ρ)*σ * E - γ * I - d * I - α * I
78+
du[3] = ρ * σ * E - γA * A - d * A
79+
du[4] = γ * I + γA * A - d * R
80+
end
81+
82+
@doc raw"""
83+
SIS(du,u,p,t)
84+
85+
Define classic SIR(suspected-infected-suspected) model.
86+
87+
Parameters: (population, infection rate, recovery rate)
88+
89+
```math
90+
\begin{aligned}
91+
& \frac{\rm{d}S}{\rm{dt}} = -\beta S I/N + \gamma I,\\
92+
&\frac{\rm{d}I}{\rm{dt}} = \beta S I/N - \gamma I,\\
93+
\end{aligned}
94+
```
95+
"""
96+
function SISbasic(du, u, p, t)
97+
pop, β, γ = p
98+
S, I = u
99+
du[1] = - β * S * I / pop + γ * I
100+
du[2] = β * S * I / pop - γ * I
101+
end

src/solve.jl

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
function solve end
2-
3-
function solve(model::SIR)
4-
function SIR_model(t,u,du)
5-
6-
end
1+
function solve end

test/Models/odecompartstest.jl

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using MathepiaModels
2+
using DifferentialEquations
3+
using Plots
4+
using Test
5+
const DE = DifferentialEquations
6+
@testset "SIRbasic" begin
7+
u_0 = [1000, 0.1, 0]
8+
p_data == 0, d = 0, α = 0, N = 1000, β = 0.2, γ = 0.1)
9+
tspan_data = (0.0, 100.0)
10+
prob_data = DE.ODEProblem(SIRbasic, u_0, tspan_data, p_data)
11+
data_solve = DE.solve(prob_data, Tsit5(), abstol = 1e-12, reltol = 1e-12, saveat = 0.1)
12+
data_withoutnois = Array(data_solve)
13+
data = data_withoutnois #+ Float32(2e-1)*randn(eltype(data_withoutnois), size(data_withoutnois))
14+
Plots.plot(data_solve.t, data[1, :], label = "Train S")
15+
Plots.plot!(data_solve.t, data[2, :], label = "Train I")
16+
@info "SIRbasic succeed"
17+
end
18+
19+
@testset "SEIRbasic" begin
20+
u_0 = [1000, 0, 1, 0]
21+
p_data == 0, d = 0, α = 0, N = 1000, β = 0.2, γ = 0.1, σ=1/5.2, ke = 0.3)
22+
tspan_data = (0.0, 100.0)
23+
prob_data = DE.ODEProblem(SEIRbasic, u_0, tspan_data, p_data)
24+
data_solve = DE.solve(prob_data, Tsit5(), abstol = 1e-12, reltol = 1e-12, saveat = 0.1)
25+
data_withoutnois = Array(data_solve)
26+
data = data_withoutnois #+ Float32(2e-1)*randn(eltype(data_withoutnois), size(data_withoutnois))
27+
Plots.plot(data_solve.t, data[1, :], label = "Train S")
28+
Plots.plot!(data_solve.t, data[2, :], label = "Train E")
29+
@info "SEIRbasic succeed"
30+
end
31+
32+
@testset "SEIARbasic" begin
33+
u_0 = [1000, 0, 1, 0, 0]
34+
p_data == 0, d = 0, α = 0, N = 1000, β = 0.2, γ = 0.1, σ=1/5.2, ke = 0.3, ka =0.3, ρ =0.3, γA = 0.1)
35+
tspan_data = (0.0, 100.0)
36+
prob_data = DE.ODEProblem(SEIARbasic, u_0, tspan_data, p_data)
37+
data_solve = DE.solve(prob_data, Tsit5(), abstol = 1e-12, reltol = 1e-12, saveat = 0.1)
38+
data_withoutnois = Array(data_solve)
39+
data = data_withoutnois #+ Float32(2e-1)*randn(eltype(data_withoutnois), size(data_withoutnois))
40+
@show Plots.plot(data_solve.t, data[1, :], label = "Train S")
41+
Plots.plot!(data_solve.t, data[2, :], label = "Train E")
42+
@info "SEIARbasic succeed"
43+
end
44+
45+
46+
@testset "SISbasic" begin
47+
u_0 = [1000, 1]
48+
p_data = (N = 1000, β = 0.2, γ = 0.1)
49+
tspan_data = (0.0, 1000.0)
50+
prob_data = DE.ODEProblem(SISbasic, u_0, tspan_data, p_data)
51+
data_solve = DE.solve(prob_data, Tsit5(), abstol = 1e-12, reltol = 1e-12, saveat = 0.1)
52+
data_withoutnois = Array(data_solve)
53+
data = data_withoutnois #+ Float32(2e-1)*randn(eltype(data_withoutnois), size(data_withoutnois))
54+
@show Plots.plot(data_solve.t, data[1, :], label = "Train S")
55+
Plots.plot!(data_solve.t, data[2, :], label = "Train E")
56+
@info "SIS succeed"
57+
end

test/runtests.jl

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
11
using MathepiaModels
2-
using DifferentialEquations
3-
using Plots
42
using Test
5-
const DE = DifferentialEquations
6-
@testset "MathepiaModels.jl" begin
7-
u_0 = [1000, 0.1, 0]
8-
p_data == 0, d = 0, α = 0, N = 1000, β = 0.2, γ = 0.1)
9-
tspan_data = (0.0, 100.0)
10-
prob_data = DE.ODEProblem(SIRbasic, u_0, tspan_data, p_data)
11-
data_solve = DE.solve(prob_data, Tsit5(), abstol = 1e-12, reltol = 1e-12, saveat = 0.1)
12-
data_withoutnois = Array(data_solve)
13-
data = data_withoutnois #+ Float32(2e-1)*randn(eltype(data_withoutnois), size(data_withoutnois))
14-
Plots.scatter(data_solve.t, data[1, :], label = "Train S")
15-
Plots.scatter!(data_solve.t, data[2, :], label = "Train I")
16-
end
3+
@info "Odecompartmentsmodel test"
4+
include("Models/odecompartstest.jl")

0 commit comments

Comments
 (0)