Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/laser/generic/immunization.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def __init__(
self.end = int(model.params.nticks if end == -1 else end)
self.verbose = bool(verbose)

def __call__(self, model, tick: int) -> None:
def step(self, tick: int) -> None:
"""
Apply routine immunization at the given tick, if eligible.

Expand All @@ -97,17 +97,28 @@ def __call__(self, model, tick: int) -> None:
On each event:
- Agents with age in [age - period//2, age + period//2) are considered.
- A Binomial draw with probability `coverage` selects agents to immunize.
- Selected agents have `susceptibility` set to 0 (immune).
- If present, test arrays on `model.nodes` are updated for validation.
- Selected agents have their state set to `nodes.R` (immune).

Args:
model (object): LASER model (unused; provided for signature parity).
tick (int): Current simulation tick.

Returns:
None
"""
if (tick >= self.start) and ((tick - self.start) % self.period == 0) and (tick < self.end):
# Identify agents in the target age window
age_low = self.age - self.period // 2
age_high = self.age + self.period // 2
in_window = (self.model.people.age >= age_low) & (self.model.people.age < age_high)
# Sample among those in window
n_candidates = np.sum(in_window)
if n_candidates == 0:
return
rng = np.random.default_rng()
selected = rng.random(n_candidates) < self.coverage
idx = np.where(in_window)[0][selected]
# Set state to recovered (immune)
self.model.nodes.state[idx] = self.model.nodes.Rd (tick < self.end):
half_window = int(self.period // 2)
lower = max(0, int(self.age - half_window))
upper = int(self.age + half_window)
Expand Down