Gillespie algorithm Created 2026-09-28 Updated 2026-11-05
The Gillespie algorithm samples statistically exact trajectories of a well-mixed chemical reaction network modeled by a continuous-time Markov chain. At copy-number state , each reaction propensity function is a nonnegative event rate and each stoichiometric vector specifies the update. Assume the rates have no explicit time dependence. Put . If , no further chemical reaction can occur: the state is an absorbing state.
For , sample a waiting time from the exponential distribution with rate , independently choose channel with probability , and update . Recompute the reaction propensity functions and repeat. The no-event probability is because ; multiplying by gives the joint waiting-time/channel probability density function . This factorization explains the two draws.[ref]
For with reaction propensity function , the waiting time has mean , and is an absorbing state. Exactness concerns the specified chemical master equation; spatial mixing errors and explicitly time-varying rates require a different model or sampling rule.
Let be the th coordinate vector and take to be zero whenever any argument is negative. Right jumps , left jumps , and absorption from compartment give the chemical master equation
For a function on the copy-number state space, define the shift operator
With the propensities from part (a), the forward operator of a Markov jump process is
Equivalently, the chemical master equation has the gain-minus-loss form
where terms outside the state space vanish.
The adjoint Markov jump-process generator acts on observables:
Indeed, shifting the summation index in the gain terms gives .
Write and . The three stoichiometric vectors are , and . The law of mass action gives the respective reaction propensity functions
In particular, producing the second chemical species does not consume the first chemical species. Since the two reactants in the third chemical reaction are different chemical species, the number of possible pairs is .
For each Markov chain state, the chemical master equation adds incoming probability flux and subtracts outgoing probability flux:
Here if either index is negative, and the initial condition is . These conventions also give the correct chemical master equation on the coordinate axes: for example, the third chemical reaction has zero outgoing reaction propensity function when either chemical species is absent.
Conditioning on the observed time. The native PDF defines as the first production time and then conditions on that production occurring at . If the intended information is its numerical value , the answer depends on . We first compute this conditional probability using a conditional probability density; conditioning on an exact value of a continuous random variable means a density ratio, since .
Before , no molecules of the second chemical species are present, so the joint-removal chemical reaction cannot occur. Molecules of the first chemical species arrive as a rate- Poisson process, and each independently starts a clock with a rate- exponential distribution for producing the first molecule of the second chemical species. Define the unnormalized probability mass function
The chemical master equation before the first production, with production treated as killing, is
Multiplying by and summing gives a partial differential equation for the probability generating function:
Its solution, verifiable by direct differentiation, is
Thus , the survival function is , and the conditional distribution of given survival to is a Poisson distribution of mean .
Production in from Markov chain state has joint probability . Therefore the probability density function of is
The first production leaves unchanged. Taking the density ratio gives a size-biased distribution of the surviving count:
In particular, under this reading the requested conditional probability is
The shift by one matters: an observation made exactly when production occurs preferentially selects larger counts, since their production reaction propensity function is larger.
Without observing the numerical time. If the conditioning merely repeats the definition of , the requested probability is instead the unconditional count at that stopping time. Before production, increases by one at rate , while production occurs at rate in Markov chain state . The competing exponential clocks imply
The first factor requires a second arrival before production from count one; the second requires production before a third arrival. The first arrival itself is certain. Production eventually occurs with probability one, as is also clear from . As a consistency check, averaging the time-conditioned answer against gives
These are two distinct, explicitly specified interpretations of the printed conditioning.
A product-Poisson stationary distribution is suggested by balancing the three reaction fluxes around the directed cycle of reaction complexes. If their mean counts are , this complex balance condition is
which gives and . This suggests the joint probability mass function
It is normalized because it is the product of two Poisson distributions. We verify it directly in the chemical master equation, rather than assuming a product-Poisson stationary distribution theorem. The three incoming terms satisfy
With negative-index values set to zero, these identities also hold on the axes. Their sum equals , precisely the outgoing probability flux. The stationary average total exit rate is , so these stationary balance equations do define an invariant distribution of a continuous-time Markov chain for the nonexplosive model verified below. This is complex balance; it does not assert pairwise detailed balance for the irreversible chemical reactions.
To identify this invariant distribution with the limiting probability distribution in the question, first check that the model is a nonexplosive continuous-time Markov chain. On any finite time interval, is bounded by its initial count plus the finite number of arrivals in a rate- Poisson process. Conditional on that bound, the rate of producing is bounded, so only finitely many such productions occur. The number of joint removals cannot exceed the available molecules. Thus only finitely many chemical reactions occur in finite time.
The continuous-time Markov chain is also an irreducible Markov chain. From a Markov chain state with both counts positive, repeated joint removals reduce both. On the axis, producing one and then removing a pair reduces by one. On the axis, adding one and then removing a pair reduces by one. Each prescribed finite sequence has positive probability, so every Markov chain state reaches . Conversely, arrivals followed by productions reach any with ; to reach , reach and remove one pair. The continuous-time Markov chain is therefore positive recurrent, and the continuous-time Markov chain convergence theorem gives from the empty initial condition.
The two Poisson factors happen to have cancelling numerical coefficients at :
An invariant distribution of a continuous-time Markov chain whose coordinates are independent Poisson distributions. This property needs verification from the reaction propensity functions; it does not follow merely from having an equilibrium for the deterministic reaction-rate equations.
For example, consider the cyclic chemical reaction network with stoichiometric vectors , and and respective reaction propensity functions , , , where all three constants are positive. Put and . For , the three incoming terms in the chemical master equation are respectively , and . They exactly cancel the outgoing terms. Boundary terms vanish by the zero negative-index convention, and normalization follows from the two Poisson distributions. Establishing a limiting probability distribution additionally requires nonexplosion, an irreducible Markov chain and positive recurrence.