Random Variables: A Density Is Not a Probability
Published:
From outcomes to numbers
A random variable $X$ is a measurable function $X:\Omega\to\mathbb{R}$ — it labels each outcome with a number. Rolling two dice, $\Omega$ has 36 elements, and $X = $ “sum” collapses them onto \(\{2,\dots,12\}\). Probability then transfers: \(P(X = 7) = P(\{\omega : X(\omega)=7\}) = 6/36\). This pushforward is why we can stop mentioning $\Omega$ almost immediately; all the information lives in the induced distribution on $\mathbb{R}$.
Discrete variables take countably many values and are described by a PMF $p(x) = P(X=x)$, with $p(x)\in[0,1]$ and $\sum_x p(x)=1$. Each value is a genuine probability.
Continuous variables take uncountably many values, and each single value has probability zero. What exists instead is a PDF $p(x)\ge 0$ with $\int p(x)\,dx = 1$, defined so that
The object that unifies both cases is the CDF
which is non-decreasing, right-continuous, and runs from 0 to 1. It jumps at atoms of a discrete variable and is continuous with $F’(x) = p(x)$ for a continuous one. Because $F$ always exists, statements phrased through CDFs — convergence in distribution, quantiles, stochastic dominance — apply uniformly to both kinds.
Change of variables
Push $X$ through a differentiable, strictly monotone map $Y = g(X)$. Probability mass is conserved, but it gets stretched or compressed, so the density must be rescaled by how much $g$ stretches the axis:
| In $d$ dimensions the derivative becomes the Jacobian matrix and the stretch factor becomes the absolute determinant, $$p_Y(\mathbf{y}) = p_X(g^{-1}(\mathbf{y}))\,\bigl | \det J_{g^{-1}}(\mathbf{y})\bigr | $$, because the determinant is exactly the local volume-scaling factor of a linear map. |
A concrete case: let $X\sim\mathrm{Uniform}(0,1)$ and $Y = -\log X$. Then $g^{-1}(y) = e^{-y}$ with derivative $-e^{-y}$, and $p_X = 1$ on the unit interval, so
the standard exponential. Uniform noise became an exponential purely through the Jacobian.
| This identity is the whole content of normalising flows: compose invertible maps, track $\sum \log | \det J | $, and you have an exact log-likelihood for the transformed density. Architectures like coupling layers exist precisely because a general $\det J$ costs $\mathcal{O}(d^3)$, whereas a triangular Jacobian costs $\mathcal{O}(d)$. |
Quantiles and inverse-transform sampling
The quantile function is the generalised inverse of the CDF, \(F^{-1}(u) = \inf\{x : F(x)\ge u\}\) for $u\in(0,1)$. The infimum handles flat regions and jumps, so $F^{-1}$ is defined even when $F$ is not strictly increasing. $F^{-1}(0.5)$ is the median.
Its consequence is one of the most useful facts in simulation: if $U\sim\mathrm{Uniform}(0,1)$ then $F^{-1}(U)$ has CDF $F$. The proof is one line, $P(F^{-1}(U)\le x) = P(U \le F(x)) = F(x)$, using only that $U$ is uniform. Every sampler for a univariate distribution can therefore be built from a uniform random number generator, provided you can invert $F$.
For the exponential with rate $\lambda$, $F(x) = 1-e^{-\lambda x}$, so $F^{-1}(u) = -\log(1-u)/\lambda$. With $\lambda = 2$ and a draw $u = 0.7$: $x = -\log(0.3)/2 = 1.20397/2 = 0.60199$. Since $1-U$ is also uniform, implementations usually write $-\log(U)/\lambda$.
Where this goes next
Summarising a distribution by a few numbers rather than a whole function is expectation and variance; the standard families and their densities are catalogued in common distributions.
Recap
- A random variable is a measurable map \(\Omega\to\mathbb{R}\); the distribution is the pushforward of \(P\).
- A PMF gives probabilities; a PDF gives density per unit \(x\) and may exceed 1. Only \(\int p\,dx\) is a probability.
- The CDF \(F(x)=P(X\le x)\) exists always and characterises the distribution.
- Under \(Y=g(X)\), densities pick up \(|\det J|\) — the identity behind normalising flows.
- \(F^{-1}(U)\) with \(U\sim\mathrm{Uniform}(0,1)\) samples from \(F\); for \(\mathrm{Exp}(\lambda)\) that is \(-\log(U)/\lambda\).
References
- Devroye, L. Non-Uniform Random Variate Generation. Springer, 1986.
- Papamakarios, G., Nalisnick, E., Rezende, D. J., Mohamed, S. & Lakshminarayanan, B. Normalizing Flows for Probabilistic Modeling and Inference. JMLR 22(57), 2021.
- Rezende, D. J. & Mohamed, S. Variational Inference with Normalizing Flows. ICML 2015.
- Casella, G. & Berger, R. L. Statistical Inference, 2nd ed. Duxbury, 2002.
