EoN.discrete_SIR¶
-
EoN.
discrete_SIR
(G, test_transmission=<function _simple_test_transmission_>, args=(), initial_infecteds=None, initial_recovereds=None, rho=None, tmin=0, tmax=inf, return_full_data=False, sim_kwargs=None)[source]¶ Simulates an SIR epidemic on G in discrete time, allowing user-specified transmission rules
From figure 6.8 of Kiss, Miller, & Simon. Please cite the book if using this algorithm.
Return details of epidemic curve from a discrete time simulation.
It assumes that individuals are infected for exactly one unit of time and then recover with immunity.
This is defined to handle a user-defined function
test_transmission(node1,node2,*args)
which determines whether transmission occurs.So elaborate rules can be created as desired by the user.
By default it uses
_simple_test_transmission_
in which case args should be entered as (p,)Arguments: - G NetworkX Graph (or some other structure which quacks like a
- NetworkX Graph)
The network on which the epidemic will be simulated.
- test_transmission function(u,v,*args)
(see below for args definition) A function that determines whether u transmits to v. It returns True if transmission happens and False otherwise. The default will return True with probability p, where args=(p,)
This function can be user-defined. It is called like: test_transmission(u,v,*args) Note that if args is not entered, then args=(), and this call is equivalent to test_transmission(u,v)
- args a list or tuple
The arguments of test_transmission coming after the nodes. If simply having transmission with probability p it should be entered as args=(p,)
[note the comma is needed to tell Python that this is really a tuple]
- initial_infecteds node or iterable of nodes (default None)
- 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 (default is None)
initial fraction infected. initial number infected is int(round(G.order()*rho)).
The default results in a single randomly chosen initial infection.
tmin start time
tmax stop time (default Infinity).
- 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
returns- 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.discrete_SIR(G, args = (0.6,), initial_infecteds=range(20)) plt.plot(t,I)
Because this sample uses the defaults, it is equivalent to a call to basic_discrete_SIR