ConradKunadu / pathosim-obg

Pathosim for use by Oxford Biosecurity Group.
MIT License
0 stars 0 forks source link

Counterfactual RNG #1

Open adrian-lison opened 8 months ago

adrian-lison commented 8 months ago

Adjust seeding in pathosim to ensure that counterfactual simulation trajectories differ only with respect to the intervention's effects (ceteris paribus with respect to random events).

ToDos

adrian-lison commented 8 months ago

@ConradKunadu Do you have an intuition on whether stratification (e.g. age groups) or geographic structure could affect the random number generation, i.e. in the sense that they influence what random events occur or not? I haven't fully grasped how they are implemented and how they interact with the main simulation.

adrian-lison commented 8 months ago

Okay, I switched to hash-based RNG for all relevant functions. The majority of the infect() function is now also RNG safe, at the cost of more computational effort (basically, we draw random numbers also for events/quantities that do not apply and immediately throw them away. This is wasteful but ensures that the RNG state does not depend on the trajectory of the simulation. Hence, we get perfect counterfactual trajectories - everything will be the same unless it is actually affected by the counterfactual.

Only two parts are not yet RNG safe:

I will make separate issues for these, as they are not high priority. The nab one is probably more relevant to us than the coinfection one.

ConradKunadu commented 8 months ago

@ConradKunadu Do you have an intuition on whether stratification (e.g. age groups) or geographic structure could affect the random number generation, i.e. in the sense that they influence what random events occur or not? I haven't fully grasped how they are implemented and how they interact with the main simulation.

Great question. My impression is no, as the full population structure (including spatial heterogeneities) is generated before the simulation runs via the behaviour module, and then isn't touched by the behaviour module. The primary way in which the behaviour module affects pathogen transmission is via immunity and transmission between people via the allocation of contacts (which also by default doesn't change). Immunity plausibly does change over time, and may have rng effects, but this would be due to how immunity operates and not age. That'd be my suggestion to look into.

I've added the example to my branch here of how geog stratification and the behaviour module are actually implemented, however: https://github.com/ConradKunadu/pathosim-obg/blob/conrad/Studies/Study_Final.py

Please do verify and lmk what you find!