In probability theory and computational science, the Gillespie algorithm, also known as the stochastic simulation algorithm (SSA), is a method for generating statistically exact sample trajectories of certain continuous-time Markov jump processes. It is especially associated with the simulation of coupled chemical reaction systems. Daniel Gillespie presented the method in 1976 and developed it further in 1977.
The method is widely used in computational systems biology, particularly when the numbers of reacting molecules are small enough that stochastic fluctuations are important. Gillespie-type algorithms are also used in network epidemiology to simulate stochastic epidemic spreading on complex networks, including continuous-time SI, SIS, and SIR processes.
Mathematically, the algorithm is a form of dynamic Monte Carlo method and is closely related to kinetic Monte Carlo methods.
The mathematical foundations of the Gillespie algorithm lie in the theory of stochastic jump processes. In 1931, Andrey Kolmogorov developed differential equations describing the time evolution of Markov processes, now known as the Kolmogorov equations.
William Feller subsequently studied purely discontinuous Markov processes and established conditions under which the Kolmogorov equations yield proper transition probabilities. Joseph L. Doob extended the mathematical theory of Markov processes during the 1940s.
Early computer simulations of related stochastic processes predated Gillespie's work. David George Kendall simulated a simple birth-and-death process using the Manchester Mark 1 computer in 1950, and Maurice S. Bartlett applied stochastic-process methods to epidemic modelling.
Gillespie's 1976 and 1977 papers derived an exact simulation procedure for systems of coupled chemical reactions using probabilistic arguments based on the physical interpretation of molecular reaction events.
Consider a system whose state at time is described by a vector . Each possible event or reaction has a propensity function . For chemical systems, the propensity represents the instantaneous rate at which a particular reaction can occur when the system is in state .
Define the total propensity
Provided that the process is Markovian, the waiting time until the next event is exponentially distributed with rate . The joint probability density that the next event occurs after a waiting time and is reaction is
Thus, the simulation requires two random choices: the time of the next event and which event occurs.
Using two independent pseudorandom numbers and , uniformly distributed on , the waiting time can be generated as
The next reaction is the smallest integer satisfying
The direct form of the Gillespie algorithm can be written as follows:
Each realization produced in this way is a sample trajectory of the corresponding stochastic process.
Traditional deterministic descriptions of chemical kinetics generally use systems of coupled ordinary differential equations for continuous concentrations. Such models are often effective when populations are large and stochastic fluctuations are relatively small.
When some molecular species occur in low copy numbers, however, fluctuations associated with individual reaction events may become significant. The Gillespie algorithm represents molecules and reaction events discretely and therefore provides a way of simulating these intrinsic stochastic fluctuations.
For the standard chemical interpretation of the algorithm, the reaction system is normally assumed to be sufficiently well mixed that spatial correlations can be neglected and that the propensity of each reaction depends only on the current state.
The original direct method may become computationally expensive when a model contains a large number of reaction channels. Consequently, numerous exact and approximate variants have been developed.
The next reaction method of Gibson and Bruck uses data structures such as dependency graphs and priority queues to reduce the computational effort needed to determine subsequent reaction events.
Approximate methods such as tau-leaping advance the system through multiple reaction events over a finite time interval rather than simulating every individual event, potentially providing substantial computational savings. Hybrid methods can likewise combine stochastic descriptions of low-copy-number species with deterministic approximations for abundant species.
For weakly coupled reaction networks, exact algorithms with computational cost independent of the total number of reaction channels under appropriate conditions have been developed.
Extensions have also been proposed for systems in which events are delayed or otherwise depart from the assumptions of a simple Markov reaction process.
Partial-propensity formulations reduce the computational work needed to evaluate and select reaction channels by exploiting the structure of their propensity functions.
Related approaches based on reaction factoring and dependency structures have also been proposed for large biochemical systems.
Partial-propensity techniques have additionally been extended to reaction networks containing delays.
The Gillespie algorithm was originally developed for coupled chemical reaction systems and remains widely used to investigate stochastic chemical and biochemical dynamics. Applications include systems in which fluctuations caused by small numbers of molecules may influence the system's behaviour, such as gene-expression and regulatory networks.
Epidemic models can also be represented as continuous-time stochastic event systems. For a network-based epidemic model, events may include transmission across an edge between susceptible and infected nodes and recovery of an infected node.
Gillespie-based simulation can therefore be used to generate continuous-time realizations of epidemic models on complex contact networks. Kuryliak, Emmerich, and Dosyn applied efficient Gillespie implementations to SI, SIS, and SIR dynamics on heterogeneous networks and studied how network structure and interventions influence epidemic peak size and timing.
A simple chemical system illustrates the direct method. Consider molecules of two types, A and B, which reversibly bind to form AB dimers:
There are two possible reactions. An A molecule and a B molecule can combine to produce an AB dimer, or an existing dimer can dissociate.
Let the rate constant for dimer formation be and the rate constant for dissociation be . If the system contains molecules of A, molecules of B, and dimers, the two propensities are
and
The total reaction propensity is therefore
The waiting time until the next reaction is sampled from an exponential distribution with mean . Once the waiting time has been generated, the probability that the next event is dimer formation is
while the probability of dissociation is
If dimer formation occurs, and each decrease by one and increases by one. If dissociation occurs, the opposite update is made. Repeatedly sampling the waiting time and reaction type generates one stochastic trajectory of the system.