epymorph.initializer
Initializers are responsible for setting up the initial conditions for the simulation: the populations at each node, and which disease compartments they belong to. It may draw from simulation parameters to do so. As there are many valid ways to do this, this module provides a uniform interface to accomplish the task as well as a few common implementations.
Initializer
Bases: SimulationFunction[SimArray]
, ABC
An initialization routine responsible for determining the initial values of populations by IPM compartment for every simulation node.
as_compartment
Convert a compartment identifier to a compartment index.
Parameters:
-
name_or_index
(int | str
) –Identifies the compartment; usually a compartment name. However this can also be an integer index, in which case we check that the index is valid and then return it.
Raises:
-
InitError
–If the compartment identifier is not valid.
validate
Override this method to validate the function evaluation result. If not overridden, the default is to do no validation. Implementations should raise an appropriate error if results are not valid.
Parameters:
-
result
(ResultT
) –The result produced from function evaluation.
NoInfection
Bases: Initializer
An initializer that places all individuals in a single compartment. Requires "population" as a data attribute.
Parameters:
-
initial_compartment
(int | str
, default:0
) –The compartment name or index in which to start the population.
requirements
class-attribute
instance-attribute
The attribute definitions describing the data requirements for this function.
For advanced use-cases, you may specify requirements as a property if you need it to be dynamically computed.
initial_compartment
instance-attribute
The IPM compartment where people should start, as either a name or index.
Explicit
Bases: Initializer
An initializer that sets all compartment populations directly. You provide the (N,C)-shaped array and the initializer returns a copy of it.
Parameters:
Proportional
Proportional(
ratios: NDArray[int64 | float64]
| list[int]
| list[float]
| list[list[int]]
| list[list[float]],
)
Bases: Initializer
An initializer that sets all compartments as a proportion of their population. Requires "population" as a data attribute.
Parameters:
-
ratios
(NDArray[int64 | float64] | list[int] | list[float] | list[list[int]] | list[list[float]]
) –A (C,)- or (N,C)-shaped array describing the ratios for each compartment. Row values will be normalized, such that they sum to 1.
requirements
class-attribute
instance-attribute
The attribute definitions describing the data requirements for this function.
For advanced use-cases, you may specify requirements as a property if you need it to be dynamically computed.
SeededInfection
SeededInfection(
initial_compartment: int | str = DEFAULT_INITIAL,
infection_compartment: int | str = DEFAULT_INFECTION,
)
Bases: Initializer
, ABC
Abstract base class for initializers which seed an initial infection. It assumes most people start out in a particular compartment (default: the first) and if chosen for infection, are moved to another compartment (default: the second).
You can customize which two compartments to use, but it can only be two.
Parameters:
-
initial_compartment
(int | str
, default:DEFAULT_INITIAL
) –Which compartment (by index or name) is "not infected", where most individuals start out.
-
infection_compartment
(int | str
, default:DEFAULT_INFECTION
) –Which compartment (by index or name) will be seeded as the initial infection.
initial_compartment
instance-attribute
The IPM compartment for non-infected individuals.
IndexedLocations
IndexedLocations(
selection: NDArray[intp] | list[int],
seed_size: int,
initial_compartment: int | str = DEFAULT_INITIAL,
infection_compartment: int | str = DEFAULT_INFECTION,
)
Bases: SeededInfection
Infect a fixed number of people distributed (proportional to their population) across a selection of nodes. A multivariate hypergeometric draw using the available populations in each node is used to distribute infections.
Requires "population" as a data attribute.
Parameters:
-
selection
(NDArray[intp] | list[int]
) –The list of node indices to infect; all values must be in range (-N,+N).
-
seed_size
(int
) –The number of individuals to infect in total.
-
initial_compartment
(int | str
, default:DEFAULT_INITIAL
) –Which compartment (by index or name) is "not infected", where most individuals start out.
-
infection_compartment
(int | str
, default:DEFAULT_INFECTION
) –Which compartment (by index or name) will be seeded as the initial infection.
requirements
class-attribute
instance-attribute
The attribute definitions describing the data requirements for this function.
For advanced use-cases, you may specify requirements as a property if you need it to be dynamically computed.
selection
instance-attribute
Which locations to infect.
seed_size
instance-attribute
seed_size: int = seed_size
How many individuals to infect, randomly distributed to selected locations.
SingleLocation
SingleLocation(
location: int,
seed_size: int,
initial_compartment: int | str = DEFAULT_INITIAL,
infection_compartment: int | str = DEFAULT_INFECTION,
)
Bases: IndexedLocations
Infect a fixed number of people at a single location (by index).
Requires "population" as a data attribute.
Parameters:
-
location
(int
) –The index of the node in which to seed an initial infection.
-
seed_size
(int
) –The number of individuals to infect in total.
-
initial_compartment
(int | str
, default:DEFAULT_INITIAL
) –Which compartment (by index or name) is "not infected", where most individuals start out.
-
infection_compartment
(int | str
, default:DEFAULT_INFECTION
) –Which compartment (by index or name) will be seeded as the initial infection.
requirements
class-attribute
instance-attribute
The attribute definitions describing the data requirements for this function.
For advanced use-cases, you may specify requirements as a property if you need it to be dynamically computed.
LabeledLocations
LabeledLocations(
labels: NDArray[str_] | list[str],
seed_size: int,
initial_compartment: int | str = DEFAULT_INITIAL,
infection_compartment: int | str = DEFAULT_INFECTION,
)
Bases: SeededInfection
Infect a fixed number of people distributed to a selection of locations (by label).
Requires "population" and "label" as data attributes.
Parameters:
-
labels
(NDArray[str_] | list[str]
) –The labels of the locations to select for infection.
-
seed_size
(int
) –The number of individuals to infect in total.
-
initial_compartment
(int | str
, default:DEFAULT_INITIAL
) –Which compartment (by index or name) is "not infected", where most individuals start out.
-
infection_compartment
(int | str
, default:DEFAULT_INFECTION
) –Which compartment (by index or name) will be seeded as the initial infection.
requirements
class-attribute
instance-attribute
The attribute definitions describing the data requirements for this function.
For advanced use-cases, you may specify requirements as a property if you need it to be dynamically computed.
seed_size
instance-attribute
seed_size: int = seed_size
How many individuals to infect, randomly distributed to selected locations.
RandomLocations
RandomLocations(
num_locations: int,
seed_size: int,
initial_compartment: int | str = DEFAULT_INITIAL,
infection_compartment: int | str = DEFAULT_INFECTION,
)
Bases: SeededInfection
Seed an infection in a number of randomly selected locations.
Requires "population" as a data attribute.
Parameters:
-
num_locations
(int
) –The number of locations to choose.
-
seed_size
(int
) –The number of individuals to infect in total.
-
initial_compartment
(int | str
, default:DEFAULT_INITIAL
) –Which compartment (by index or name) is "not infected", where most individuals start out.
-
infection_compartment
(int | str
, default:DEFAULT_INFECTION
) –Which compartment (by index or name) will be seeded as the initial infection.
requirements
class-attribute
instance-attribute
The attribute definitions describing the data requirements for this function.
For advanced use-cases, you may specify requirements as a property if you need it to be dynamically computed.
num_locations
instance-attribute
num_locations: int = num_locations
The number of locations to choose (randomly).
seed_size
instance-attribute
seed_size: int = seed_size
How many individuals to infect, randomly distributed to selected locations.
TopLocations
TopLocations(
top_attribute: AttributeDef[type[int]]
| AttributeDef[type[float]],
num_locations: int,
seed_size: int,
initial_compartment: int | str = DEFAULT_INITIAL,
infection_compartment: int | str = DEFAULT_INFECTION,
)
Bases: SeededInfection
Infect a fixed number of people across a fixed number of locations, selecting the top locations as measured by a given data attribute.
Requires "population" and the top attribute as data attributes.
Parameters:
-
top_attribute
(AttributeDef[type[int]] | AttributeDef[type[float]]
) –The attribute to use in determining the "top" locations. Must be numeric data.
-
num_locations
(int
) –The number of locations to choose.
-
seed_size
(int
) –The number of individuals to infect in total.
-
initial_compartment
(int | str
, default:DEFAULT_INITIAL
) –Which compartment (by index or name) is "not infected", where most individuals start out.
-
infection_compartment
(int | str
, default:DEFAULT_INFECTION
) –Which compartment (by index or name) will be seeded as the initial infection.
top_attribute
instance-attribute
top_attribute: (
AttributeDef[type[int]] | AttributeDef[type[float]]
) = top_attribute
The attribute to by which to judge the 'top' locations. Must be an N-shaped attribute.
requirements
instance-attribute
The attribute definitions describing the data requirements for this function.
For advanced use-cases, you may specify requirements as a property if you need it to be dynamically computed.
num_locations
instance-attribute
num_locations: int = num_locations
The number of locations to choose (randomly).
seed_size
instance-attribute
seed_size: int = seed_size
How many individuals to infect, randomly distributed between all selected locations.
BottomLocations
BottomLocations(
bottom_attribute: AttributeDef[type[int]]
| AttributeDef[type[float]],
num_locations: int,
seed_size: int,
initial_compartment: int | str = DEFAULT_INITIAL,
infection_compartment: int | str = DEFAULT_INFECTION,
)
Bases: SeededInfection
Infect a fixed number of people across a fixed number of locations, selecting the bottom locations as measured by a given geo attribute.
Requires "population" and the bottom attribute as data attributes.
Parameters:
-
bottom_attribute
(AttributeDef[type[int]] | AttributeDef[type[float]]
) –The attribute to use in determining the "bottom" locations. Must be numeric data.
-
num_locations
(int
) –The number of locations to choose.
-
seed_size
(int
) –The number of individuals to infect in total.
-
initial_compartment
(int | str
, default:DEFAULT_INITIAL
) –Which compartment (by index or name) is "not infected", where most individuals start out.
-
infection_compartment
(int | str
, default:DEFAULT_INFECTION
) –Which compartment (by index or name) will be seeded as the initial infection.
bottom_attribute
instance-attribute
bottom_attribute: (
AttributeDef[type[int]] | AttributeDef[type[float]]
) = bottom_attribute
The attribute to by which to judge the 'bottom' locations. Must be an N-shaped attribute.
requirements
instance-attribute
The attribute definitions describing the data requirements for this function.
For advanced use-cases, you may specify requirements as a property if you need it to be dynamically computed.
num_locations
instance-attribute
num_locations: int = num_locations
The number of locations to choose (randomly).
seed_size
instance-attribute
seed_size: int = seed_size
How many individuals to infect, randomly distributed between all selected locations.