Tutorials › Quantitative Systems Pharmacology (QSP) › Stochastic Events and Update Scheduling in Agent Models

Spatial and Agent-Based Approaches · Tutorial 232 of 799

Stochastic Events and Update Scheduling in Agent Models

Compare event-driven and fixed-step stochastic updates, calculate event probabilities, and choose scheduling rules that match the model’s assumptions.

Advanced 12 min read

What You'll Learn

  • Define event hazards and the conditions for an event-driven update.
  • Derive waiting-time and event-type probabilities from competing hazards.
  • Convert a constant event rate into a fixed-step event probability.
  • Identify timing and ordering errors caused by large steps or sequential updates.
  • Explain how scheduling and random-number use affect reproducibility.
  • Compare event-driven, synchronous, and asynchronous update schemes.

Why Update Scheduling Is Part of the Model

An agent-based model specifies which events agents can undergo, but a simulation must also specify when those events are considered and how simultaneous or competing updates are resolved. A cell may divide, die, move, or change state according to stochastic rules. The same rules can generate different trajectories if one implementation checks every agent once per fixed interval while another advances directly to the next event time.

Scheduling is therefore not merely a programming detail. It determines the time scale represented by the simulation, whether one agent’s update can affect another agent during the same step, and how random draws map to events. The appropriate scheme depends on the model’s intended stochastic process and on whether rates change between updates.

Definition: Let \(X(t)\) denote the complete agent-model state at time \(t\), including agent states and any spatial occupancy needed to determine which events are possible. An event channel \(j\) is an allowed state transition with hazard \(a_j(X(t),t)\), measured in events per unit time. Conditional on the current state, the probability that channel \(j\) occurs during a sufficiently short interval of length \(h\) is \(a_j(X(t),t)h+o(h)\), where \(o(h)/h\) tends to zero as \(h\) tends to zero.

The state must include enough information to determine the hazards. For example, if a cell can divide only when a neighboring site is empty, local occupancy belongs in the model state because it affects whether the division channel is enabled. Hazards can be zero for disabled events. A complete state representation allows the update procedure to calculate rates consistently after each event.

Event-Driven Updates

In a continuous-time event-driven scheme, the simulation clock advances to the next stochastic event rather than by a predetermined increment. Suppose that, while the state remains fixed, there are \(m\) enabled channels with constant hazards \(a_1,\ldots,a_m\). Their total hazard is \(A=\sum_{j=1}^{m}a_j\). The waiting time to the next event is exponentially distributed with rate \(A\), and, conditional on an event occurring, channel \(j\) is selected with probability \(a_j/A\).

$$ P(\text{no event in }[t,t+\tau])=e^{-A\tau}, \qquad \tau\sim \operatorname{Exponential}(A), \qquad P(\text{next channel}=j)=\frac{a_j}{A}. $$

This result assumes that the current state and its hazards remain unchanged up to the next event, that the event channels define the possible transitions, and that the total hazard is finite. After an event, the state changes; the simulator must then recalculate the enabled channels and their hazards. The selected event is applied once, at the simulated event time, before the next waiting time is generated.

Derivation: Over a short interval \(h\), the probability of no event is \(1-Ah+o(h)\), since the channel hazards add and the probability of multiple events is of smaller order than \(h\). If \(S(\tau)\) is the probability of no event through time \(\tau\), then \(S(\tau+h)=S(\tau)(1-Ah+o(h))\). Taking the limit gives \(dS/d\tau=-AS\), with \(S(0)=1\), so \(S(\tau)=e^{-A\tau}\). The probability density that the first event is channel \(j\) at time \(\tau\) is \(a_j e^{-A\tau}\). Integrating over \(\tau\geq 0\) gives \(a_j/A\), the stated channel probability.

Worked Example: Two Competing Cell Events

Hypothetical model. A cell in a fixed local environment has a division hazard of \(0.08\) per hour and a death hazard of \(0.02\) per hour. Assume these hazards stay constant until the first event.

The total hazard is \(A=0.08+0.02=0.10\) per hour. The waiting time to either event is exponential with mean \(1/A=10\) hours. The probability that no event occurs during the next 2 hours is \(e^{-A\tau}=e^{-(0.10)(2)}=e^{-0.2}=0.8187\). Thus the probability of at least one event in those 2 hours is \(1-0.8187=0.1813\).

Conditional on an event being next, its type is division with probability \(0.08/0.10=0.8000\), and death with probability \(0.02/0.10=0.2000\). The probability that division is the first event and occurs within 2 hours is \((0.08/0.10)(1-e^{-0.2})=0.8000(0.1813)=0.1450\). The calculation describes the first event only; it does not count a possible later event after the cell’s state has changed.

The simple event-driven procedure above applies directly when hazards are constant between events. If hazards vary continuously with time even though the state is unchanged, the probability of no event through \(\tau\) instead depends on the integrated total hazard, \(\int_0^\tau A(u)\,du\). A constant-rate waiting-time draw is then not generally valid. Time-varying hazards require an algorithm that accounts for their time dependence, or a stepwise approximation whose accuracy is checked. Predetermined events, such as a treatment administration at a known time, must also be placed on the simulation schedule so that a stochastic event does not incorrectly carry the model past a state-changing intervention.

Fixed-Step Updates and Rate-to-Probability Conversion

A fixed-step scheme advances the clock by \(\Delta t\) and evaluates stochastic events at those update times. A hazard is a rate, not a probability: multiplying a rate by a step length gives only a small-step approximation to an event probability. For one constant hazard \(a\), the exact probability of at least one event over a step, if the rate stays constant, is \(p=1-e^{-a\Delta t}\). For a single event channel that disables itself after firing, a fixed-step implementation may draw a Bernoulli event with this probability.

$$ p(\text{at least one event in }\Delta t)=1-e^{-a\Delta t} \approx a\Delta t \quad \text{when }a\Delta t\text{ is small}. $$

For several competing channels with constant hazards and total \(A\), the exact probability of no event in the step is \(e^{-A\Delta t}\). The probability that the first event in the step is channel \(j\) is \((a_j/A)(1-e^{-A\Delta t})\). These probabilities describe the first event only. A scheme that permits just one update per agent per step will not represent multiple events by that agent within the same interval.

$$ P(\text{no event})=e^{-A\Delta t}, \qquad P(\text{first event is }j)=\frac{a_j}{A}\left(1-e^{-A\Delta t}\right). $$

Worked Example: Choosing a Fixed Step for a Cell Event

Hypothetical model. Each eligible cell has one event channel with a constant hazard of \(0.03\) per hour. The simulator uses a step of 0.5 hours and allows at most one event of this type per cell in a step.

The exact per-cell event probability for the step is \(p=1-e^{-(0.03)(0.5)}=1-e^{-0.015}=0.01489\). Using the small-step approximation gives \(a\Delta t=(0.03)(0.5)=0.01500\). The absolute difference is \(0.01500-0.01489=0.000112\), about \(0.75\%\) of the exact probability.

If 20 eligible cells have independent event draws and unchanged hazards during this step, the expected number of events is \(20p=20(0.01489)=0.2978\). This expectation does not mean that 0.2978 events occur in a particular run; the realized count is an integer. The independence and unchanged-hazard assumptions may fail if one event alters another cell’s eligibility or local environment during the interval.

A step should be small relative to the fastest relevant event time scale, but “small” is a model-specific accuracy requirement, not a universal number. When \(A\Delta t\) is large, a substantial fraction of agents may have multiple events available within a step, or important state changes may occur between scheduled updates. A one-event-per-step rule then creates timing error even if the probability formula for the first event is exact. Reducing \(\Delta t\) can reduce this error, at increased computational cost.

Update Order, Conflicts, and Reproducibility

A fixed-step model must additionally define how agents are processed. In a synchronous update, event proposals are calculated from a shared snapshot of the state at the beginning of the step and then committed together. In an asynchronous update, agents are processed in sequence and their changes can affect later agents in that same step. A randomized sequential order can avoid always favoring a fixed index order, but it does not make the result equivalent to a synchronous update.

Worked Example: Two Cells Compete for One Empty Site

Hypothetical model. Two cells can each attempt to move into the same empty site during a step. Each independently proposes a move with probability \(0.40\). If both propose, the model must choose a winner.

Under a synchronous snapshot, the probability both propose is \(0.40(0.40)=0.1600\). Suppose the conflict is resolved by choosing either proposer with equal probability. The chance that the site is occupied is the chance at least one proposal occurs: \(1-(1-0.40)^2=1-0.36=0.6400\). By symmetry, each cell has probability \(0.6400/2=0.3200\) of being the winner.

Now consider sequential processing with cell 1 first, immediate commitment of its successful move, and cell 2 attempting only if the site remains empty. Cell 1 occupies the site with probability \(0.40\). Cell 2 occupies it with probability \((1-0.40)(0.40)=0.2400\). Total occupancy is still \(0.6400\), but the two cell-specific probabilities are \(0.4000\) and \(0.2400\), respectively. The fixed order favors cell 1. Randomizing the order can remove this systematic identity preference, but the process still has sequential rather than snapshot semantics.

For reproducibility, record more than a single random seed. The model specification should state the update schedule, agent ordering rule, conflict-resolution rule, and the point at which rates and eligibility are recalculated. With a conventional sequential random-number generator, changing the order of operations can assign different random draws to different agents, so even the same seed need not reproduce the same trajectory after a code change. Reproducibility can be strengthened by recording software and parameter versions, using a documented deterministic ordering, or assigning random streams to agents or events. These choices make runs easier to repeat; they do not remove the model’s inherent stochastic variation.

Choosing a Scheme and Diagnosing Problems

ApproachScheduling interpretationMain advantageImportant limitation
Event-drivenAdvance to the next event time; recalculate after each event.Represents continuous-time event timing without a fixed time grid.Requires valid hazards between events; time-varying rates and scheduled interventions need explicit handling.
Fixed-step, synchronousPropose updates from a shared state snapshot, then resolve and commit.Clear simultaneous-update semantics and convenient regular observation times.Can delay changes until the next step and requires explicit conflict resolution.
Fixed-step, sequentialProcess agents in an order, usually committing changes immediately.Simple to implement and accommodates local changes during processing.Results can depend on order; a fixed ordering can systematically privilege some agents.

Several diagnostics can reveal a mismatch between the chosen schedule and the intended model. Compare fixed-step runs at successively smaller \(\Delta t\); if summaries such as event counts, event-time distributions, or spatial occupancy shift materially, the original step may be too coarse. Check that probabilities lie between zero and one, that disabled events have zero hazard, and that total event probabilities agree with the stated rule. For competing events, verify that no-event and event-type probabilities sum to one. Compare results across agent orderings to detect order sensitivity, and test whether a known scheduled intervention occurs at its intended time.

These checks identify implementation and approximation problems, but they do not establish that the biological rules themselves are appropriate. Event-driven simulation is not automatically more realistic: its advantage is exact timing for the specified continuous-time hazards under its assumptions. Fixed-step simulation can be appropriate when the underlying process is naturally updated at discrete times or when its step-size error is demonstrably negligible. The key is to make the schedule part of the model definition and validate that implementation against that definition.

Common Mistakes

  • Treating a rate as a probability. A hazard of 0.2 per hour is not a 20% chance of an event over any interval. For a one-hour interval with constant hazard, the probability is \(1-e^{-0.2}=0.1813\).
  • Using a large step with a small-step approximation. The approximation \(p\approx a\Delta t\) is justified when \(a\Delta t\) is small. For larger values, it can be inaccurate or even exceed one.
  • Assuming synchronous and sequential updates are interchangeable. Immediate changes during a sequential sweep can alter later agents’ opportunities; a snapshot update cannot do so until proposals are committed.
  • Assuming a seed guarantees identical results under any schedule. A seed initializes random draws, but changed draw order or event ordering can assign those draws differently.
Key takeaway: Specify the event-time assumptions, conversion from hazards to probabilities, update order, and conflict rule together. Then check that time-step refinement or alternative orderings do not reveal a consequential scheduling artifact.

Check Your Understanding

Answer each question, then compare with the solutions below.

  1. A single event has constant hazard \(0.12\) per day. What is the probability it occurs within 3 days?
  2. Two competing event channels have hazards \(0.06\) and \(0.04\) per hour. Find the probability that no event occurs in the next 1 hour, and the probability that the next event is channel 1.
  3. Why can two simulations with the same random seed produce different trajectories after changing from a fixed agent order to a randomized order?
  4. What is one reason a fixed-step simulation with a one-event-per-agent limit may differ from a continuous-time event-driven simulation?

Solutions. (1) \(1-e^{-(0.12)(3)}=1-e^{-0.36}=0.3023\), or about 30.23%. (2) The total hazard is \(0.10\) per hour, so the no-event probability is \(e^{-0.10}=0.9048\). Conditional on an event being next, channel 1 has probability \(0.06/0.10=0.6000\). (3) Changing the order changes which agent receives each successive draw from a conventional random-number stream; it can also change state immediately before later agents are processed. (4) More than one event may occur during a step, but the fixed-step rule permits only one; it therefore misses later within-step events and may delay state changes until the next update.

Clinical Biostats