Content uploaded by Wesley Cota
Author content
All content in this area was uploaded by Wesley Cota on Sep 23, 2017
Content may be subject to copyright.
Computer Physics Communications 219 (2017) 303-312
Optimized Gillespie algorithms for the simulation of Markovian
epidemic processes on large and heterogeneous networks
Wesley Cota and Silvio C. Ferreira
Departamento de Física, Universidade Federal de Viçosa, 36570-000, Viçosa, MG, Brazil
23
BRASÃO DA UFV
O Brasão da UFV continuará a ser utilizado na instituição, mas ficará restrito a
divulgações de ordem solene e formal, tais como:
- Documentos oficiais destinados a autoridades políticas ou religiosas.
- Certificados ou diplomas de conclusão de cursos de formação básica, de
ensino médio e técnico, de graduação ou pós-graduação.
- Produtos originados de ocasiões específicas, como placas de homenagens ou
selos comemorativos.
- Documentos oficiais destinados a autoridades dos Poderes Executivo,
Legislativo e Judiciário, das Forças Armadas e autoridades eclesiásticas.
O Brasão jamais deve ser utilizado em documentos particulares ou de
interesses não institucionais.
Introduction
•Based on the Gillespie Algorithm (GA), we optimize it by
introducing phantom processes.
•We numerically confirm that the optimized algorithms can
be several orders of magnitude more efficient.
Networks as substrates
•For a pair (i, j), the element of the adjacency matrix
is Aij = 1 when they are connected and 0otherwise.
•The degree is given by ki=PjAij. The moments
hkniare given by the single degree distribution Ps(k).
•A hub has k hki. Outliers have degree given by
NP (k)1in an ensemble of networks with degree
distribution P(k),k=k0,· · · , kc.
•Power-law (PL) distributions P(k)∼k−γ,k∈
[k0, N], have hkmaxi ∼ N1
γ−1.
•We consider a rigid cutoff defined as NP (kc)=1such
that kmax ∼N1/γ.
Epidemics and absorbing-states
•In closed systems, the states where the disease is eradi-
cated are called absorbing states.
•Stochastic simulations are done with finite systems.
•We consider a quasistationary (QS) analysis using an re-
flecting boundary when visiting the absorbing state.
•[· · · ]are the QS averages and h· · · i the standard ones.
•The sth moment of the QS density of infected vertices is
[ρs] = 1
Ns
N
X
n=1
ns¯
Pn,(1)
and the dynamical susceptibility is
[χ] = N[ρ2]−[ρ]2
[ρ].(2)
0.0
0.2
0.4
0.6
0.8
N−0.5[χ]
103
104
105
106
107
10-2 10-1
λ
0
6
12
18
N0.5[ρ]
(a)
(b)
Figure 1: SIS QS (a) susceptibility and (b) density divided and mul-
tiplied, respectively, by Nagainst infection rate λfor µ= 1. Sizes
indicated in the legends. PL network with γ= 2.3and rigid cutoff.
The Gillespie Algorithm (GA)
•Consider Zindependent spontaneous processes p=
1,2,· · · , Z with rates ν1, ν2,· · · , νZ.
•The probability of the pth process in [t, t +dt]is νpdt.
•The master equation dP0
dt =−νP0and dP1
dt =νP0with
Pj(0) = δj0gives:
•P0(t) = e−νt (process has not happened until time t),
•P1(t)=1−e−νt (it has happened until time t).
•The probability that the next process is pand that it
will happen within [t+τ, t +τ+dt]is:
Z
Y
q=1
e−νqτ
νpdt =νp
RRe−Rτ dt, (3)
with R=Pqνqbeing the total rate of transitions.
•The next event will take place after a time τwith
PR(τ) = Re−Rτ , and will be pwith probability νp/R.
•The GA algorithm is proposed as follows:
1Build a list with all processes and respective rates;
2Select τfrom PR(τ)as τ=−ln(u)/R,u∈U(0,1);
3Choose pwith probability νp/R and update the system state;
4Increment time as t→t+τ;
5Return to step 1.
Implementation in epidemics models
•Three states: σi= 0 (susceptible, S), σi= 1 (infected, I)
and σi= 2 (recovered, R).
•I→R at rate µi, R→S at rate αi. Vertex iinfects jat rate
λij, if σi= 1 and σj= 0.
•Lists V(I) and M,V(R) and A, and the total rates are
M=
N
X
i=1
µiδ(σi,1) =
NI
X
p=1
Mp(4)
and
A=
N
X
i=1
αiδ(σi,2) =
NR
X
p=1
Ap.(5)
•To implement the GA, we also need V(IS) and Lsuch that
L=
N
X
i,j=1
λijδ(σi,1)δ(σj,0) =
NIS
X
p=1
Lp.(6)
•The total rate is R=M+A+L. With m=M/R,
a=A/R and l=L/R we choose I→R, R→S or IS→II.
•One element pof the list Vis chosen with probability proportional
to its respective rate.
•The choice is done using the rejection method:νp/νmax.
•The time is incremented as t→t+τ, with τfrom PR(τ).
Optimized Gillespie Algorithm (OGA)
I
i
i i
(a) λij
(b) j j
λij
(c) j j
i
λij
S
R
j
ij
i
Figure 2: Examples of (a)-(b) phantom and (c) real infection.
•We write the total infection rate as L=W−P, with
W=
N
X
i,j=1
λijδ(σi,1),(7)
and
P=
N
X
i,j=1
λijδ(σi,1)[δ(σj,1) + δ(σj,2)].(8)
•The total rate is R=M+A+W. We need Wwith
the maximum production rates of each infected vertex:
W=
N
X
i=1
wiδ(σi,1) =
NI
X
p=1
Wp.(9)
•Recovering and waning of immunity follow the same
as before. With w=W/R, an infected vertex iis
selected as an element pof V(I) proportionally to Wp.
•One neighbor jof iis chosen proportionally to λij. If suscep-
tible, it becomes infected.
•The time is incremented by τwith PR(τ) = Re−Rτ .
Susceptible-Infected-Susceptible (SIS)
•σi= 0 or 1, rates µi=µ,αi=∞, and λij =λAij.
•M=µNI,L=λNIS,A= 0. Since Wp=λKp, only the
list NIis needed. So, W=λNk, with Nk=Pikiσi.
•GA: R=M+L. With l=L/R, an element of V(IS) is
selected with equal chance and is infected.
•OGA: R=M+W. With w=W/R, infected vertex i
chosen with probability ki/kmax. Neighbor uniformly.
100101102
t
10-10
10-8
10-6
10-4
10-2
100
〈ρ〉
GA
OGA
IOGA
0.1 0.2 0.3 0.4
λ
10-4
10-3
10-2
10-1
[ρ]
Figure 3: SIS decay for µ= 1 on a UCM network with γ= 4.0,k0= 3,
N= 104.λ= 0.150 < λcand λ= 0.300 > λc. Inset: QS density.
101
102
103
104
105
106
tCPU (s)
103104105106107
N
101
102
103
104
105
106
tCPU (s)
GA
OGA
IOGA
y=0.04N
y=2N0.5
103104105106107
N
(a) (b)
(c) (d)
Figure 4: CPU times for QS simulations of the SIS dynamics (µ= 1)
at the epidemic threshold for: (a) Exponential; (b) UCM with γ= 2.3;
(c) UCM with γ= 4.0; and (d) UCM with γ= 4.0plus an outlier.
Contact Process (CP)
•Rates: µi=µ,αi=∞and λij =λAij/ki. Then, M=
µNI,L=PNIS
p=1 λ/Kp,A= 0 and W=λNI.
•GA: With l=L/R,V(IS)
pis selected by kmin/Kp.
•OGA: Infected vertex iis chosen. With m=µ/(µ+λ),
I→S. With w=λ/(µ+λ), one of the kineighbors of iis
randomly selected and infected if susceptible.
103104105106107
N
101
102
103
104
105
106
tCPU (s)
GA
OGA
y=0.04N
y=2N0.5
103104105106107
N
(b)(a)
Figure 5: CPU times for QS simulations of the CP (µ= 1) at λcon
UCM networks: k0= 3,kc∼N1/γ. (a) γ= 2.3and (b) γ= 4.0.
Susceptible-Infected-Recovered (SIR)
•Rates: µi=µ,αi= 0 and λij =λAij.
•So, M=µNI,L=λNIS,A= 0 and W=λNk.
Figure 6: SIR dynamics in a UCM network with γ= 4.0and N= 104,
k0= 3 and kc∼N1/γ. The final (a) average density of recovered
vertices and (b) epidemic lifetime.
Conclusions
•The phantom processes simplify hugely the determination
of all possible events and the OGA still provides statisti-
cally exact simulations.
•The GA is much slower than OGA due to the building of
the lists of all possible events after change of states.
•The ideas developed here can be used as a groundwork for
the building of efficient algorithms for other Markovian
dynamics.
Links
•CPC 219 (2017) 303-312
•GitHub: SIS implementations
Acknowledgments
This work was supported by the funding agencies
FAPEMIG, CNPq and CAPES, Brazil.