epirecipes / sir-julia

Various implementations of the classical SIR model in Julia
MIT License
195 stars 39 forks source link

Fleck example with non-exponential distributions #111

Closed slwu89 closed 5 months ago

slwu89 commented 5 months ago

This PR will address #110. @sdwfrost I added a script in the tutorials/jump_process_fleck folder that demonstrates how to use Fleck to simulate arbitrary waiting times; I included Dirac and your Gamma(4,1) in the example but as you can see, it is extremely easy to use whatever you'd like!

A few notes about Fleck, it is designed for users to build further simulation models upon; it really is just responsible for handling the sampler for the next time and clock. It has a panopoly of sampling algorithms available (first reaction, direct methods, rejection, etc). For this script I used a next reaction method which should be competitive across many distribution types. Because Fleck is more of a tool to build simulation model frameworks rather than a full modeling suite, we need to make a struct to store the state and handle some updating logic.

The gist of Fleck is that you give a sampler a key type that it will use to uniquely identify clocks (i.e. in CombinedNextReaction{Tuple{Symbol,Int}} the tuple type is the clock key). You can enable a clock with enable! passing the sampler, the key, the distribution, the enabling time, the current world time, and an rng. You can disable a clock with enable! passing the sampler, the key, and the disabling time. You can ask the sampler for the next clock firing time and the key of the corresponding clock with next.

Please note that we are in the midst of working on a dev push to get some more features in prior to putting Fleck on the general repo, so I may need to update this in a few months. I'm making this a draft PR since I'm not sure how you'd want to explain what Fleck is in the jmd file.

sdwfrost commented 5 months ago

Thanks @slwu89! I understand that Fleck.jl is more a library than a framework - feel free to put in something in the intro as you see fit.

slwu89 commented 5 months ago

no problem @sdwfrost! Let me know what you think of the revised text.

sdwfrost commented 5 months ago

Thanks @slwu89! Having the extended distributions really helps.