mirror of https://github.com/mehalter/Petri.jl.git
Browse Source
Documentation Update (#28)
Documentation Update (#28)
* Updated docs to use Literate.jl to generate example notebooks * Update README and docspull/29/head
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 183 additions and 178 deletions
-
1.gitignore
-
104README.md
-
5docs/Project.toml
-
32docs/make.jl
-
11docs/src/assets/analytics.js
-
35docs/src/index.md
-
1examples/Project.toml
-
96examples/epidemiology.jl
-
76examples/epidemiologyModels.jl
@ -1,3 +1,8 @@ |
|||
[deps] |
|||
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" |
|||
LabelledArrays = "2ee39098-c373-598a-b85f-a56591580800" |
|||
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306" |
|||
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" |
|||
Petri = "4259d249-1051-49fa-8328-3f8ab9391c33" |
|||
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" |
|||
StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0" |
@ -0,0 +1,11 @@ |
|||
var _paq = window._paq || []; |
|||
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */ |
|||
_paq.push(['trackPageView']); |
|||
_paq.push(['enableLinkTracking']); |
|||
(function() { |
|||
var u="https://matomo.mehalter.com/"; |
|||
_paq.push(['setTrackerUrl', u+'matomo.php']); |
|||
_paq.push(['setSiteId', '4']); |
|||
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; |
|||
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s); |
|||
})(); |
@ -0,0 +1,96 @@ |
|||
# # [Basic Epidemiology Models](@id epidemiology_example) |
|||
# |
|||
#md # [](@__NBVIEWER_ROOT_URL__/examples/epidemiology.ipynb) |
|||
|
|||
using Petri |
|||
using LabelledArrays |
|||
using StochasticDiffEq |
|||
using OrdinaryDiffEq |
|||
using Plots |
|||
|
|||
# ### SIR Model |
|||
# |
|||
# The SIR model represents the epidemiological dynamics of an infectious disease |
|||
# that causes immunity in its victims. There are three *states:* `Suceptible |
|||
# ,Infected, Recovered`. These states interact through two *transitions*. |
|||
# Infection has the form `S+I -> 2I` where a susceptible person meets an |
|||
# infected person and results in two infected people. The second transition is |
|||
# recovery `I -> R` where an infected person recovers spontaneously. |
|||
|
|||
S = [:S,:I,:R] |
|||
Δ = LVector( |
|||
inf=(LVector(S=1, I=1), LVector(I=2)), |
|||
rec=(LVector(I=1), LVector(R=1)), |
|||
) |
|||
sir = Petri.Model(S, Δ) |
|||
|
|||
Graph(sir) |
|||
|
|||
# Once a model is defined, we can define out initial parameters `u0`, a time |
|||
# span `tspan`, and the transition rates of the interactions `β` |
|||
|
|||
u0 = LVector(S=10.0, I=1.0, R=0.0) |
|||
tspan = (0.0,7.5) |
|||
β = LVector(inf=0.4, rec=0.4); |
|||
|
|||
# Petri.jl provides interfaces to StochasticDiffEq.jl and OrdinaryDiffEq.jl |
|||
# Here, we call the `SDEProblem` function that returns an StochasticDiffEq |
|||
# problem object and an appropriate Callback set that can be passed to the |
|||
# StochasticDiffEq solver which can then be plotted and visualized |
|||
|
|||
prob, cb = SDEProblem(sir, u0, tspan, β) |
|||
|
|||
sol = StochasticDiffEq.solve(prob,SRA1(),callback=cb) |
|||
|
|||
plot(sol) |
|||
|
|||
# Similarly, we can generated `ODEProblem` statements that can be used with |
|||
# OrdinOrdinaryDiffEq solvers |
|||
|
|||
prob = ODEProblem(sir, u0, tspan, β) |
|||
sol = OrdinaryDiffEq.solve(prob,Tsit5(),reltol=1e-8,abstol=1e-8) |
|||
|
|||
plot(sol) |
|||
|
|||
# ### SEIR Model |
|||
|
|||
S = [:S,:E,:I,:R] |
|||
Δ = LVector( |
|||
exp=(LVector(S=1, I=1), LVector(I=1, E=1)), |
|||
inf=(LVector(E=1), LVector(I=1)), |
|||
rec=(LVector(I=1), LVector(R=1)), |
|||
) |
|||
seir = Petri.Model(S, Δ) |
|||
|
|||
Graph(seir) |
|||
#- |
|||
u0 = LVector(S=10.0, E=1.0, I=0.0, R=0.0) |
|||
tspan = (0.0,15.0) |
|||
β = LVector(exp=0.9, inf=0.2, rec=0.5) |
|||
|
|||
prob, cb = SDEProblem(seir, u0, tspan, β) |
|||
sol = StochasticDiffEq.solve(prob,SRA1(),callback=cb) |
|||
|
|||
plot(sol) |
|||
|
|||
# ### SEIRD Model |
|||
|
|||
S = [:S,:E,:I,:R, :D] |
|||
Δ = LVector( |
|||
exp=(LVector(S=1, I=1), LVector(I=1, E=1)), |
|||
inf=(LVector(E=1), LVector(I=1)), |
|||
rec=(LVector(I=1), LVector(R=1)), |
|||
die=(LVector(I=1), LVector(D=1)), |
|||
) |
|||
seird = Petri.Model(S, Δ) |
|||
|
|||
Graph(seird) |
|||
#- |
|||
u0 = LVector(S=10.0, E=1.0, I=0.0, R=0.0, D=0.0) |
|||
tspan = (0.0,15.0) |
|||
β = LVector(exp=0.9, inf=0.2, rec=0.5, die=0.1) |
|||
|
|||
prob, cb = SDEProblem(seird, u0, tspan, β) |
|||
sol = StochasticDiffEq.solve(prob,SRA1(),callback=cb) |
|||
|
|||
plot(sol) |
@ -1,76 +0,0 @@ |
|||
# -*- coding: utf-8 -*- |
|||
using Petri |
|||
using LabelledArrays |
|||
using StochasticDiffEq |
|||
using OrdinaryDiffEq |
|||
using Plots |
|||
|
|||
@show "SIR" |
|||
|
|||
S = [:S,:I,:R] |
|||
Δ = LVector( |
|||
inf=(LVector(S=1, I=1), LVector(I=2)), |
|||
rec=(LVector(I=1), LVector(R=1)), |
|||
) |
|||
sir = Petri.Model(S, Δ) |
|||
|
|||
u0 = LVector(S=10.0, I=1.0, R=0.0) |
|||
tspan = (0.0,7.5) |
|||
β = LVector(inf=0.4, rec=0.4) |
|||
|
|||
|
|||
prob, cb = SDEProblem(sir, u0, tspan, β) |
|||
|
|||
sol = StochasticDiffEq.solve(prob,SRA1(),callback=cb) |
|||
|
|||
plot(sol) |
|||
|
|||
prob = ODEProblem(sir, u0, tspan, β) |
|||
sol = OrdinaryDiffEq.solve(prob,Tsit5(),reltol=1e-8,abstol=1e-8) |
|||
|
|||
plot(sol) |
|||
|
|||
Graph(sir) |
|||
|
|||
@show "SEIR" |
|||
|
|||
S2 = [:S,:E,:I,:R] |
|||
Δ2 = LVector( |
|||
exp=(LVector(S=1, I=1), LVector(I=1, E=1)), |
|||
inf=(LVector(E=1), LVector(I=1)), |
|||
rec=(LVector(I=1), LVector(R=1)), |
|||
) |
|||
seir = Petri.Model(S2, Δ2) |
|||
|
|||
u0 = LVector(S=10.0, E=1.0, I=0.0, R=0.0) |
|||
tspan = (0.0,15.0) |
|||
β = LVector(exp=0.9, inf=0.2, rec=0.5) |
|||
|
|||
prob, cb = SDEProblem(seir, u0, tspan, β) |
|||
sol = StochasticDiffEq.solve(prob,SRA1(),callback=cb) |
|||
|
|||
plot(sol) |
|||
|
|||
Graph(seir) |
|||
|
|||
@show "SEIRD" |
|||
|
|||
S3 = [:S,:E,:I,:R, :D] |
|||
Δ3 = LVector( |
|||
exp=(LVector(S=1, I=1), LVector(I=1, E=1)), |
|||
inf=(LVector(E=1), LVector(I=1)), |
|||
rec=(LVector(I=1), LVector(R=1)), |
|||
die=(LVector(I=1), LVector(D=1)), |
|||
) |
|||
seird = Petri.Model(S3, Δ3) |
|||
|
|||
u0 = LVector(S=10.0, E=1.0, I=0.0, R=0.0, D=0.0) |
|||
tspan = (0.0,15.0) |
|||
β = LVector(exp=0.9, inf=0.2, rec=0.5, die=0.1) |
|||
|
|||
prob, cb = SDEProblem(seird, u0, tspan, β) |
|||
sol = StochasticDiffEq.solve(prob,SRA1(),callback=cb) |
|||
|
|||
plot(sol) |
|||
|
|||
Graph(seird) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue