ContactNetwork¶
-
class
contagion.
ContactNetwork
(G: networkx.classes.graph.Graph, fraction_infected: float = 0, fraction_recovered: float = 0)¶ For creating contact networks fron NetworkX graphs.
Methods
generate_random_walk
(walk_length)Generates an unbiased random walk of a specified length along the nodes/edges of the contact network. generate_random_walk_degree_sequence
(walk_length)Generates an unbiased random walk of a specified length along the nodes/edges of the contact network and returns the degree of each node encountered during the walk. immunize_network
(Im[, im_type, …])Immunizes a network according to a provided Immunization array. init_Su_In_Re
()Initializes susceptible, infected, and recovered arrays, ensuring there is no overlap/redundancy among them. reset_Su_In_Re
()Resets susceptible, infected, and recovered arrays to their original initializations. -
generate_random_walk
(walk_length: int = 1)¶ Generates an unbiased random walk of a specified length along the nodes/edges of the contact network. Elements of the walk are node indices.
Parameters: walk_length : int
number of nodes to include in the random walk
Returns: walk : List
the node indices for the walk
-
generate_random_walk_degree_sequence
(walk_length: int = 1)¶ Generates an unbiased random walk of a specified length along the nodes/edges of the contact network and returns the degree of each node encountered during the walk.
Parameters: walk_length : int
number of nodes to include in the random walk
Returns: degrees : List
the degree of each element of a random walk
-
immunize_network
(Im, im_type='vaccinate', im_starts_after=0, efficacy=1.0, mo_thresh=1)¶ Immunizes a network according to a provided Immunization array. The immunization array may be generated independently, or using the methods in the Immunization class. Immunization is either “vaccinate” (implemented by placing individuals in the Recovered compartment) or “monitor” (which tracks specified nodes, stopping a contagion simulation when mo_thresh monitored nodes have been ever infected).
Parameters: Im : numpy.ndarray
a (self.n, 1) array with 1 at indices to be immunized and 0 elsewhere
im_type : str
immunization type. Can be either “vaccinate” or “monitor”
im_starts_after : int
step index after which the immunization policy should be implemented
efficacy : float
efficacy of the immunization (as a float in [0, 1.]) only operates with im_type == “vacciante”.
mo_thresh : int
monitor threshold.
Returns: None
Raises: ValueError: when immunization array is the wrong dimensions
ValueError: when invalid immunization type is provided.
-
init_Su_In_Re
()¶ Initializes susceptible, infected, and recovered arrays, ensuring there is no overlap/redundancy among them.
Returns: None
-
reset_Su_In_Re
()¶ Resets susceptible, infected, and recovered arrays to their original initializations.
Parameters: None Returns: None
-