SynchronousDynamics: Synchronous process dynamics
- class epydemic.SynchronousDynamics(p, g=None)
Bases:
DynamicsA dynamics that runs synchronously in discrete time, applying local rules to each node in the network. These are simple to understand and simple to code for many cases, but can be statistically inexact and slow for large systems.
- Parameters:
p (
Process) – the network process to rung (
Union[Graph,NetworkGenerator]) – prototype network to run over (optional)
Extra metadata
-
SynchronousDynamics.TIMESTEPS_WITH_EVENTS:
Final[str] = 'epydemic.dynamics.timesteps_with_events' Metadata element holding the number timesteps that actually had events occur within them
Running a dynamics
Synchronous dynamics works as follows:
Any events posted for (or before) the current simulation time are fired by calling
Dynamics.runPendingEvents().The stochastic and fixed-rate events are extracted using
SynchronousDynamics.allEventsInTimestep()The events are fired in the order returned. All events are “fire-able” at the start of the timestep; they may not actually be fired if a previous (in the same timestep) has removed the event’s element from the locus.
The number of events fired is updated.
The current simulation time is updated.
This continues until the process indicates that it has reached equilibrium, as determined by
Process.atEqulibrium().
The exact events determined to be fire-able are computed by
allEventsInTimestep(), which by default does the following:
Accesses the underlying process to acquire the event distribution for per-element events by calling
Process.perElementEventDistribution().For each locus having elements, it selects each element in turn and decides whether to fire an event at this element based on the probability given for that event.
Accesses the fixed-rate event distribution of the process by calling
Process.fixedRateEventDistribution()For each non-empty locus, it chooses at event with the probability given for that event, chooses a random element on which to fire it.
Firing an event first calls its event function and then reports its firing to the event tap.
- SynchronousDynamics.do(params)
Execute the process under synchronous dynamics.
- Parameters:
params (
Dict[str,Any]) – the parameters of the simulation- Return type:
Dict[str,Any]- Returns:
a dict of experimental results
- SynchronousDynamics.allEventsInTimestep(t)
Return the list of events to be executed in this timestep. This includes both the stochastic and fixed-rate events, but does not include posted events.
By default this method accesses the stochastic event distribution and looks at each event type in the order in which they were registered by
Process.build(). It chooses those events that should be fired based on the choice probability, and returns them in order. It then re-visits the distributions for fixed-rate events and choose random elements for them to happen on.This behaviour can be overridden by sub-classes to provide a different ordering for events. The order sometimes has a significant impact on the behaviour of the simulation.
- Parameters:
t (
float) – the simulation time- Return type:
List[Tuple[Locus,Union[Any,Tuple[Any,Any]],Callable[[float,Union[Any,Tuple[Any,Any]]],None],str]]- Returns:
a list of locus, element, event function, and name
Refer to Event orderings for more details on how this method can affect simulations.