Skip to content

laser.measles.mixing.base

laser.measles.mixing.base

laser.measles.mixing.base.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 pop, lat, and lon columns. May be None when the mixer is attached to a model component (the model sets it automatically).

required
params

Pydantic parameter object specific to the mixing model.

required

Example:

1
2
3
4
5
6
7
8
```python
from laser.measles.mixing.gravity import GravityMixing, GravityParams

# Construct a mixer — scenario is set automatically by the model
mixer = GravityMixing(params=GravityParams(k=0.01, c=2.0))
migration = mixer.migration_matrix  # (N, N) patch-to-patch travel
mixing = mixer.mixing_matrix        # rows sum to 1 (includes self-mixing)
```

laser.measles.mixing.base.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.mixing.base.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.mixing.base.BaseMixing.scenario property writable

Scenario DataFrame providing patch populations and coordinates.

laser.measles.mixing.base.BaseMixing.get_distances()

Compute pairwise great-circle distances between all patches.

Returns:

Type Description
ndarray

Distance matrix of shape (N, N) in kilometres.

laser.measles.mixing.base.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.mixing.base.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.mixing.base.BaseMixing.trips_into()

Returns the number of trips into each patch per tick.

laser.measles.mixing.base.BaseMixing.trips_out_of()

Returns the number of trips out of each patch per tick.