Cumulative Distribution Function
The cumulative distribution function gives the probability that a random variable falls at or below a value, unifying discrete and continuous cases.
One function for every distribution
The cumulative distribution function (CDF) is F(x) = P(X ≤ x). Unlike a PMF or PDF, it is defined for every random variable, discrete, continuous, or mixed. It rises monotonically from 0 at −∞ to 1 at +∞.
Properties
- Non-decreasing: if a ≤ b then F(a) ≤ F(b).
- Right-continuous, with limits 0 and 1 at the extremes.
- P(a < X ≤ b) = F(b) − F(a).
- Jumps of size p(x) at discrete atoms; smooth where a density exists.
Recovering the distribution
Differentiating the CDF gives the density for continuous variables; the jump sizes give the PMF for discrete ones. So the CDF carries the full information of the distribution in a single, always-well-defined object.
The quantile function
The inverse, F⁻¹(p), is the quantile function: the value below which a fraction p of the mass lies. The median is F⁻¹(0.5). Quantiles summarize distributions robustly and are the basis for confidence intervals and box plots.
Inverse-transform sampling
If U is uniform on [0,1], then X = F⁻¹(U) has CDF F. This single fact turns a uniform random generator into a generator for any distribution whose quantile function you can compute, and it is a workhorse of Monte Carlo sampling.
import math, random
# sample exponential(rate=lam) via inverse transform
lam = 2.0
u = random.random()
x = -math.log(1-u)/lam
print(round(x,4))