Symbolic Matrix-Based Models

Provides an API to define epidemiological models in terms of sympy symbolic expressions based on a matrix description.

class epipack.symbolic_matrix_epi_models.SymbolicMatrixEpiModel(compartments, initial_population_size=1, correct_for_dynamical_population_size=False)[source]

Bases: epipack.symbolic_epi_models.SymbolicMixin, epipack.numeric_matrix_epi_models.MatrixEpiModel

A general class to define standard mean-field compartmental epidemiological model.

Parameters

compartments (list of string) -- A list containing compartment strings.

compartments

A list containing strings that describe each compartment, (e.g. "S", "I", etc.).

Type

list of string

N_comp

Number of compartments (including population number)

Type

int

linear_rates

Matrix containing transition rates of the linear processes.

Type

sympy.Matrix

quadratic_rates

List of matrices that contain transition rates of the quadratic processes for each compartment.

Type

list of sympy.Matrix

affected_by_quadratic_process

List of integer compartment IDs, collecting compartments that are affected by the quadratic processes

Type

list of int

Example

>>> epi = SymbolicMatrixEpiModel(symbols("S I R"))
>>> print(epi.compartments)
[ S, I, R ]
dydt()[source]

Obtain the equations of motion for this model in form of a sympy.Matrix.

set_linear_rates(rate_list, reset_rates=True, allow_nonzero_column_sums=True)[source]

Define the linear transition rates between compartments.

Parameters
  • rate_list (list of tuple) --

    A list of tuples that contains transitions rates in the following format:

    [
        ( acting_compartment, affected_compartment, rate ),
        ...
    ]
    

  • allow_nonzero_column_sums (bool, default : False) -- This keyword has no function in this class

  • reset_rates (bool, default : True) -- Whether to reset all linear rates to zero before setting the new ones.

set_quadratic_rates(rate_list, reset_rates=True, allow_nonzero_column_sums=False)[source]

Define the quadratic transition processes between compartments.

Parameters
  • rate_list (list of tuple) --

    A list of tuples that contains transitions rates in the following format:

    [
        ("coupling_compartment_0",
         "coupling_compartment_1",
         "affected_compartment",
         rate
         ),
        ...
    ]
    

  • allow_nonzero_column_sums (bool, default : False) -- This keyword has no function in this class

  • reset_rates (bool, default : True) -- Whether to reset all quadratic rates to zero before setting the new ones.

Example

For an SEIR model.

epi.set_quadratic_rates([
    ("S", "I", "S", -1 ),
    ("S", "I", "E", +1 )
])

Read as

"Coupling of S and I leads to a reduction in "S" proportional to \(S\times I\) and rate -1/time_unit. Furthermore, coupling of S and I leads to an increase in "E" proportional to \(S\times I\) and rate +1/time_unit."

class epipack.symbolic_matrix_epi_models.SymbolicMatrixSIModel(infection_rate, initial_population_size=1)[source]

Bases: epipack.symbolic_matrix_epi_models.SymbolicMatrixEpiModel

An SI model derived from epipack.symbolic_epi_models.SymbolicMatrixEpiModel.

class epipack.symbolic_matrix_epi_models.SymbolicMatrixSIRModel(infection_rate, recovery_rate, initial_population_size=1)[source]

Bases: epipack.symbolic_matrix_epi_models.SymbolicMatrixEpiModel

An SIR model derived from epipack.symbolic_epi_models.SymbolicMatrixEpiModel.

class epipack.symbolic_matrix_epi_models.SymbolicMatrixSIRSModel(infection_rate, recovery_rate, waning_immunity_rate, initial_population_size=1)[source]

Bases: epipack.symbolic_matrix_epi_models.SymbolicMatrixEpiModel

An SIRS model derived from epipack.symbolic_epi_models.SymbolicMatrixEpiModel.

class epipack.symbolic_matrix_epi_models.SymbolicMatrixSISModel(infection_rate, recovery_rate, initial_population_size=1)[source]

Bases: epipack.symbolic_matrix_epi_models.SymbolicMatrixEpiModel

An SIS model derived from epipack.symbolic_epi_models.SymbolicMatrixEpiModel.