def __init__(self, R0, recovery_rate, symptomatic_rate, population_size=1.0): infection_rate = R0 * recovery_rate MatrixEpiModel.__init__(self, list("SEIR"), population_size) self.set_quadratic_rates([ ("S", "I", "S", -infection_rate), ("S", "I", "E", +infection_rate), ]) self.add_transition_processes([ ("E", symptomatic_rate, "I"), ("I", recovery_rate, "R"), ])
def __init__(self, R0, recovery_rate, quarantine_rate, containment_rate, population_size=1.0): infection_rate = R0 * recovery_rate MatrixEpiModel.__init__(self, list("SIRXH"), population_size) self.set_quadratic_rates([ ("S", "I", "S", -infection_rate), ("S", "I", "I", +infection_rate), ]) self.add_transition_processes([ ("S", containment_rate, "H"), ("I", recovery_rate, "R"), ("I", containment_rate + quarantine_rate, "X"), ])
def mean_field_SIRX_tracing(kw): R0 = kw['R0'] Q0 = kw['Q0'] waning_quarantine_rate = omega = kw['waning_quarantine_rate'] recovery_rate = rho = kw['recovery_rate'] quarantine_rate = kappa = rho * Q0 / (1-Q0) infection_rate = eta = R0 * (rho) app_participation_ratio = theta = kw['app_participation_ratio'] k0 = kw['k0'] model = MatrixEpiModel(list("SIXRQ")) model.add_transition_processes([ ( "Q", waning_quarantine_rate,"S"), ( "I", recovery_rate,"R"), ( "I", kappa,"X"), ]) model.add_transmission_processes([ ( "S", "I", eta, "I", "I"), ( "I", "I", theta**2*kappa*k0, "I", "X"), ( "S", "I", theta**2*kappa*k0, "I", "Q"), ]) #for C, M in zip(model.compartments, model.quadratic_rates): # print(C, M) I0 = kw["I0"] model.set_initial_conditions({"S":1-I0,"I":I0}) t = kw["t"] result = model.integrate(t) return t, result
MatrixEpiModel.__init__(self, list("SEIR"), population_size) self.set_quadratic_rates([ ("S", "I", "S", -infection_rate), ("S", "I", "E", +infection_rate), ]) self.add_transition_processes([ ("E", symptomatic_rate, "I"), ("I", recovery_rate, "R"), ("R", waning_immunity_rate, "S"), ]) if __name__ == "__main__": # pragma: no cover epi = MatrixEpiModel(list("SEIR")) print(epi.compartments) print() epi.add_transition_processes([ ("E", 1.0, "I"), ("I", 1.0, "R"), ]) print(epi.linear_rates) epi.set_quadratic_rates([ ("S", "I", "S", -1.0), ("S", "I", "E", +1.0), ]) print() for iM, M in enumerate(epi.quadratic_rates): print(epi.get_compartment(iM), M)
from epipack import MatrixEpiModel, get_2D_lattice_links import numpy as np from time import time start = time() N = 1000 links = [(i, i + 1, 1.0) for i in range(N - 1)] base_compartments = "SIR" compartments = [(node, C) for node in range(N) for C in "SIR"] model = MatrixEpiModel(compartments) infection_rate = 2 recovery_rate = 1 mobility_rate = 0.1 quadratic_processes = [] linear_processes = [] print("defining processes") for node in range(N): quadratic_processes.append( ((node, "S"), (node, "I"), infection_rate, (node, "I"), (node, "I")), ) linear_processes.append(((node, "I"), recovery_rate, (node, "R"))) for u, v, w in links:
from time import time start = time() network, config, _ = nw.load('MHRN.json') # get the network properties N = len(network['nodes']) links = [ ( link['source'], link['target'], 1.0 ) for link in network['links'] ] base_compartments = "SIR" compartments = [ (node, C) for node in range(N) for C in base_compartments ] model = MatrixEpiModel(compartments) infection_rate = 3 recovery_rate = 1 mobility_rate = 0.05 quadratic_processes = [] linear_processes = [] print("defining processes") for node in range(N): quadratic_processes.append( ( (node, "S"), (node, "I"), infection_rate, (node, "I"), (node, "I") ), )