EoN.fast_nonMarkov_SIR

EoN.fast_nonMarkov_SIR(G, trans_time_fxn=None, rec_time_fxn=None, trans_and_rec_time_fxn=None, trans_time_args=(), rec_time_args=(), trans_and_rec_time_args=(), initial_infecteds=None, initial_recovereds=None, rho=None, tmin=0, tmax=inf, return_full_data=False, sim_kwargs=None)[source]

A modification of the algorithm in figure A.3 of Kiss, Miller, & Simon to allow for user-defined rules governing time of transmission.

Please cite the book if using this algorithm.

This is useful if the transmission rule is non-Markovian in time, or for more elaborate models.

Allows the user to define functions (details below) to determine the rules of transmission times and recovery times. There are two ways to do this. The user can define a function that calculates the recovery time and another function that calculates the transmission time. If recovery is after transmission, then transmission occurs. We do this if the time to transmission is independent of the time to recovery.

Alternately, the user may want to model a situation where time to transmission and time to recovery are not independent. Then the user can define a single function (details below) that would determine both recovery and transmission times.

Arguments:

G Networkx Graph

trans_time_fxn a user-defined function

returns the delay until transmission for an edge. May depend on various arguments and need not be Markovian.

Returns float

Will be called using the form

trans_delay = trans_time_fxn(source_node, target_node, *trans_time_args)
Here trans_time_args is a tuple of the additional arguments the functions needs.

the source_node is the infected node the target_node is the node that may receive transmission rec_delay is the duration of source_node’s infection, calculated by rec_time_fxn.

rec_time_fxn a user-defined function

returns the delay until recovery for a node. May depend on various arguments and need not be Markovian.

Returns float.

Called using the form

rec_delay = rec_time_fxn(node, *rec_time_args)
Here rec_time_args is a uple of additional arguments the function needs.
trans_and_rec_time_fxn a user-defined function

returns both a dict giving delay until transmissions for all edges from source to susceptible neighbors and a float giving delay until recovery of the source.

Can only be used INSTEAD OF trans_time_fxn AND rec_time_fxn.

Gives an ERROR if these are also defined

Called using the form ``trans_delay_dict, rec_delay = trans_and_rec_time_fxn(

node, susceptible_neighbors, *trans_and_rec_time_args)``

here trans_delay_dict is a dict whose keys are those neighbors who receive a transmission and rec_delay is a float.

trans_time_args tuple
see trans_time_fxn
rec_time_args tuple
see rec_time_fxn
trans_and_rec_time_args tuple
see trans_and_rec_time_fxn
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)
final time
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 even create animations using class methods.
SAMPLE USE:
import EoN
import networkx as nx
import matplotlib.pyplot as plt
import random

N=1000000
G = nx.fast_gnp_random_graph(N, 5/(N-1.))



#set up the code to handle constant transmission rate
#with fixed recovery time.
def trans_time_fxn(source, target, rate):
    return random.expovariate(rate)

def rec_time_fxn(node,D):
    return D

D = 5
tau = 0.3
initial_inf_count = 100

t, S, I, R = EoN.fast_nonMarkov_SIR(G,
                        trans_time_fxn=trans_time_fxn,
                        rec_time_fxn=rec_time_fxn,
                        trans_time_args=(tau,),
                        rec_time_args=(D,),
                        initial_infecteds = range(initial_inf_count))

# note the comma after ``tau`` and ``D``.  This is needed for python
# to recognize these are tuples

# initial condition has first 100 nodes in G infected.