Gillespie algorithm was first created by Joseph L. Doob and others (circa 1945) and was presented by Dan Gillespie in 1976.
Gillespie used it to simulate chemical and biochemical systems of reactions.
Mathematically, it is a variant of a dynamic Monte Carlo method and similar to the kinetic Monte Carlo method.
Nowadays the algorithm has been used to simulate increasingly complex systems. This project uses the SIR model(Susceptible, Infectious, or Recovered) to exemplify the method and its math principle.
Also, some modifications of the algorithm are included, like
SIR model is a description of a disease spreading in a finite population.
Suppose for every individual in the population, the probability of this individual turning to another state at any time is equal to some constant value. This means the distribution of transition with respect to time is an exponential distribution. (Can proved from geometry distribution by taking infinite small time step).
For SIR model, there are two transitions: from S to I and from I to R. At any time t, the transition rate
This is self-explanatory: The infectious rate is modeled in proportional to the infected people. While for the recovery rate, it is equal for every single individual. Now we get the coefficient of the exponential distribution for the two events: infection and recovering, for all single individuals.
To simulate the process of disease spreading, we need those steps:
- sample a time when one event happens.
- choose which kind of event just happened.
- update the system's state since one individual changed, the whole system was changed.
We will go through those step by step.
First, let us think of none of those events happened before
The PDF of all individuals not changed before
So the PDF that something does happens in
Now we know how long it takes for something to happens. But which event is happened? We could choose one event based on their propensity, meaning the probability who is turned is
That is to say, state changes with high propensities are more likely to occur.
Now we know the PDF of something happens and we know the probability of what event happens. We are all set! What we are going to do next is just updating the system based on the sampled time and sampled event, then do the whole process iteratively until we meet max step or the system would not change anymore. We could sample once a time sample a time using inverse sampling method:
and sample an event using
then pick up the rth individual and update its state change:
-If S &rarr I happens, then
Alternatively, we could solve this by constructing an ODE in a deterministic way:
where all the listed parameters are constant.
-
$\beta$ is (the number of people one person will contact per unit time) * (transmissive rate). -
$\gamma$ is the "recover progress/rate" for one person. For example, the recovery time for the disease is five days, then$\gamma$ is 0.2. Then in$\Delta t$ , the recovered people's number is$\gamma I(t)$ . -
$N$ is the total number of people in the population.
Then
There are several flaws in the traditional Gillespie algorithm. For example, if the number of the population is very large, then it may take a very long time for the simulation since every time it only updates one single individual. Moreover, the lambda of the exponential distribution for an event to occur will be large, hence run into some numerical issues when applying reverse sampling. And at the begining, the increasing of infected individuals would grow up slowly, there will not be a significant change in the system. There are several modifications for it, including the next reaction method,
This method is very intuitive and natural. Since the traditional method only takes one individual at a time, why not take several individuals in one update? In another way, update the rates less often. The algorithm can be achieved in several steps:
- Takes a constant (well this could also be adaptive) time at each step and calculates how many events happened in this time interval for every kind of event.
- Update the system and do it iteratively until it reaches a static state.
The only tricky part is how many events happened in a time interval. Does it sound familiar? Think of modeling the number of phone calls an office would receive during some fixed time, a classical model you will probably meet in a statistics course. Yes, it is actually a Poisson distribution! The expectation of the Poisson is
This method just combines the ODE method and Gillespie algorithm for large N.
Say N is
-When
-When
The model does not take into consideration of the spatial information of the system, say every individual has different distance to each other, causing the transmissive rate not a constant.
