EoN.fast_SIR

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

fast SIR simulation for exponentially distributed infection and recovery times

From figure A.3 of Kiss, Miller, & Simon. Please cite the book if using this algorithm.

Arguments:
G networkx Graph
The underlying network
tau number
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)
maximum time after which simulation will stop. the default of running to infinity is okay for SIR, but not for SIS.
transmission_weight string (default None)
the label for a weight given to the edges. transmission rate is G.adj[i][j][transmission_weight]*tau
recovery_weight string (default None))
a label for a weight given to the nodes to scale their recovery rates gamma_i = G.nodes[i][recovery_weight]*gamma
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
Returns:

times, S, I, R numpy arrays

Or if return_full_data is 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 create animations using class methods.
SAMPLE USE:
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.fast_SIR(G, tau, gamma,
                            initial_infecteds = range(initial_size))

plt.plot(t, I)