stewid / SimInf

A framework for data-driven stochastic disease spread simulations
http://stewid.github.io/SimInf/
GNU General Public License v3.0
33 stars 14 forks source link

Pause and resume run to input new events #51

Closed loganwur closed 9 months ago

loganwur commented 9 months ago

Dear authors,

I am looking for a way to pause a model run at a predefined timepoint, extract information to create new events, insert the events, and resume the model run. I hope I haven't missed anything in the documentation. Is this possible? I thought I was on to something with the continue() function, but it seems I was wrong.

Cheers,

Logan

trosendal commented 9 months ago

This functionality is no problem. If you look at this repository: https://github.com/KSTuominen/LAMRSAControl you can see a quite advanced model with many nodes where the external transfers are created "between" time steps by starting and stopping a SimInf model. The essence is the you 1. set your initial state of your nodes in u0 and add the exttrans events that you would like to have for just the following day. 2. Run the model 1 timestep by setting tspan to 1. 3. Collect the trajectory from that run and and determine the extrans you want for the next day; replace your events in the model object with you new events and create a new u0 from the trajectory 4. Run the model with tspan = 2. Repeat day by day. Once you have done this once you could append all your events and run the model from time 1 to n which will be much faster of course. One pitfall that you should be careful with is to consider using events with proportions instead of absolute counts since when you run the model later with the same events your states could be different if you have any propensities that include stochastic births or deaths.

loganwur commented 9 months ago

Hi trosendal. Thanks a lot for this. This is clear and exactly what I was looking for. I'll implement it this way, then! I appreciate you.