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. There are potentially many ways to do this, driven by source data from the geo or simulation parameters, so this module provides a uniform interface to accomplish the task, as well as a few common implementations.
Initializer
Bases: SimulationFunction[SimArray]
, ABC
Represents 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. You can specify a string -- which will be interpreted as a compartment name -- or an integer -- which will be interpreted as an index. Raises InitException 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 'population' individuals in a single compartment (default: the first compartment).
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) array and we use a copy of it.
initials
instance-attribute
The initial compartment values to use.
Proportional
Proportional(
ratios: NDArray[int64 | float64]
| list[int]
| list[float]
| list[list[int]]
| list[list[float]],
)
Bases: Initializer
Set all compartments as a proportion of their population according to the geo.
The parameter array provided to this initializer will be normalized, then multiplied
element-wise by the geo population. So you're free to express the proportions
in any way, (as long as no row is zero). Parameters:
- ratios
a (C,) or (N,C) numpy array describing the ratios for each compartment
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 infection to start. We assume
most people start out in a particular compartment (default: the first) and if chosen
for infection, are placed in another compartment (default: the second). The user
can identify which two compartments to use, but it can only be two compartments.
Parameters:
- initial_compartment
which compartment (by index) is "not infected", where most
individuals start out
- infection_compartment
which compartment (by index) 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 is used to distribute infections. Parameters:
- selection
a one-dimensional array of indices;
all values must be in range (-N,+N)
- seed_size
the number of individuals to infect in total
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). Parameters:
- location
the index of the node in which to seed an initial infection
- seed_size
the number of individuals to infect in total
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).
Parameters:
- labels
the labels of the locations to select for infection
- seed_size
the number of individuals to infect in total
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. Parameters:
- num_locations
the number of locations to choose
- seed_size
the number of individuals to infect in total
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 geo attribute.
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.
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.