Week 10 · Random walks and first passage

Measure the probability of reaching capacity by a deadline.

← Week 9 · Subject contents · Week 11 →

Measure the probability of reaching capacity by a deadline.

Work through the problem

A buffer changes by +1 or −1 each minute with equal probability. Let T be the first minute it reaches level 3, starting at 0. The event T ≤ n is equivalent to the running maximum by minute n reaching 3. Checking only the last value misses paths that already reached 3 and came back down.

The earliest possible hit is at minute 3, with probability (1/2)³ = 1/8. Simulate a longer window, recording runs without hits as censored. The fraction of hits by the horizon estimates a probability. The mean among only completed hits does not give the unconditional mean.

First passage counts earlier hits. Fraction that has reached 3 by minute. Series: Cumulative hits.

First passage counts earlier hits.

Run the Python lab

import numpy as np
steps = np.random.default_rng(5).choice([-1,1], (15000,60))
walks = steps.cumsum(1)
ever = np.maximum.accumulate(walks, axis=1) >= 3
curve = ever.mean(axis=0)
print("Hit by minute 3:", round(curve[2],3))
print("Hit by minute 60:", round(curve[-1],3))
print("At or above 3 at minute 60:", round((walks[:,-1]>=3).mean(),3))
assert abs(curve[2]-.125) < .02

Output from the lab

Hit by minute 3: 0.127
Hit by minute 60: 0.699
At or above 3 at minute 60: 0.349

Practice

  1. Can the cumulative hit probability decrease with time?

Check your reasoning

  1. No. A path counted as having hit stays counted even when it moves down.

← Week 9 · Subject contents · Week 11 →

Further reading · MIT 6.262 · Discrete Stochastic Processes