EoN.Gillespie_SIR(G, tau, gamma, initial_infecteds=None, initial_recovereds=None, rho=None, tmin=0, tmax=inf, recovery_weight=None, transmission_weight=None, return_full_data=False, sim_kwargs=None)[source]

Performs SIR simulations for epidemics.

For unweighted networks, the run time is usually slower than fast_SIR, but they are close. If we add weights, then this Gillespie implementation slows down much more.

I think there are better ways to implement the algorithm to remove this. This will need a new data type that allows us to quickly sample a random event with appropriate weight. I think this is doable through a binary tree and it is in development.

Rather than using figure A.1 of Kiss, Miller, & Simon, this uses a method from Petter Holme

“Model versions and fast algorithms for network epidemiology”

which focuses on SI edges (versions before 0.99.2 used a method more like fig A.1).

This approach will not work for nonMarkovian transmission. Boguna et al
“Simulating non-Markovian stochastic processes”

have looked at how to handle nonMarkovian transmission in a Gillespie Algorithm. At present I don’t see a way to efficientl adapt their approach - I think each substep will take O(N) time. So the full algorithm will be O(N^2). For this, it will be much better to use fast_SIR which I believe is O(N log N)

See Also:

fast_SIR which has the same inputs but uses a different method to run faster, particularly in the weighted case.

G networkx Graph
The underlying network
tau positive float
transmission rate per edge
gamma number
recovery rate per node
initial_infecteds node or iterable of nodes
if a single node, then this node is initially infected if an iterable, then whole set is initially infected if None, then choose randomly based on rho. If rho is also None, a random single node is chosen. If both initial_infecteds and rho are assigned, then there is an error.
initial_recovereds iterable of nodes (default None)
this whole collection is made recovered. Currently there is no test for consistency with initial_infecteds. Understood that everyone who isn’t infected or recovered initially is initially susceptible.
rho number
initial fraction infected. number is int(round(G.order()*rho))
tmin number (default 0)
starting time
tmax number (default Infinity)
stop time
recovery_weight string (default None)
the string used to define the node attribute for the weight. Assumes that the recovery rate is gamma*G.nodes[u][recovery_weight]. If None, then just uses gamma without scaling.
transmission_weight string (default None)
the string used to define the edge attribute for the weight. Assumes that the transmission rate from u to v is tau*G.adj[u][v][transmission_weight] If None, then just uses tau without scaling.
return_full_data boolean (default False)
Tells whether a Simulation_Investigation object should be returned.
sim_kwargs keyword arguments
Any keyword arguments to be sent to the Simulation_Investigation object Only relevant if return_full_data=True
times, S, I, R each a numpy array
giving times and number in each status for corresponding time

OR if return_full_data=True:

full_data Simulation_Investigation object
from this we can extract the status history of all nodes We can also plot the network at given times and even create animations using class methods.
import networkx as nx
import EoN
import matplotlib.pyplot as plt

G = nx.configuration_model([1,5,10]*100000)
initial_size = 10000
gamma = 1.
tau = 0.3
t, S, I, R = EoN.Gillespie_SIR(G, tau, gamma,
                            initial_infecteds = range(initial_size))

plt.plot(t, I)