ABMModel#

class ABMModel(scenario, params, name='abm')[source]#

Bases: BaseLaserModel

Agent-based model for measles transmission with daily timesteps (SEIR).

Both scenario and params are required positional arguments. There is no default constructor — omitting params raises TypeError.

Parameters:
  • scenario (BaseABMScenario | DataFrame) – A DataFrame containing the metapopulation patch data. Required columns: id (str), pop (int), lat (Float64), lon (Float64), mcv1 (Float64).

  • params (ABMParams) – Simulation parameters including num_ticks, seed, and start_time. This argument is mandatory.

  • name (str) – The name of the model. Defaults to "abm".

Notes

Typical usage:

from laser.measles.abm import ABMModel, ABMParams
from laser.measles.abm import components

params = ABMParams(num_ticks=365, seed=42)
model = ABMModel(scenario=df, params=params)
model.add_component(components.InfectionSeedingProcess)
model.add_component(components.InfectionProcess)
model.run()

Initialize the disease model with the given scenario and parameters.

Parameters:
  • scenario (BaseABMScenario | DataFrame) – A DataFrame containing the metapopulation patch data, including population, latitude, and longitude.

  • parameters (ABMParams) – A set of parameters for the model and simulations.

  • name (str) – The name of the model. Defaults to “abm”.

Returns:

None

Attributes

ParamsType

ScenarioType

components

Retrieve the list of model components.

people

Methods

scenario_wrapper_class#

alias of BaseABMScenario

__call__(model, tick)[source]#

Hook for subclasses to update the model for a given tick.

Parameters:
  • model – The model instance.

  • tick (int) – The current time step or tick.

Return type:

None

setup_patches()[source]#

Setup the patches for the model.

Return type:

None

setup_people()[source]#

Placeholder for people - sets the data types for patch_id and susceptibility.

Return type:

None

initialize_people_capacity(capacity, initial_count=-1)[source]#

Initialize the people LaserFrame with a new capacity while preserving all properties.

This method uses the factory method from BasePeopleLaserFrame to create a new instance of the same type with the specified capacity, copying all properties from the existing instance.

Parameters:

capacity (int) – The new capacity for the people LaserFrame

Return type:

None

infect(indices, num_infected)[source]#

Infect agents by moving them from Susceptible to Exposed state.

This method finds the transmission component and delegates to its infect method, which handles both individual agent state updates and patch counter updates.

Parameters:
  • indices (int | ndarray) – The indices of the agents to infect.

  • num_infected (int | ndarray) – The number of agents to infect (for API consistency). Note: In ABM, this should match the length of indices.

Return type:

None

plot(fig=None)[source]#

Plots various visualizations related to the scenario and population data.

Parameters:

fig (Figure | None) – A matplotlib Figure object to use for plotting. If None, a new figure will be created.

Yields:

None – This function uses a generator to yield control back to the caller after each plot is created.

The function generates three plots:

  1. A scatter plot of the scenario patches and populations.

  2. A histogram of the distribution of the day of birth for the initial population.

  3. A pie chart showing the distribution of update phase times.