StochasticDynamics
: Stochastic (Gillespie) process 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 and was later refined further by him.
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.
-
class
epydemic.
StochasticDynamics
(g=None)¶ Bases:
epydemic.networkdynamics.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.
Creating a dynamics¶
-
StochasticDynamics.
__init__
(g=None)¶ Create a dynamics, optionally initialised to run on the given network.
Parameters: g – prototype network to run the dynamics over (optional)
Running a dynamics¶
To run a process’ dynamics we need two things: the event rate table that maps an event type and its rate to the function for that event; and the overall experimental control that runs the experiment and packages-up some key common results.
-
StochasticDynamics.
eventRateDistribution
(t)¶ Return the event distribution, a sequence of (l, r, f) triples where l is the locus where the event occurs, r is the rate at which an event occurs, and f is the event function called to make it happen. This method must be overridden in sub-classes. Note that it’s a rate we want, not a probability: the former can be obtained from the latter simply by multiplying the event probability by the number of times it’s possible in the current network, which is often a population of nodes or edges in a given state.
It is perfectly fine for an event to have a zero rate. The process is assumed to have reached equilibrium if all events have zero rates.
Parameters: t – current time Returns: the event rate distribution
-
StochasticDynamics.
do
(params)¶ Run the simulation using Gillespie dynamics. The process terminates when either there are no events with zero rates or when
at_equilibrium()
return True.Parameters: params – the experimental parameters Returns: the experimental results dict