Uniform Distribution¶
Overview¶
The uniform distribution assigns equal probability to all values in an interval \([a, b]\). It is the simplest continuous distribution and serves as the foundation for random number generation, simulation, and probability integral transforms.
Definition¶
A random variable \(X\) follows a continuous uniform distribution on \([a, b]\):
The PDF is constant over the interval, reflecting equal likelihood for all values.
CDF¶
Properties¶
Derivation of Mean¶
Derivation of Variance¶
Standard Uniform Distribution¶
The special case \(U \sim \text{Uniform}(0, 1)\) is the standard uniform distribution. Any uniform variable can be related to it:
Conversely:
Probability Integral Transform¶
The uniform distribution plays a central role in simulation through the probability integral transform:
Theorem: If \(X\) is a continuous random variable with CDF \(F\), then \(F(X) \sim \text{Uniform}(0, 1)\).
Converse (Inverse Transform Sampling): If \(U \sim \text{Uniform}(0, 1)\), then \(X = F^{-1}(U)\) has CDF \(F\).
Proof¶
which is the CDF of \(\text{Uniform}(0, 1)\).
This theorem is the basis for generating random samples from any distribution using only a uniform random number generator.
Discrete Uniform Distribution¶
The discrete counterpart assigns equal probability to a finite set of values \(\{a, a+1, \ldots, b\}\):
Worked Example¶
Problem: Daily returns of a certain asset are modeled as uniformly distributed between \(-2\%\) and \(+3\%\). What is the probability the return exceeds \(1\%\)? What is the expected return?
Solution:
Python: PDF, CDF, and Sampling¶
PDF and CDF¶
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats
a, b = 2, 8
x = np.linspace(a - 1, b + 1, 300)
fig, ax = plt.subplots(figsize=(12, 3))
ax.plot(x, stats.uniform(loc=a, scale=b-a).pdf(x), label='PDF', lw=2)
ax.plot(x, stats.uniform(loc=a, scale=b-a).cdf(x), label='CDF', lw=2)
ax.spines[['top', 'right']].set_visible(False)
ax.legend()
plt.show()
Sampling with Histogram¶
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
np.random.seed(42)
a, b = 2, 8
samples = stats.uniform(loc=a, scale=b-a).rvs(50_000)
fig, ax = plt.subplots(figsize=(12, 3))
ax.hist(samples, bins=60, density=True, alpha=0.7, label='Samples')
x = np.linspace(a - 1, b + 1, 300)
ax.plot(x, stats.uniform(loc=a, scale=b-a).pdf(x), 'r-', lw=2, label='PDF')
ax.spines[['top', 'right']].set_visible(False)
ax.legend()
plt.show()
Inverse Transform Sampling¶
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
np.random.seed(42)
# Generate exponential samples via inverse transform
u = np.random.uniform(0, 1, 50_000)
lam = 2.0
x_exp = -np.log(1 - u) / lam # F_inv(u) for Exponential(lambda)
fig, ax = plt.subplots(figsize=(12, 3))
ax.hist(x_exp, bins=100, density=True, alpha=0.7, label='Inverse transform samples')
t = np.linspace(0, 4, 200)
ax.plot(t, stats.expon(scale=1/lam).pdf(t), 'r-', lw=2, label='Exponential PDF')
ax.spines[['top', 'right']].set_visible(False)
ax.legend()
plt.show()
Key Takeaways¶
- The uniform distribution assigns equal probability to all values in an interval, making it the "maximally uninformative" distribution over a bounded range.
- The standard uniform \(U(0,1)\) is the building block for random number generation via the inverse transform method.
- The probability integral transform establishes that applying the CDF to any continuous random variable yields a uniform result.
- Despite its simplicity, the uniform distribution is foundational to Monte Carlo simulation and computational statistics.