• Keine Ergebnisse gefunden

2.2 Simulations

2.2.4 The Gillespie algorithm

So far, we have investigated how to solve the differential equations describing the model while treating the molecular species’ concentrations as continuous numbers.

But what if the number of the molecular species we are describing cannot be treated as a continuous number? This is the case when we are considering small numbers of molecules, say below 100. This brings with it two different issues.

Firstly, the number of molecules is so small that it becomes coarse-grained and we cannot approximate it well using a continuous number. Doing calculations which involve 0.1 molecules makes no sense: either there are 0 or 1 molecules.

Secondly, randomness starts to play a role. If the deterministic simulation gives us a result of 0.1 molecules for a given time step, this means that there would be 0.1 molecules on average. In reality, this could be 0, or 1, or 2, or ... molecules.

It is intuitively clear that this would make a big difference to the outcome of the simulations. With deterministic simulations, we can still make statements for the average behaviour of the model system, but in reality, each realization of the sys-tem would yield a different results simply due to pure chance. If we are interested in the statistical characteristics of those realizations, such as the variability, we have to perform stochastic simulations.

A very current example of this is the statistics of cases of an infectious disease:

deterministic simulations can inform us about the average behaviour, but to cor-rectly reflect the highly stochastic and localized nature of disease outbreaks, we need stochastic simulations.

To perform stochastic simulations, we use the same reaction equations from

equa-tion (2.1), however we need to treat them differently. We cannot translate the reaction equations to the differential equations from equation (2.3) anymore, since this assumes that the species are continuous quantities. Instead of treating the dif-ferent molecular species as continuous quantities and the reactions as continuous fluxes, we now treat the species as integer numbers and the reactions as separate events. To perform simulations, we consider the separate reactions one by one.

This is called the Gillespie Algorithm (Gillespie, 1977).

Initialization of reactants

Choose next reaction and time

Update reactants’

numbers

Iteration if time < end time

Figure 2.3: Schematic of the Gillespie algorithm.

The basic mechanism of the algorithm is schematically shown in figure 2.3. First, the initial conditions are used to initialize all reactant numbers. Then, we need to pick a reaction as well as the waiting time until it occurs randomly. How this is done will be explained in detail below. When a reaction has been chosen, the next step is to carry out the changes of this reaction on the reactant concentrations:

they are updated to reflect the decrease in reactant species and the increase in product species. The simulation time is advanced by the wait time.

In the next step, it is checked whether the total time exceeds the specified simula-tion time - if this is not the case, the simulasimula-tion continues, and the main simulasimula-tion step is iterated: the next reaction will be chosen and carried out.

In the reaction step, we need to ensure that the reactions occur with the correct statistics. We want to pick reactions at random, but each of them should happen with the correct relative frequency and with correct statistics of the waiting time in between reactions. The Gillespie algorithm has an elegant solution to ensure this.

Imagine a reaction with reactants A and B and product C, occurring with a rate constantk1. Then the total rate of the reaction will equal to r1 = A·B·k1. This is the instantaneous rate, its unit is molecules/s since it denotes the change of C.

The mean time between reactions will be 1/r1. When we consider all the reactions in a given reaction network, we can define a total rate of all reactions that can

occur:

rtot =

n−1

X

i=0

ri, (2.18)

where the sum extends over all n rates in the reaction network. The mean time until any reaction occurs in this network is 1/rtot.

To perform the simulations, we also need to know the probability distribution of times between reactions to choose reaction times that not only give the correct mean reaction time, but also the correct statistics. It can be shown that the times between reactions are exponentially distributed, since the reactions are in-dependent of each other (except for the change of the reactant). Processes with this characteristic are called Markov processes, and another example is radioactive decay: the time in between independent decay events is also exponentially dis-tributed.

We can assign a waiting time between reactions by drawing exponentially dis-tributed random numbers, which is typically done by computing

τ = 1

rtotlog

1 U1

, (2.19)

where U1 is a random number drawn from a uniform distribution between 0 and 1. Consequently, log (1/U1) is an exponentially distributed number between 0 and

∞. This ensures that we will on average wait a time of 1/rtot between reactions, and that the waiting times are exponentially distributed.

Next, it needs to be decided which reaction occurs at the newly determined time point. For each of the reactions, the probability to occur isri/rtot. We can therefore create a new random number U2, uniformly distributed between 0 and 1, and find the smallest k for which

k

X

i=0

ri > rtot·U2. (2.20) Using this procedure, each reaction is chosen proportionally to the width of the interval that they contribute to the sum representing rtot, and thus proportionally to ri/rtot.

After the reaction and its waiting time have been determined, the reaction is car-ried out, which means that the total simulation time is advanced by the waiting time and the molecule numbers are updated according to the reaction that has occurred. Then, if the total simulation time has not been exceeded, another step can be carried out: first, the reaction rates have to be updated according to the

new reactant numbers. Then, the random procedure is again used to pick the next reaction and waiting time.

Using the Gillespie algorithm, a stochastic simulation of a system of reaction equa-tions can be carried out. We now have all the tools needed to build a model and to carry out both stochastic and deterministic simulations.