02 · Probability & Random Variables

A standalone tutorial (used in W02): the probability the course actually uses, built from the ground up — sample spaces, events, random variables, and expectation. Joints, conditionals and Bayes’ rule follow in the next concept. Readers already comfortable with these notions may proceed directly to Distributions and Maximum Likelihood.

NoteThe level this works at

This tutorial works at the elementary level, and deliberately: it treats arbitrary subsets as events and splits the world into “discrete” and “continuous”. That is the standard undergraduate presentation and is entirely serviceable for every computation in the course.

The elementary treatment here is enough for the probability calculations used in the course. Later notes introduce joint and conditional distributions when they are needed for diffusion models.

Probability theory is built on two distinct maps: the probability measure, which assigns numbers to events, and the random variable, which assigns numbers to outcomes. Distinguishing the two carefully at the outset prevents most of the common confusions, and this tutorial is organized accordingly.

The sample space, events, and the probability measure

A random experiment is modeled by three objects.

  • The sample space \(\Omega\) is the set of all possible outcomes of the experiment, with one element \(\omega \in \Omega\) per complete outcome. For a single die, \(\Omega = \{1, \dots, 6\}\). For two coin tosses, \(\Omega = \{HH, HT, TH, TT\}\); note that an outcome specifies the result of the entire experiment, i.e. both tosses. For a point drawn from the interval \([0,1]\), \(\Omega = [0,1]\), an uncountable set.

  • An event is a subset \(A \subseteq \Omega\); events are the objects to which probabilities are assigned. “The die shows an even number” is the event \(\{2, 4, 6\}\); “at least one head” is the event \(\{HH, HT, TH\}\). An event is a collection of outcomes, not an outcome.

    Worth pausing on the asymmetry here, because it is the source of a lot of early confusion. Exactly one outcome occurs, but many events occur at once. Roll a \(4\) and the single outcome is \(\omega = 4\) — yet “even”, “at most \(5\)”, “not a \(6\)” and \(\Omega\) itself have all occurred simultaneously, because \(4\) belongs to all of them. Outcomes are exclusive; events are not.

  • The probability measure is the first of the two maps:

    \[ P : \text{events} \longrightarrow [0, 1], \]

    required to satisfy Kolmogorov’s axioms: (i) \(P(A) \ge 0\) for every event \(A\);

    1. \(P(\Omega) = 1\); (iii) for mutually exclusive events \(A_1, A_2, \dots\), \(P\big(\bigcup_i A_i\big) = \sum_i P(A_i)\) (countable additivity).

All further rules are consequences of the axioms; two used constantly are \(P(A^c) = 1 - P(A)\) and \(P(A \cup B) = P(A) + P(B) - P(A \cap B)\).

A remark on the continuous case. For \(\Omega = [0,1]\) with the uniform measure, every singleton event \(\{\omega\}\) has probability zero, although some outcome certainly occurs. Probability zero therefore does not mean impossibility; it means a vanishing fraction of the possibilities. This is also the reason \(P\) is defined on events rather than on individual outcomes: in the continuous case, individual outcomes are too small to carry probability.

Random variables

The second map is the random variable. A random variable is a function

\[ X : \Omega \longrightarrow \mathbb{R} \]

that assigns a numerical value to each outcome. For the two-coin experiment with \(X\) the number of heads: \(X(HH) = 2\), \(X(HT) = X(TH) = 1\), \(X(TT) = 0\). Despite the name, \(X\) is a fixed, deterministic function; the randomness resides entirely in which outcome \(\omega\) the experiment produces.

WarningA random variable is not a function of events

The single most common misreading is that a random variable takes events to numbers. It does not. Its input is a single outcome \(\omega\), never a set.

Take a die and the indicator of oddness,

\[ Y(\omega) = \begin{cases} 1 & \omega \in \{1,3,5\},\\ 0 & \omega \in \{2,4,6\}. \end{cases} \]

It is tempting to read this as “\(Y\) sends the event even to \(0\).” It does not. \(Y\) sends the outcome \(2\) to \(0\), and the outcome \(4\) to \(0\), and the outcome \(6\) to \(0\) — three separate outcomes that happen to receive the same number. Nothing is ever evaluated at the set \(\{2,4,6\}\).

The direction that is available runs the other way: a random variable manufactures events by taking preimages. From \(Y\) we recover

\[ \{\omega : Y(\omega) = 0\} = \{2,4,6\}, \qquad \{\omega : Y(\omega) = 1\} = \{1,3,5\}, \]

so the chain is random variable \(\to\) numerical condition \(\to\) event \(\to\) probability. Getting this arrow the right way round is most of what the two-map picture buys you.

The two maps combine as follows. A statement such as \(\mathbb{P}(X = 1)\) is evaluated by first identifying the event determined by the condition and then applying \(P\) to it:

\[ \mathbb{P}(X = 1) \;=\; P\big(\{\omega \in \Omega : X(\omega) = 1\}\big) \;=\; P(\{HT, TH\}) = \tfrac{2}{4}. \]

Carrying this out for every value (or set of values) of \(X\) yields the distribution of \(X\), a probability assignment on the real line. Once the distribution is available, the underlying sample space is usually suppressed and one works with the distribution directly; this is standard practice, and the remainder of the course follows it. The present section records what that convention leaves implicit.

A discrete random variable is described by its probability mass function (pmf) \(p(x) = \mathbb{P}(X = x)\), with \(\sum_x p(x) = 1\). A continuous random variable is described by its probability density function (pdf) \(f(x) \ge 0\), with \(\int_{-\infty}^{\infty} f(x)\, dx = 1\); probabilities are obtained as areas under the density,

\[ \mathbb{P}(a \le X \le b) = \int_a^b f(x)\, dx . \]

Three properties of densities deserve emphasis.

  • A density value is not a probability and may exceed 1; the Uniform distribution on \([0, \tfrac12]\) has \(f \equiv 2\). Only areas under the density are probabilities.
  • \(\mathbb{P}(X = x) = 0\) for every individual \(x\), by the singleton remark above. The informal reading of a density is \(f(x)\,dx \approx\) the probability of an outcome within \(dx\) of \(x\); densities compare the relative plausibility of neighborhoods.
  • The cumulative distribution function (CDF) \(F(x) = \mathbb{P}(X \le x)\) applies to discrete and continuous variables alike, and its derivative, where it exists, is the pdf. The CDF appears in Generative AI, in Its Simplest Form as the sampling map \(F^{-1}\).

What \(\Omega\) actually is when the variable is continuous

Write \(T \sim \mathcal{N}(\mu, \sigma^2)\) for tomorrow’s temperature and it is natural to assume the sample space is \(\mathbb{R}\). It is not — or at least, it need not be, and thinking it must be obscures what the notation says.

The experiment is tomorrow. Its outcomes are the ways tomorrow could turn out: every physically possible state of the world, an enormous set with no numbers in it anywhere. Call it \(\Omega\). The temperature is a reading taken from such a state,

\[ T : \Omega \longrightarrow \mathbb{R}, \]

which extracts one number from each possible world and discards everything else about it — the wind, the cloud cover, who won the match. Humidity would be a second reading \(H : \Omega \to \mathbb{R}\) of the very same worlds, which is precisely why \(T\) and \(H\) can be correlated: they are two numbers pulled from one outcome.

So \(T \sim \mathcal{N}(\mu, \sigma^2)\) is not a claim about \(\Omega\) at all. It is a claim about the distribution induced by \(T\) on the real line: the probability that lands on each region of \(\mathbb{R}\) once \(P\) is pushed through \(T\). The underlying \(\Omega\) stays exactly where it was, unmentioned.

The canonical shortcut

Nobody ever constructs the set of possible worlds. What statistics does instead is take the induced distribution and make it the model:

\[ \Omega = \mathbb{R}, \qquad P = \mathcal{N}(\mu, \sigma^2), \qquad X(\omega) = \omega . \]

Sample space the real line, probability the Gaussian itself, random variable the identity function — the outcome is the number. This is the canonical probability space, and it is what is silently in play whenever a textbook says “let \(X \sim \mathcal{N}(0,1)\)” and never mentions an experiment.

The shortcut is legitimate because every probability statement about the value of \(T\) depends only on the induced distribution, and the canonical space reproduces that distribution exactly. It costs you nothing as long as you want statements about one variable’s value. It costs you something the moment you want two variables to live on the same outcome — then you need a sample space rich enough to carry both, which is the subject of the next section.

Expectation

The expectation of a random variable is the probability-weighted average of its values,

\[ \mathbb{E}[X] = \sum_x x\, p(x) \qquad\text{or}\qquad \mathbb{E}[X] = \int x\, f(x)\, dx , \]

the center of mass of the distribution. The expectation need not be an attainable value; a fair die has \(\mathbb{E}[X] = 3.5\). More generally, for a function \(g\),

\[ \mathbb{E}[g(X)] = \sum_x g(x)\, p(x) \qquad\text{or}\qquad \int g(x)\, f(x)\, dx , \]

so that the distribution of \(g(X)\) itself need never be computed (a fact sometimes called the law of the unconscious statistician).

Two properties carry most of the weight in this course.

  • Linearity. \(\mathbb{E}[aX + bY] = a\,\mathbb{E}[X] + b\,\mathbb{E}[Y]\) holds for all random variables on a common sample space, with no independence assumption. (Independence is required for the separate statement \(\mathbb{E}[XY] = \mathbb{E}[X]\,\mathbb{E}[Y]\).)
  • Variance. \(\operatorname{Var}(X) = \mathbb{E}\big[(X - \mathbb{E}X)^2\big] = \mathbb{E}[X^2] - (\mathbb{E}X)^2\) measures spread about the mean, and for independent random variables variances add. The identity \(\operatorname{Var}(x_0 + \sigma z) = 1 + \sigma^2\) of W01 is an instance.

Finally, the conditional expectation \(\mathbb{E}[X \mid Y = y]\) is the mean of the conditional distribution of \(X\) given \(Y = y\), regarded as a function of \(y\). It is the minimum-mean-squared-error prediction of \(X\) from the observation \(Y = y\) (proved in Distributions and Maximum Likelihood), and the denoiser \(\mathbb{E}[x_0 \mid x_\sigma]\) of W01 is precisely a conditional expectation.

The four objects, in one table

Object Form What it does Common misreading
Sample space \(\Omega\) a set lists every way the experiment could turn out that it must be numbers
Event \(A\) \(A \subseteq \Omega\) a yes/no question about the outcome that only one can occur
Probability \(P\) \(P(A) \in [0,1]\) assigns probability to events that it applies to outcomes
Random variable \(X\) \(X : \Omega \to \mathbb{R}\) assigns a number to outcomes that it applies to events

The two maps point at different arguments, and that is the whole distinction: probabilities attach to events, numbers attach to outcomes. A distribution is what you get by combining them — push \(P\) through \(X\) and read off the result on the real line.

Correspondence with this course

Object Where it appears in this course
Sample space \(\Omega\), outcome \(\omega\) the randomness underlying every “sample”
\(P\): events \(\to [0,1]\) the data distribution \(p_{\text{data}}\)
Random variable \(X: \Omega \to \mathbb{R}\) data \(x\), noise \(\varepsilon\), latent \(z\)
pmf / pdf every curve in the Distribution Playground
Joint \(p(x, z)\) mixture model: latent variable and observation
Marginalization \(\sum_z p(x, z)\) the mixture density; later, the ELBO (M3)
Conditioning and Bayes’ rule posteriors; the tanh denoiser of W01
Independence i.i.d. data; likelihoods factorize
\(\mathbb{E}\), linearity, variance losses, noise accumulation, \(1 + \sigma^2\)
\(\mathbb{E}[X \mid Y]\) the denoiser — the central object of the course

Exercises

  1. For two fair coin tosses with \(X\) the number of heads: write out \(\Omega\), the values \(X(\omega)\) for all four outcomes, and the pmf of \(X\); verify that the pmf sums to 1 using the additivity axiom.
  2. Exhibit (a) a pdf exceeding 3 at some point; (b) a random variable whose expectation is not an attainable value; (c) two dependent random variables for which \(\mathbb{E}[X + Y] = \mathbb{E}[X] + \mathbb{E}[Y]\) nevertheless holds, illustrating that linearity requires no independence.
  3. Let \(U \sim \text{Uniform}(0,1)\) and \(X = U^2\). Compute \(\mathbb{E}[X]\) twice: directly via \(\mathbb{E}[g(U)]\), and by first deriving the CDF and pdf of \(X\). Compare the effort required.