generated from AlgebraicJulia/AlgebraicTemplate.jl
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from AlgebraicJulia/retry
Basic functionality
- Loading branch information
Showing
23 changed files
with
928 additions
and
110 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,7 @@ Manifest.toml | |
.DS_Store | ||
.vscode | ||
.ipynb_checkpoints | ||
|
||
cache/ | ||
|
||
figures/SIRSDiscretetrajectory.png |
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 |
---|---|---|
@@ -1,11 +1,19 @@ | ||
name = "AlgebraicABMS" | ||
uuid = "1301f41b-2c8a-4430-9d85-ab97d23a62cd" | ||
name = "AlgebraicABMs" | ||
uuid = "5a5e3447-9604-46e6-8d91-cb86f5f51721" | ||
license = "MIT" | ||
authors = ["AlgebraicJulia Developer <[email protected]>"] | ||
authors = ["Kris Brown <[email protected]>"] | ||
version = "0.0.1" | ||
|
||
[deps] | ||
AlgebraicPetri = "4f99eebe-17bf-4e98-b6a1-2c4f205a959b" | ||
AlgebraicRewriting = "725a01d3-f174-5bbd-84e1-b9417bad95d9" | ||
Catlab = "134e5e36-593f-5add-ad60-77f754baafbe" | ||
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" | ||
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" | ||
Fleck = "5bb9b785-358c-4fee-af0f-b94a146244a8" | ||
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" | ||
Reexport = "189a3867-3050-52da-a836-e630ba90ab69" | ||
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" | ||
|
||
[compat] | ||
Catlab = "^0.16" | ||
|
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 |
---|---|---|
@@ -1,4 +1,11 @@ | ||
[deps] | ||
AlgebraicABMS = "1301f41b-2c8a-4430-9d85-ab97d23a62cd" | ||
AlgebraicABMs = "5a5e3447-9604-46e6-8d91-cb86f5f51721" | ||
AlgebraicPetri = "4f99eebe-17bf-4e98-b6a1-2c4f205a959b" | ||
AlgebraicRewriting = "725a01d3-f174-5bbd-84e1-b9417bad95d9" | ||
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" | ||
Catlab = "134e5e36-593f-5add-ad60-77f754baafbe" | ||
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" | ||
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" | ||
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306" | ||
LiveServer = "16fef848-5104-11e9-1b77-fb7a48bbb589" | ||
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" |
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,41 @@ | ||
# # Petri Net rewriting | ||
# | ||
# First we want to load our package with `using` | ||
|
||
using AlgebraicABMs | ||
using Catlab, AlgebraicPetri # for declaring model building blocks | ||
using Distributions # for defining hazard rates | ||
|
||
# ## Schema | ||
# | ||
# We create a regular grid | ||
|
||
@present SchLife(FreeSchema) begin | ||
Cell::Ob | ||
(N,E,W,S)::Hom(Cell,Cell) | ||
Life::Ob | ||
live::Hom(Life,Cell) | ||
end | ||
|
||
# We define a network of cells | ||
|
||
@present SchLifeGraph <: SchSymmetricGraph begin | ||
Life::Ob | ||
live::Hom(Life,V) | ||
end | ||
|
||
@acset_type Life(SchLifeGraph) <: AbstractSymmetricGraph | ||
|
||
function living_neighbors(n::Int; alive=false) | ||
X = Life(1) | ||
alive && add_part!(X, :Live, live=1) | ||
for _ in 1:n | ||
v = add_part!(X, :V) | ||
add_part!(X, :Life, live=v) | ||
add_edge!(X, v, 1) | ||
end | ||
X | ||
end | ||
|
||
living_neighbors(2) | ||
|
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# # Petri Net rewriting | ||
# | ||
# First we want to load our package with `using` | ||
|
||
using AlgebraicABMs | ||
using Catlab, AlgebraicPetri # for declaring model building blocks | ||
using Distributions # for defining hazard rates | ||
using Makie, CairoMakie # visualization | ||
|
||
# ## Petri-net based model | ||
# | ||
# We define an SIRS model with birth and death | ||
|
||
sir_pn= @acset LabelledPetriNet begin | ||
S=3; sname=[:S,:I,:R] | ||
T=7; tname=[:inf,:rec,:birth,:deathS,:deathI,:deathR,:wane] | ||
I=7; it=[1,1,2,4,5,6,7]; is=[1,2,2,1,2,3,3] | ||
O=5; ot=[1,1,2,3,7]; os=[2,2,3,1,1] | ||
end | ||
|
||
to_graphviz(sir_pn) | ||
|
||
# A "state of the world" in this model is just a finite set of Susceptible, Infected, and Recovered people. Thus we can specify a model with 3 integers. | ||
|
||
init = PetriNetCSet(sir_pn, S=100, I=5); # Initial state | ||
|
||
|
||
# We declare parameters to specify the random waiting times | ||
pS, pI, pR = 95,5,0 | ||
pop = 100 | ||
lifespan = 65*365 | ||
μ = 1/lifespan | ||
β = 0.001 | ||
wane = 60; | ||
|
||
# We associate with each transition a function which takes a time point and return a distribution of waiting times | ||
clockdists = Dict{Symbol,Function}(); | ||
|
||
## the Exponential clocks (Markov) | ||
clockdists[:inf] = (t) -> Exponential(1 / β) | ||
clockdists[:birth] = (t) -> Exponential(1 / (μ*pop)) | ||
clockdists[:deathS] = (t) -> Exponential(1 / μ) | ||
clockdists[:deathI] = (t) -> Exponential(1 / μ) | ||
clockdists[:deathR] = (t) -> Exponential(1 / μ) | ||
clockdists[:wane] = (t) -> Exponential(wane) | ||
|
||
## the Weibull clock (non-Markov) | ||
α, θ = weibullpar(30, 5) | ||
clockdists[:rec] = (t) -> Weibull(α, θ); | ||
|
||
# We make a reporting function that extracts information from each time step. | ||
count(acs::ACSet) = | ||
NamedTuple(Dict([o => nparts(acs, o) for o in ob(acset_schema(acs))])); | ||
|
||
|
||
# We simulate a model | ||
sirout = run!(sir_pn, clockdists, init; save=count, maxevent=2000) | ||
X = first.(sirout) | ||
SIR = [getindex.(last.(sirout), x) for x in 1:3] | ||
f = Figure(); | ||
Legend(f[1, 2], lines!.(Ref(Axis(f[1,1])), Ref(X), SIR), ["S", "I","R"]) | ||
|
||
## We can also save the figure to the filesystem. | ||
isdir("figures") || mkdir("figures"); | ||
Makie.save("figures/SIRSDiscretetrajectory.png", f, px_per_unit=1, size=(800,600)); | ||
|
||
f | ||
|
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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
# Library Reference | ||
|
||
```@autodocs | ||
Modules = [AlgebraicABMS] | ||
Modules = [ | ||
AlgebraicABMs.Distributions, | ||
AlgebraicABMs.PetriInterface, | ||
AlgebraicABMs.RewriteSemiMarkov | ||
] | ||
``` |
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 |
---|---|---|
@@ -1,7 +1,10 @@ | ||
# AlgebraicABMS.jl | ||
# AlgebraicABMs.jl | ||
|
||
```@meta | ||
CurrentModule = AlgebraicABMS | ||
CurrentModule = AlgebraicABMs | ||
``` | ||
|
||
`AlgebraicABMS.jl` is a Julia library for... | ||
`AlgebraicABMs.jl` is a Julia library for creating agent-based models. We ultimate want to provide capabilities on par with software like AnyLogic, NetLogo, and Agents.jl - all while offering a mostly declarative interface such that: | ||
- The model's logic is transparent (rather than hidden away in complicated interactions of code blocks) | ||
- Models can be built compositionally (we can naturally 'glue' models together at a high level, without worrying about implementation details and edge-cases) | ||
- Models can be _migrated_ at a high level, whether interpersonally (collaboration with others who have a different ontology/vocabulary) or intrapersonally (one updates one's own model of the of world and wishes to reuse one's old model under new assumptions, without having to manually refactor code and dig into implementation details). |
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.