EoN.percolation_based_discrete_SIR¶
- EoN.percolation_based_discrete_SIR(G, p, initial_infecteds=None, initial_recovereds=None, rho=None, tmin=0, tmax=inf, *, rng=None, return_full_data=False, sim_kwargs=None)[source]¶
perfoms a simple SIR epidemic but using percolation as the underlying method.
From figure 6.10 of Kiss, Miller, & Simon. Please cite the book if using this algorithm.
The simple case of all nodes transmitting with probability p independently to each neighbor and then recovering, but using a percolation-based approach.
- Warning:
You probably shouldn’t use this algorithm.
See
basic_discrete_SIRwhich produces equivalent outputs.That algorithm will be faster than this one.
The value of this function is that by performing many simulations we can see that the outputs of the two are equivalent.
This algorithm leads to a better understanding of the theory, but it’s not computationally efficient.
- Arguments:
- G networkx Graph
The network the disease will transmit through.
- p number
transmission probability
- 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 as for initial_infecteds, but initially
recovered nodes.
- rho number
initial fraction infected. number is int(round(G.order()*rho))
tmin start time
tmax stop time (if not extinct first). Default step is 1.
- rng random number generator
If None, will be set to np.random.default_rng()
- 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:
t, 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 even create animations using class methods.
- SAMPLE USE:
import networkx as nx import EoN import matplotlib.pyplot as plt G = nx.fast_gnp_random_graph(1000,0.002) t, S, I, R = EoN.percolation_based_discrete_SIR(G, p) plt.plot(t,S)
This is equivalent to basic_discrete_epidemic (but many simulations may be needed before it’s clear, since these are stochastic)