Contagion

class contagion.Contagion(network: contagion.ContactNetwork, beta: float = 1.0, gamma: float = 1.0, save_history: bool = True, track_symptomatic: bool = False, psi: float = 1.0, omega: float = 0.0, implement_testing: bool = False, testing_type: str = 'random', test_rate: float = 0.0, contagion_type: str = 'sir')

For running epidemiological simulations on contact networks.

Methods

get_Im_random_filter()
get_new_recoveries() Calculates new recoveries in a time period.
get_new_symptomatic() Calculates new symptomatic infected nodes.
get_new_tested() Selects new nodes for testing.
get_new_testedpositive() New positive tests are newly-administered tests of infected patients.
get_new_transmissions() Calculates new infections in a time period.
init_histories() Initializes history tracking for susceptible, infected, recovered, and (if paramaterized) symptomatic and tested nodes.
plot_simulation(steps) Runs an epidemic simulation and produces a corresponding simulation history figure.
run_simulation(steps) Runs a contagion simulation for the specified number of steps.
run_simulation_get_max_infected(steps) Runs a contagion simulation and returns the maximum number of infected individuals at any step.
run_simulation_get_max_infected_index([steps]) Runs an epidemic simulation and returns the step at which the greatest number of infected individuals was reached.
run_simulation_monitor_notification() Runs an epidemic simulation up to the point that a threshold number of monitored individual are (ever) infected.
simulate_step() Iterates a single simulation time step, updating susceptible, infected, and recovered records with new transmissions and recoveries.
update_EverTested() Updates record of nodes ever tested with recent tests.
update_In() Updates infected record with new transmissions and new recoveries.
update_Re() Updates recovered record with new recoveries.
update_Su() Updates susceptible record with new transmissions.
update_Sy() Updates symptomatic record with new symptomatic infected nodes.
get_Im_random_filter()
get_new_recoveries()

Calculates new recoveries in a time period.

Parameters:

None

Returns:

new_recoveries : np.ndarray

an array describing if nodes are new recoveries

get_new_symptomatic()

Calculates new symptomatic infected nodes.

Parameters:

None

Returns:

new_symptomatic : np.ndarray

an array describing if nodes are newly-symptomatic nodes

get_new_tested()

Selects new nodes for testing. Re-testing is permitted. Default testing strategy is uniform random testing, although contact tracing (“contact”) is also available.

Parameters:

None

Returns:

new_tested : np.ndarray

array of nodes with newly-administered tests

new_ever_tested : np.ndarray

array of nodes with newly-administered tests who have not been tested before

Raises:

NotImplementedError

Raised if test rate is not recognized.

get_new_testedpositive()

New positive tests are newly-administered tests of infected patients.

Parameters:

None

Returns:

new_testedpositive : np.ndarray

array describing if nodes are new positive tests

get_new_transmissions()

Calculates new infections in a time period.

Parameters:

None

Returns:

new_transmissions : np.ndarray

an array describing if nodes are new transmissions

init_histories()

Initializes history tracking for susceptible, infected, recovered, and (if paramaterized) symptomatic and tested nodes.

Parameters:None
Returns:None
plot_simulation(steps: float = inf)

Runs an epidemic simulation and produces a corresponding simulation history figure.

Parameters:

steps : float

number of simulation steps to run.

run_simulation(steps: float = inf)

Runs a contagion simulation for the specified number of steps. If step count is not provided, runs until infectivity subsides.

Returns:None
run_simulation_get_max_infected(steps: float = inf)

Runs a contagion simulation and returns the maximum number of infected individuals at any step.

Parameters:

steps : float

number of simulation steps to run.

Returns:

num : int

maximum number of infected individuals at any simulation step.

run_simulation_get_max_infected_index(steps=inf)

Runs an epidemic simulation and returns the step at which the greatest number of infected individuals was reached.

Parameters:

steps : int

number of simulation steps to run.

Returns:

Historical index of maximum number of infected individuals.

run_simulation_monitor_notification()

Runs an epidemic simulation up to the point that a threshold number of monitored individual are (ever) infected.

Parameters:

None

Returns:

num : int

time-step when threshold number of monitored individual were (ever) infected

simulate_step()

Iterates a single simulation time step, updating susceptible, infected, and recovered records with new transmissions and recoveries. Handles delayed immunization and “switching out” for partial immunity.

Parameters:None
Returns:None
update_EverTested()

Updates record of nodes ever tested with recent tests.

Parameters:None
Returns:None
update_In()

Updates infected record with new transmissions and new recoveries.

Parameters:None
Returns:None
update_Re()

Updates recovered record with new recoveries. Handles immunity durations.

Parameters:

None

Returns:

None

Raises:

ValueError

Raised if contagion type is invalid.

update_Su()

Updates susceptible record with new transmissions.

Parameters:None
Returns:None
update_Sy()

Updates symptomatic record with new symptomatic infected nodes.

Parameters:None
Returns:None