StochasticDynamics: Stochastic (Gillespie) process dynamics

class epydemic.StochasticDynamics(p, g=None)

Bases: Dynamics

A dynamics that runs stochastically in continuous time. This is a very efficient and statistically exact approach, but requires that the statistical properties of the events making up the process are known. See Gillespie [Gil76, Gil77] for a discussion of the technique.

Parameters:
  • p (Process) – the process to run

  • g (Union[Graph, NetworkGenerator, None]) – network or network generator (optional, can be provided later)

Running a dynamics

The idea of stochastic event-based simulation arose in ab initio chemistry to simulate interactions between molecules. The basic technique is due to Gillespie [Gil76, Gil77].

The basic idea of Gillespie simulation is to structure an experiment in terms of events which occur with some probability over continuous time. Individual event probabilities are converted to rates by multiplying the individual probability by the number of possible ways it can occur at this instance, leading to a probability distribution of events and the time until they occur. We then draw from this distribution and update it according to the behaviour defined for that particular event. This allows the rates of events to change over time.

The dynamics works as follows:

  • The event rate distribution is acquird from the process by calling Process.eventRateDistribution(), which returns both per-event and fixed-rate events.

  • Based on these rates, a random time offset to the next event is drawn from an exponential distribution.

  • The event that occurs at this time is then drawn from the combined distribution of the rates of all the available events.

  • Any events posted for before this ofset time are run by calling Dynamics.runPendingEvents().

  • The simulation time is updated by the time offset.

  • An element is drawn randomly from the event locus, and the corresponding event is fired.

  • The firing of the event is recorded through the event tap.

  • This process continues until the process is at equilibrium, as indicated by its Process.atEquilibrium() method.

StochasticDynamics.do(params)

Run the simulation using Gillespie dynamics.

Parameters:

params (Dict[str, Any]) – the experimental parameters

Return type:

Dict[str, Any]

Returns:

the experimental results dict