laser.measles.api
laser.measles.api
laser.measles.api.BaseMixing(scenario, params)
Bases: ABC
Abstract base for spatial mixing models.
Subclasses implement a specific migration kernel (gravity, radiation, etc.) that computes patch-to-patch travel probabilities from population sizes and distances. The resulting matrices drive spatial transmission in infection components.
Use a concrete mixer at set parameters time by passing it to an
infection component's parameter object, e.g.
InfectionParams(mixer=GravityMixing(...)). The model automatically
sets the scenario before the matrix is first accessed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scenario
|
Patch data with |
required | |
params
|
Pydantic parameter object specific to the mixing model. |
required |
Example:
1 2 3 4 5 6 7 8 | |
laser.measles.api.BaseMixing.migration_matrix
property
Migration matrix computed from get_migration_matrix().
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The migration matrix with lazy computation and caching. |
laser.measles.api.BaseMixing.mixing_matrix
property
Mixing matrix computed from get_mixing_matrix().
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The mixing matrix with lazy computation and caching. |
laser.measles.api.BaseMixing.scenario
property
writable
Scenario DataFrame providing patch populations and coordinates.
laser.measles.api.BaseMixing.get_distances()
Compute pairwise great-circle distances between all patches.
Returns:
| Type | Description |
|---|---|
ndarray
|
Distance matrix of shape |
laser.measles.api.BaseMixing.get_migration_matrix()
abstractmethod
Initialize a migration/diffusion matrix for population mixing. The diffusion matrix is a square matrix where each row represents the outbound migration from a given patch to all other patches e.g., [i,j] = [from_i, to_j].
Convention is: - Trips into node j: N_i @ M[i,j] - Trips out of node i: np.sum(M[i,j] * N_i[:,np.newaxis], axis=1)
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: The diffusion matrix: (N, N) |
laser.measles.api.BaseMixing.get_mixing_matrix()
Initialize a mixing matrix for population mixing.
The mixing matrix is a square matrix where each row represents the mixing of a given patch to all other patches e.g., [i,j] = [from_i, to_j]. It also includes internal mixing within a patch.
laser.measles.api.BaseMixing.trips_into()
Returns the number of trips into each patch per tick.
laser.measles.api.BaseMixing.trips_out_of()
Returns the number of trips out of each patch per tick.
laser.measles.api.CompetingDestinationsMixing(scenario=None, params=None)
Bases: BaseMixing
Competing-destinations migration model for spatial mixing.
Extends the gravity kernel with a correction that accounts for the attractiveness of alternative destinations:
When \(\delta < 0\), destinations that are surrounded by many other attractive locations receive less travel — the nearby alternatives "compete" for travellers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scenario
|
DataFrame | None
|
Patch data. |
None
|
params
|
CompetingDestinationsParams | None
|
Model parameters. |
None
|
Example:
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
laser.measles.api.CompetingDestinationsMixing.get_migration_matrix()
Compute the competing-destinations migration matrix.
Returns:
| Type | Description |
|---|---|
ndarray
|
Migration matrix of shape |
laser.measles.api.CompetingDestinationsParams
Bases: BaseModel
Parameters for the competing-destinations mixing model.
Extends the gravity kernel with a correction factor that penalises destinations surrounded by many other attractive alternatives.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Population source exponent. |
required |
b
|
float
|
Population destination exponent. |
required |
c
|
float
|
Distance decay exponent. |
required |
k
|
float
|
Average trip probability. |
required |
delta
|
float
|
Destination-competition exponent — negative values penalise destinations with many nearby competitors. |
required |
Example:
1 2 3 4 5 | |
laser.measles.api.GravityMixing(scenario=None, params=None)
Bases: BaseMixing
Gravity migration model for spatial mixing.
Computes a spatial mixing matrix where travel probability between patches is proportional to population sizes and inversely proportional to distance:
The scenario is optional at construction time. When attached to a
model via InfectionParams(mixer=...), the model sets the scenario
automatically before the mixing matrix is first computed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scenario
|
DataFrame | None
|
Patch data with |
None
|
params
|
GravityParams | None
|
Gravity model parameters. Uses
|
None
|
Example:
1 2 3 4 5 6 7 8 9 | |
laser.measles.api.GravityMixing.get_migration_matrix()
Compute the gravity-based migration matrix.
Returns:
| Type | Description |
|---|---|
ndarray
|
Migration matrix of shape |
laser.measles.api.GravityParams
Bases: BaseModel
Parameters for the gravity migration model.
The gravity kernel computes migration flow as:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
float
|
Population source exponent (applied as a − 1 inside the kernel). |
required |
b
|
float
|
Population destination exponent. |
required |
c
|
float
|
Distance decay exponent — larger values suppress long-distance travel. |
required |
k
|
float
|
Average trip probability (scales the overall matrix). |
required |
Example:
1 2 3 4 5 | |
laser.measles.api.RadiationMixing(scenario=None, params=None)
Bases: BaseMixing
Radiation migration model for spatial mixing.
Outbound migration from origin i to destination j is enhanced by the destination population and absorbed by the density of nearer destinations (intervening opportunities):
where \(s_{ij} = \sum_{k \in \Omega(i,j)} p_k\) is the total population of patches closer to i than j.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scenario
|
DataFrame | None
|
Patch data. |
None
|
params
|
RadiationParams | None
|
Model parameters. Uses
|
None
|
Example:
1 2 3 4 5 6 7 8 9 | |
laser.measles.api.RadiationMixing.get_migration_matrix()
Compute the radiation-based migration matrix.
Returns:
| Type | Description |
|---|---|
ndarray
|
Migration matrix of shape |
laser.measles.api.RadiationParams
Bases: BaseModel
Parameters for the radiation migration model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_home
|
bool
|
Whether to include home in the migration matrix |
required |
k
|
float
|
Scale parameter (avg trip probability) |
required |
Example:
1 2 3 4 5 | |
laser.measles.api.StoufferMixing(scenario=None, params=None)
Bases: BaseMixing
Stouffer intervening-opportunities migration model.
Long-distance travel is suppressed by the cumulative population of patches between origin and destination (intervening opportunities):
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scenario
|
DataFrame | None
|
Patch data. |
None
|
params
|
StoufferParams | None
|
Model parameters. Uses
|
None
|
Example:
1 2 3 4 5 6 7 8 9 | |
laser.measles.api.StoufferMixing.get_migration_matrix()
Compute the Stouffer migration matrix.
Returns:
| Type | Description |
|---|---|
ndarray
|
Migration matrix of shape |
laser.measles.api.StoufferParams
Bases: BaseModel
Parameters for the Stouffer migration model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_home
|
bool
|
Whether to include home in the migration matrix |
required |
k
|
float
|
Scale parameter (avg trip probability) |
required |
Example:
1 2 3 4 5 | |