UT-Covid / episimlab

Framework for development of epidemiological models
https://ut-covid.github.io/episimlab/
BSD 3-Clause "New" or "Revised" License
3 stars 1 forks source link

Generic SetupSampler for stochastic state transitions #46

Open kellypierce opened 2 years ago

kellypierce commented 2 years ago

There are two levels of stochasticity possible: stochastic parameter draws, e.g. sampling sigma from a triangular distribution as in

https://github.com/eho-tacc/episimlab/blob/d70b69066082a2e3526e1830e06272a03db74714/episimlab/setup/greek/sigma.py#L23

and stochastic state transitions as implemented in compt_model.py: https://github.com/eho-tacc/episimlab/blob/e74c298f964d015fde4813ceac6666a68cf97af3/episimlab/compt_model.py#L126

The individual parameters each have their own setup methods, giving flexibility on distribution use for each parameter. In contrast, state transitions will always share the same assumption on underlying probability distribution (if one is Poisson, all are Poisson).

But different models or different researchers might want to switch from Poisson to Binomial. A possible implementation would be a setup class for the state transitions, so when a user is writing a model file (their own version of models/partition_v1.py, they can use that setup class to select Poisson or Binomial state transitions.

ethho commented 2 years ago

The current way of doing this is to generate an integer seed seed_state at every step, managed by this process:

https://github.com/eho-tacc/episimlab/blob/295d24ca52af41b9ea861bf641ba6fc82d35d6aa/episimlab/setup/seed.py#L8-L8

...and consumed by processes when they need to perform some kind of stochastic draw, e.g. for sigma:

https://github.com/eho-tacc/episimlab/blob/295d24ca52af41b9ea861bf641ba6fc82d35d6aa/episimlab/setup/greek/sigma.py#L23-L41

Currently, the numpy.random.Generator instance gets constructed by different processes when they call the get_rng util:

https://github.com/eho-tacc/episimlab/blob/295d24ca52af41b9ea861bf641ba6fc82d35d6aa/episimlab/utils/rng.py#L5-L11