epirecipes / sir-julia

Various implementations of the classical SIR model in Julia
MIT License
196 stars 38 forks source link

Added AlgebraicPetri impplementations of SIR model #8

Closed mehalter closed 4 years ago

mehalter commented 4 years ago

I am working with the AlgebraicJulia organization to help build a category theory based modeling framework for defining scientific models. We have recently put out AlgebraicPetri which allows you to define Petri net models using this new framework by defining building block Petri nets as open systems, and combine them through composition. This includes an Epidemiology module to make it easy to define models such as SIR. I have included some examples of using this method to create an SIR model, and then uses Petri.jl to generate solvers using OrdinaryDiffEq.jl, StochasticDiffEq.jl, and DiffEqJump.jl.

I would love to get these added to the collection of Julia implementations of SIR, and any feedback on these example tutorials would be great!

sdwfrost commented 4 years ago

Thanks! Let me take a look at these and give some feedback - I mostly want to ensure a consistent parameterization/look, and that examples are as bite-sized as possible with few dependencies. I already had coded up the SIR model using Petri.jl, but was struggling with AlgebraicPetri.jl - I saw the Epidemiology module but was trying to keep everything in a single customizable script. I'd love to get some simple examples of (a) an age structured model (b) method of stages to give an Erlang distribution for infection duration.

Ultimately, I'd like to get an idea of how you can put together a model like @gbohner Coexist model using AlgebraicPetri.jl rather than the Einstein summation approach.

sdwfrost commented 4 years ago

Is there a way to add the code from AlgebraicPetri.Epidemiology inline into the script so that it's more transparent? I (and I'm sure many others) aren't familiar with category theory, so it would be more educational to have those inline and inspectable, and link out to your more convenient interface.

I'll add a vanilla Petri.jl implementation of these (I saw that you added SDE and jump process output just a few hours ago).

sdwfrost commented 4 years ago

While I like bitesize implementations, I think it detracts from the power of a high-level representation to have the SDE, ODE and SSA systems separated into three separate tutorials. Here's what I did with ModelingToolkit: https://github.com/epirecipes/sir-julia/blob/master/markdown/rn_mtk/rn_mtk.md

mehalter commented 4 years ago

Thanks for the feedback! I'll add some snippets from the AlgebraicPetri.Epidemiology to show how the category and interactions are defined and group them all into together. Also I started an implementation of the coexist model using AlgebraicPetri tonight. Tomorrow I'll try to finish it and polish it up and add it as an example in the documentation to give a clear example of how to extend the library definitions to handle a model like that!

sdwfrost commented 4 years ago

There's also https://github.com/vollmersj/coexist.jl which is a Julia port, if that helps

mehalter commented 4 years ago

I just updated the AlgebraicPetri.jl tutorial to combine it into a single tutorial with some source code snippets to show how the theory of Epidemiology is defined.

sdwfrost commented 4 years ago

Thanks @mehalter! This is great.