Exponential Distribution
The exponential distribution describes the waiting time until the next event when events happen at a constant average rate: time until the next customer arrives, until a light bulb fails, until the next earthquake, between two clicks on a website.
It is the continuous partner of the Poisson distribution: Poisson counts how many events happen in an interval, exponential measures how long you wait between them.
| Parameter | Meaning | Default |
|---|---|---|
scale |
the average waiting time β = 1 / rate | 1.0 |
size |
output shape | one value |
Note: NumPy uses
scale(the mean), not the rate λ. If calls arrive at a rate of 4 per hour, the mean waiting time isscale = 1/4hour = 15 minutes.
Generating exponential data
import numpy as np
rng = np.random.default_rng(42)
# Customers arrive every 3 minutes on average
waits = rng.exponential(scale=3, size=8)
print(waits.round(2))
print("arrival times:", waits.cumsum().round(1))[7.21 7.01 7.15 0.84 0.26 4.36 4.23 9.37]
arrival times: [ 7.2 14.2 21.4 22.2 22.5 26.8 31.1 40.4]
cumsum() turns waiting times between arrivals into the clock times of the arrivals. Notice the mix of short and long gaps: many short waits, a few long ones.
Mean, spread and the long tail
For an exponential distribution, the mean and the standard deviation are both equal to scale. Values are always ≥ 0, with a long tail to the right:
import numpy as np
rng = np.random.default_rng(42)
x = rng.exponential(scale=3, size=200_000)
print(f"mean {x.mean():.3f} std {x.std():.3f}")
print(f"median {np.median(x):.3f} (theory 3 * ln 2 = {3 * np.log(2):.3f})")
print(f"share waiting longer than 9 min: {np.mean(x > 9):.4f} (theory {np.exp(-3):.4f})")mean 2.997 std 3.004
median 2.074 (theory 3 * ln 2 = 2.079)
share waiting longer than 9 min: 0.0496 (theory 0.0498)
The median is smaller than the mean: most waits are short, but rare long waits pull the average up.
Visualising
import numpy as np
import matplotlib.pyplot as plt
rng = np.random.default_rng(42)
plt.figure(figsize=(6, 3.5))
for scale, color in [(0.5, "#e07a5f"), (1, "#4dabcf"), (2, "#81b29a")]:
x = rng.exponential(scale, size=20_000)
plt.hist(x, bins=np.linspace(0, 6, 61), density=True, histtype="step",
color=color, linewidth=1.5, label=f"scale = {scale}")
plt.xlabel("waiting time")
plt.ylabel("density")
plt.legend()
plt.tight_layout()
plt.show()
print("Plotted exponential distributions for three scales")Plotted exponential distributions for three scales
All curves start at their highest point at 0 and decay; a larger scale means a slower decay and longer typical waits.
The memoryless property
The exponential distribution is memoryless: if you have already waited 5 minutes for the next customer, the extra time you still have to wait has the same distribution as if you had just started. Past waiting tells you nothing about the future.
import numpy as np
rng = np.random.default_rng(3)
x = rng.exponential(scale=3, size=1_000_000)
already_waited = x[x > 5] # cases where 5 minutes passed
extra = already_waited - 5
print(f"mean wait from scratch: {x.mean():.3f}")
print(f"mean extra wait after 5 min: {extra.mean():.3f}")mean wait from scratch: 3.002
mean extra wait after 5 min: 2.998
Connection to Poisson
If waiting times between events are exponential with mean β, then the number of events in a time window of length T is Poisson with λ = T / β:
import numpy as np
rng = np.random.default_rng(11)
gaps = rng.exponential(scale=0.5, size=100_000) # rate 2 events per unit time
times = gaps.cumsum()
per_window = np.bincount(times.astype(int))[:-1] # events in [0,1), [1,2), ...
print(f"events per unit window: mean {per_window.mean():.3f}, var {per_window.var():.3f}")events per unit window: mean 1.999, var 2.024
Mean and variance are both close to 2: a Poisson distribution with λ = 2.
Test yourself
What does the exponential distribution typically model?
- Counts of events
- Waiting time until the next event
- Heights of people
- Percentages
Events happen 5 times per minute on average. What scale do you pass to rng.exponential?
- 5
- 0.2
- 1
- 25
Which property is special to the exponential distribution?
- It is symmetric
- It is memoryless
- It has no mean
- It only takes integer values