Closed glwagner closed 4 years ago
On my laptop it took 30 min to generate a daily cycle of contacts on a 100,000 node barabasi-albert graph with attachment parameter 2 (roughly 200,000 edges):
The subsequent 21-day kinetic simulation took 41 minutes.
Here's the result:
Needless to say if contacts were generated each time we can add roughly 11 hours to the above time.
This PR introduces the
EpidemicSimulator
for performing simulations of epidemics with evolving contact networks.The use of
EpidemicSimulator
is demonstrated inexamples/super_simple_epidemic.py
. It includes the ability to "cycle" contacts over a day, rather than generating new contacts for time interval of an epidemic simulation. We don't have a role for theHealthService
yet, but this should be easy.There are a few other major changes:
assign_ages
function that attaches ages to the nodes of a networkx GraphTransitionRates
, which means that the clinical parameters may either be:GammaSampler
,BetaSampler
, orAgeDependentBetaSampler
,AgeDependentConstant
.TransitionRates
then generates dictionaries for the transition rates. A unique mapping from list elements to node IDs is used by sorting the node IDs.It also puts the entire loop in the contact simulator into a numba function. This yields a further speed up of approx 2x, though YMMV.
On my laptop,
examples/super_simple_epidemic.py
--- which implements a 10,000 node, 21 day epidemic simulation --- takes ~70 s when cycling contacts, and 400 s when generating new contacts every day. It generates this plot: