Skip to content

Commit e637347

Browse files
authored
Merge pull request #1 from Song921012/dev
SIRbasis
2 parents 6d3193c + 7aab664 commit e637347

File tree

7 files changed

+58
-3
lines changed

7 files changed

+58
-3
lines changed

Project.toml

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ uuid = "2bd2a319-f9c6-417c-a4f9-7b097fc62840"
33
authors = ["Pengfei Song"]
44
version = "0.1.0"
55

6+
[deps]
7+
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
8+
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
9+
610
[compat]
711
julia = "1.6"
812

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
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)

src/MathepiaModels.jl

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
module MathepiaModels
2+
using DifferentialEquations
3+
using Plots
24

3-
# Write your package code here.
5+
include("Models/odecompartmentsmodel.jl")
6+
7+
export SIRbasic
48

59
end

src/Models/odecompartmentsmodel.jl

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@doc raw"""
2+
SIR(du,u,p,t)
3+
4+
Define classic SIR(suspected-infected-recovered) model.
5+
6+
Parameters: (birth rate, natural death rate, disaese induced death rate, population, infection rate, recovery rate)
7+
8+
``$$
9+
\begin{aligned}
10+
& \frac{\rm{d}S}{\rm{dt}} = \Lambda -\beta S I/N - d S,\\
11+
&\frac{\rm{d}I}{\rm{dt}} = \beta S I/N - \gamma I - d I - \alpha I,\\
12+
&\frac{\rm{d}R}{\rm{dt}} = \gamma I - d R,\\
13+
\end{aligned}
14+
$$``
15+
"""
16+
function SIRbasic(du, u, p,t)
17+
Λ,d,α,N,β,γ = p
18+
pop =>0&d>0) ? Λ/d : N
19+
S, I, R = u
20+
du[1] = Λ - β*S*I/pop - d*S
21+
du[2] = β*S*I/pop - γ * I - d*I -α * I
22+
du[3] = γ * I - d * R
23+
end

src/solve.jl

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

src/type.jl

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
abstract type AbstractEpiModel end
2+
3+
mutable struct SIR <: AbstractEpiModel
4+
tspan::Tuple
5+
parameter:: NamedTuple
6+
saveat
7+
end

test/runtests.jl

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
using MathepiaModels
2+
using DifferentialEquations
3+
using Plots
24
using Test
3-
5+
const DE = DifferentialEquations
46
@testset "MathepiaModels.jl" begin
5-
# Write your tests here.
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")
616
end

0 commit comments

Comments
 (0)