---
title: The Poisson process
heading: Random arrivals in time, the gaps between them, and how streams combine
eyebrow: A11 · Lesson 13 · The Poisson process
xp: 40
---

::: hook
Cosmic rays flip bits in a memory chip at random moments. Packets reach a router, photons reach a detector, electrons cross a diode's junction, calls reach a switch. None of these arrive on a schedule, but each has a steady average rate, and each arrival is unaffected by the others. Lesson 12 counted such events in a fixed window. This lesson follows them in time: the **Poisson process** says how many arrive in any interval, how long you wait for the next one, and what happens when streams merge or split.
:::

::: play
- The curve is the probability density of the time until the $k$th arrival of a Poisson process at rate $\lambda$ per second. For $k = 1$ it's the exponential gap; each further arrival adds another independent gap.
- As $k$ grows, the wait bunches up around its mean, $k/\lambda$, with a spread of only $\sqrt{k}/\lambda$: many random gaps add up to something fairly predictable.
:::

```sim plot
view: graph
x: t = 0..20
y: density = 0..0.3
slider: lam = 0.5..4 step 0.5 = 1
slider: k = 1..10 step 1 = 3
plot: lam^k*t^(k - 1)*exp(-lam*t)/(k - 1)! | label: time until the kth arrival
readout: mean wait = k/lam | digits: 3
readout: standard deviation = sqrt(k)/lam | digits: 3
```

::: predict
## A memory chip suffers 2 bit upsets a day on average, at random. What's the chance of a 12-hour stretch with none?

- [ ] 0.5
- [x] About 0.37
- [ ] 0
- [ ] About 0.14

::: reveal
About 0.37: $e^{-1}$. Twelve hours at 2 a day averages 1 upset, and for a Poisson process the chance of none in a stretch with mean count $\mu$ is $e^{-\mu}$. Upsets don't wait their turn: a third of half-days pass clean, while others see two or three.
:::
:::

::: nameit
## The Poisson process

Arrivals at average rate $\lambda$ per second form a **Poisson process** when arrivals in non-overlapping intervals are independent and, in a short interval $\Delta t$, one arrival happens with probability $\lambda\Delta t$ and two almost never. Then:

- **The count** in any interval of length $t$ is Poisson with mean $\lambda t$:
$$P(N = k) = \frac{(\lambda t)^ke^{-\lambda t}}{k!}$$
- **The gaps** between arrivals are exponential with mean $1/\lambda$: $P(\text{gap} > t) = e^{-\lambda t}$.
- **No memory:** having waited $s$ seconds already, the remaining wait is still exponential with mean $1/\lambda$. The process doesn't know how long it's been.

## Merging and splitting

- **Merging** independent Poisson streams of rates $\lambda_1$ and $\lambda_2$ gives a Poisson stream of rate $\lambda_1 + \lambda_2$, and each arrival came from stream 1 with probability $\lambda_1/(\lambda_1 + \lambda_2)$.
- **Splitting** (thinning): if each arrival is kept independently with probability $p$, the kept arrivals are a Poisson stream of rate $p\lambda$, independent of the dropped ones.

## Fluctuations

The count's variance equals its mean, $\lambda t$, so its relative fluctuation is $1/\sqrt{\lambda t}$. That's the root of shot noise: a current $I$ is a stream of electrons at rate $I/q$, and its graininess shows up as noise that a later lesson turns into $\sqrt{2qIB}$.
:::

::: example
## A memory sees 2 upsets per day on average. Find the chance of no upset in 12 hours, the chance of 3 or more in a day, and the expected wait for the next upset.

::: solution
1. **No upset in 12 hours.** Twelve hours has mean $\lambda t = 1$:
   $$\begin{aligned} P(0) &= e^{-1} \\ &= 0.368 \end{aligned}$$
2. **Three or more in a day.** A day has mean 2:
   $$\begin{aligned} P(\ge 3) &= 1 - e^{-2}\left(1 + 2 + \frac{2^2}{2}\right) \\ &= 1 - 5e^{-2} \\ &= 0.323 \end{aligned}$$
3. **Expected wait.** The gaps are exponential with mean $1/\lambda$, half a day: 12 hours.
4. **No memory.** Because of the missing memory, that's also the expected wait from any moment, even if the last upset was hours ago.

**Answer:** the chance of no upset in 12 hours is 0.368, of 3 or more in a day 0.323, and the expected wait is 12 hours.
:::
:::

::: example
## Packets reach a router at 200 per second. What fraction of the gaps are shorter than 1 ms? A second link adds 300 packets per second; what's the merged rate, and what fraction of the merged arrivals come from the first link?

::: solution
1. **Short gaps.** The gaps are exponential with rate 200 per second:
   $$\begin{aligned} P(\text{gap} < 1\text{ ms}) &= 1 - e^{-200 \times 0.001} \\ &= 1 - e^{-0.2} \\ &= 0.181 \end{aligned}$$
2. **What it means.** Nearly a fifth of the packets arrive within a millisecond of the one before, even though the average gap is 5 ms. Short gaps are the most common kind; that's what makes queues build up.
3. **Merge the links.** Merged, the stream is Poisson at 500 per second.
4. **Share from the first link.** Each arrival came from the first link with probability
   $$\frac{200}{500} = 0.4$$

**Answer:** 18.1% of the gaps are shorter than 1 ms; the merged rate is 500 per second, and 40% of the merged arrivals come from the first link.
:::
:::

::: example
## A detector counts photons at an average of $10^6$ per second. If 10% of the photons are absorbed before reaching it, what does it count? What is the relative fluctuation of the count in 1 ms?

::: solution
1. **Thin the stream.** Thinning keeps a Poisson process Poisson: the detector sees a Poisson stream at
   $$0.9 \times 10^6\ \text{per second}$$
2. **Count in 1 ms.** The mean count is 900, with standard deviation
   $$\sqrt{900} = 30$$
3. **Relative fluctuation.**
   $$\frac{1}{30} = 3.3\%$$
4. **Counting longer.** Counting for 100 ms instead brings it to 0.33%: the precision of any photon or particle measurement improves only as the square root of the counting time.

**Answer:** it counts $0.9 \times 10^6$ photons per second, and the count in 1 ms fluctuates by 3.3%.
:::
:::

::: check
given: lam = 0.5 | 2 | 6; t = 0.75 | 2.5 | 3; k = 1 | 2 | 3
answer: (lam*t)^k*exp(-lam*t)/k!
tolerance: 0.5%

## Arrivals form a Poisson process at {lam} per second. What's the probability of exactly {k} arrivals in {t} s?

::: right
Right. The count is Poisson with mean $\lambda t$, so $P(\given{k}) = (\lambda t)^{\given{k}}e^{-\lambda t}/\given{k}!$ = {answer}.
:::

::: misses
- [lam^k*exp(-lam)/k!] That uses the mean for one second. The mean for {t} s is $\lambda t$.
- [exp(-lam*t)] That's the chance of none.
- [any] Not yet. Use the Poisson formula with mean $\lambda t$.
:::
:::

::: check
given: lam = 50 | 200 | 1000; t = 1 | 2 | 10
answer: exp(-lam*t*1e-3)
tolerance: 0.5%

## Packets arrive as a Poisson process at {lam} per second. What's the probability that the gap after a packet is longer than {t} ms?

::: right
Right. Gaps are exponential: $P(\text{gap} > t) = e^{-\lambda t}$ = {answer}.
:::

::: misses
- [1 - exp(-lam*t*1e-3)] That's the chance the gap is shorter.
- [exp(-lam*t)] Convert milliseconds to seconds.
- [any] Not yet. Use $e^{-\lambda t}$ with $t$ in seconds.
:::
:::

::: check
kind: parts
given: l1 = 100 | 200; l2 = 50 | 300; p = 0.05 | 0.2

## Two independent Poisson streams, at {l1} and {l2} arrivals per second, merge. Then each merged arrival is marked as an error with probability {p}, independently.

::: part
answer: l1 + l2
tolerance: 0.5%

### What is the merged rate, per second?

::: misses
- [(l1 + l2)/2] Merging adds the rates.
- [any] Not yet. Independent Poisson streams merge into one with the summed rate.
:::
:::

::: part
answer: l1/(l1 + l2)
tolerance: 0.5%

### What fraction of the merged arrivals come from the first stream?

::: misses
- [l2/(l1 + l2)] That's the second stream's share.
- [any] Not yet. Each arrival comes from stream 1 with probability $\lambda_1/(\lambda_1 + \lambda_2)$.
:::
:::

::: part
answer: p*(l1 + l2)
tolerance: 0.5%

### At what rate do errors arrive?

::: misses
- [p*l1] Errors can come from either stream: thin the merged rate.
- [any] Not yet. Thinning a Poisson stream by $p$ gives a Poisson stream of rate $p\lambda$.
:::
:::

::: right
Right. Merging and thinning both keep the process Poisson, so every question about the error stream is answered by its rate alone.
:::
:::

::: check
given: lam = 5000 | 1e5 | 1e7; t = 1 | 10 | 100
answer: 100/sqrt(lam*t*1e-3)
unit: %
tolerance: 0.5%

## A detector counts Poisson arrivals at {lam} per second for {t} ms. What is the count's relative fluctuation, its standard deviation over its mean, in percent?

::: right
Right. The mean is $\lambda t$ and so is the variance, so the relative fluctuation is $1/\sqrt{\lambda t}$ = {answer}.
:::

::: misses
- [100/(lam*t*1e-3)] The standard deviation is $\sqrt{\lambda t}$, not $\lambda t$'s reciprocal.
- [100*sqrt(lam*t*1e-3)] That's upside down: more counts mean a smaller relative fluctuation.
- [any] Not yet. Divide the standard deviation $\sqrt{\lambda t}$ by the mean $\lambda t$.
:::
:::

::: check
kind: python
given: lam = 2 | 5; s = 1 | 2 | 3

## Simulate a Poisson process at `lam` = {lam} per second for 10 000 seconds with `rng = np.random.default_rng(s)`: draw exponential gaps with `rng.exponential(1 / lam, n)` (take enough, `n = int(lam * 10000 * 1.2)`), add them up into arrival times and keep those below 10 000. Set `counts` to the number of arrivals in each 1-second window (an array of 10 000), `mean`, `var` to their mean and variance, and `p0` to the fraction of windows with no arrivals, to compare with $e^{-\lambda}$.

```python starter
import numpy as np
rng = np.random.default_rng(s)
counts = np.full(10000, lam)
mean = var = lam
p0 = np.exp(-lam)
print(mean, var, p0)
```

```python solution
import numpy as np
rng = np.random.default_rng(s)
n = int(lam * 10000 * 1.2)
t = np.cumsum(rng.exponential(1 / lam, n))
t = t[t < 10000]
counts = np.bincount(t.astype(int), minlength=10000)[:10000]
mean = counts.mean()
var = counts.var()
p0 = np.mean(counts == 0)
print(mean, var, p0)
```

```python tests
import numpy as np
r = np.random.default_rng(s)
tt = np.cumsum(r.exponential(1 / lam, int(lam * 10000 * 1.2))); tt = tt[tt < 10000]
c = np.bincount(tt.astype(int), minlength=10000)[:10000]
assert np.array_equal(counts, c), "Count the arrivals in each whole second: np.bincount of the integer parts of the times."
assert abs(mean - c.mean()) < 1e-12 and abs(var - c.var()) < 1e-12 and abs(p0 - np.mean(c == 0)) < 1e-12, "mean, var and p0 come from counts."
assert abs(mean - lam) < 0.1 and abs(var / mean - 1) < 0.05 and abs(p0 - np.exp(-lam)) < 0.01, "The counts should be Poisson: variance equal to the mean, and P(0) close to e^(-λ)."
```

::: right
Right. Building the process from exponential gaps gives counts whose variance matches their mean and whose empty windows match $e^{-\lambda}$: the two descriptions of a Poisson process, gaps and counts, are the same thing.
:::
:::

::: check
kind: derivation
vars: lam = 0.1..5, t = 0.1..3, n = 10..1000

## Derive the chance of no arrival in time $t$. Split $t$ into $n$ short pieces, each with an arrival probability of $\lambda t/n$, independently.

::: step
answer: (1 - lam*t/n)^n

### What's the chance that none of the $n$ pieces has an arrival?
:::

::: step
answer: exp(-lam*t)

### What does that become as $n \to \infty$?
:::

::: right
Right. $(1 - x/n)^n \to e^{-x}$, the same limit that turns compound interest into continuous growth. It's also $P(\text{gap} > t)$, which is why the gaps are exponential.
:::
:::

::: check
kind: choice

## A Poisson stream of failures has a mean gap of 1000 hours. The last failure was 800 hours ago. What is the expected time to the next one?

- [x] 1000 hours
- [ ] 200 hours
- [ ] 1800 hours
- [ ] 0 hours: it's overdue

::: right
Right. The exponential gap has no memory: the time already waited tells you nothing about the time left. That's the defining property of purely random arrivals, and the reason it's wrong to say a failure is "due".
:::

::: misses
- [2] That assumes failures come every 1000 hours like a clock. Random arrivals don't keep count.
- [3] Nothing about the past adds to the future wait: it's still 1000 hours.
- [4] A Poisson process is never overdue.
:::
:::

::: explain
## Why do the gaps between random arrivals have an exponential distribution, and why does that mean most gaps are shorter than the average?

::: model
For a gap to be longer than $t$, no arrival can happen in any of the many tiny intervals that make up $t$, and each is independent with a small, fixed chance. Multiplying those chances gives $e^{-\lambda t}$, an exponential tail. Its density is largest at zero and falls steadily, so short gaps are the most likely, and the mean, $1/\lambda$, is pulled up by occasional long gaps: $1 - e^{-1}$, about 63%, of gaps are shorter than the mean. Random arrivals therefore cluster, which is why queues form even when the average load is well under capacity.
:::
:::

::: practice

::: check
given: lam = 2 | 4; t = 0.5 | 1
answer: 1 - exp(-lam*t)
tolerance: 0.5%

## Arrivals come at {lam} per second. What's the chance of at least one in {t} s?

::: misses
- [exp(-lam*t)] That's the chance of none. Subtract it from 1.
- [any] $1 - e^{-\lambda t}$.
:::
:::

::: check
given: lam = 10 | 40; p = 0.1 | 0.25
answer: p*lam
tolerance: 0.5%

## A Poisson stream at {lam} per second has each arrival kept with probability {p}. What's the kept stream's rate?

::: misses
- [lam] Thinning scales the rate by $p$.
- [any] $p\lambda$.
:::
:::
:::
