canmod / macpan2

Rebuilding https://github.com/mac-theobio/McMasterPandemic/
https://canmod.github.io/macpan2/
GNU General Public License v3.0
2 stars 0 forks source link

integrate `adaptivetau` for stochastic model simulation #114

Open papsti opened 1 year ago

papsti commented 1 year ago

i imagine folks who work with compartmental models may occasionally want to simulate them stochastically. for example, me :)

david suggested using adaptivetau as opposed to implementing the Gillespie algorithm directly in macpan2. @bbolker may have some opinions on software design/implementation to add here.

this feature could help me with a project over the next month or two, but i understand if it's not a priority compared to other features. i will likely start by trying to use adaptivetau directly with a simple model.

bbolker commented 1 year ago

Do you mean using the adaptivetau package? Unfortunately I don't see an easy way to integrate R code at this level (macpan is fast because it stays in TMB-land for the whole simulation path). I don't honestly know the best way to implement continuous-time (or approximate continuous-time) stochastic simulation at the moment - I think it might actually be pretty tricky since it would involve a departure from our hard-coded assumption of fixed time steps. I initially thought that @Flynn-Primrose's new integration methods machinery could handle this, but now I don't think so ...

A big question is how attached you are to continuous-time methods - could you get by with fixed daily time steps? Machinery already exists to generate Poisson, normal, and negative binomial deviates on the fly (binomial, multinomial, and overdispersed analogues [beta-binomial, Dirichlet-multinomial?] would probably be useful as well), although I'm pretty sure its use is not yet documented anywhere ...