Session 9: Conditional Expectation

Movement III: Two Random Variables

EE 520: Random Processes (Fall 2026). Instructor: John Lipor.

Launch

Session 3 turned beliefs into actions when the actions were discrete: search here or there. Today the action is a number. A posterior distribution over the target’s range is a whole curve; the operator wants one figure, “your best guess of the range.” What single number should a posterior become? This session answers it. The best guess of XX from an observation YY turns out to be the conditional expectation 𝔼[X|Y]\mathbb{E}[X \,|\,Y], and, crucially, it is itself a random variable, a function of the data. That is exactly what an estimator is, so this session builds the first genuine estimator of the course.

Development

From a number to a random variable

Fix a value yy. The conditional density (or PMF) fX|Y(⋅|y)f_{X \,|\,Y}(\cdot \,|\,y) is a genuine distribution, so it has an expectation like any other:

Definition 1 (Conditional expectation given a value). 𝔼[X|Y=y]=∫xfX|Y(x|y)dx(sum, in the discrete case).\begin{equation} \mathbb{E}[X \,|\,Y = y] = \int x\, f_{X \,|\,Y}(x \,|\,y)\, dx \qquad\text{(sum, in the discrete case).} \end{equation}

This is one number for each yy: the mean of the posterior over XX once we know Y=yY = y. Take the 2×22 \times 2 detection table of Session 8 (prior ℙ(θ=1)=0.25\mathbb{P}(\theta = 1) = 0.25, PD=0.9P_D = 0.9, PFA=0.15P_{FA} = 0.15). Because θ\theta is an indicator, its conditional expectation is just a conditional probability: 𝔼[θ|Y=1]=ℙ(θ=1|Y=1)=23,𝔼[θ|Y=0]=ℙ(θ=1|Y=0)=253≈0.038.\begin{equation} \mathbb{E}[\theta \,|\,Y = 1] = \mathbb{P}(\theta = 1 \,|\,Y = 1) = \frac{2}{3}, \qquad \mathbb{E}[\theta \,|\,Y = 0] = \mathbb{P}(\theta = 1 \,|\,Y = 0) = \frac{2}{53} \approx 0.038 . \end{equation} So the map y↦𝔼[θ|Y=y]y \mapsto \mathbb{E}[\theta \,|\,Y = y] takes exactly two values, one for each possible reading.

Here is the step that trips up nearly everyone. Collect those per-value answers into a single object that reads YY and returns the matching number:

Two objects, one symbol, and keeping them straight is the whole battle: 𝔼[X|Y=y]\mathbb{E}[X \,|\,Y = y] is a number (you have plugged in a value), while 𝔼[X|Y]\mathbb{E}[X \,|\,Y] is a random variable (you have not).

The tower property

The single most useful identity about conditional expectation says that averaging the conditional guesses recovers the plain average.

Theorem 1 (Tower property). For any random variables XX and YY with 𝔼|X|<∞\mathbb{E}\left\lvert X \right\rvert < \infty, 𝔼[𝔼[X|Y]]=𝔼[X].\begin{equation} \mathbb{E}\left[\mathbb{E}[X \,|\,Y]\right] = \mathbb{E}[X]. \end{equation}

Proof. Take X,YX, Y discrete (the continuous proof is identical with integrals in place of sums). By definition and then regrouping the double sum, 𝔼[𝔼[X|Y]]=∑y𝔼[X|Y=y]pY(y)=∑y(∑xxpX|Y(x|y))pY(y)=∑xx∑ypX|Y(x|y)pY(y)=∑xx∑ypXY(x,y)=∑xxpX(x)=𝔼[X],\begin{align} \mathbb{E}\left[\mathbb{E}[X \,|\,Y]\right] &= \sum_y \mathbb{E}[X \,|\,Y = y]\, p_Y(y) = \sum_y \left(\sum_x x\, p_{X \,|\,Y}(x \,|\,y)\right) p_Y(y) \\ &= \sum_x x \sum_y p_{X \,|\,Y}(x \,|\,y)\, p_Y(y) = \sum_x x \sum_y p_{XY}(x, y) = \sum_x x\, p_X(x) = \mathbb{E}[X], \end{align} using pX|Y(x|y)pY(y)=pXY(x,y)p_{X \,|\,Y}(x \,|\,y)\, p_Y(y) = p_{XY}(x, y) (the chain rule) and then summing out yy to recover the marginal pXp_X. ◻

The outer expectation is over YY: we average the conditional guess g(Y)g(Y) across all the readings YY might produce, weighted by how likely each is. This is the computational workhorse of the movement, and it powers both proofs below.

Law of total variance

Conditioning also splits variance into two honest pieces.

Proposition 1 (Law of total variance). var⁡(X)=𝔼Y[var(X|Y)]+var⁡Y(𝔼[X|Y]).\begin{equation} \operatorname{var}(X) = \mathbb{E}_Y\left[\operatorname{var}(X \,|\,Y)\right] + \operatorname{var}_Y\left(\mathbb{E}[X \,|\,Y]\right). \end{equation}

Proof. Write var⁡(X|Y)=𝔼[X2|Y]−𝔼[X|Y]2\operatorname{var}(X \,|\,Y) = \mathbb{E}[X^2 \,|\,Y] - \mathbb{E}[X \,|\,Y]^2 and take expectations, using the tower property on each term: 𝔼Y[var(X|Y)]=𝔼[X2]−𝔼Y[𝔼[X|Y]2].\begin{equation} \mathbb{E}_Y\left[\operatorname{var}(X \,|\,Y)\right] = \mathbb{E}[X^2] - \mathbb{E}_Y\left[\mathbb{E}[X \,|\,Y]^2\right]. \end{equation} Meanwhile, since 𝔼Y[𝔼[X|Y]]=𝔼[X]\mathbb{E}_Y\left[\mathbb{E}[X \,|\,Y]\right] = \mathbb{E}[X] by the tower property, var⁡Y(𝔼[X|Y])=𝔼Y[𝔼[X|Y]2]−𝔼[X]2.\begin{equation} \operatorname{var}_Y\left(\mathbb{E}[X \,|\,Y]\right) = \mathbb{E}_Y\left[\mathbb{E}[X \,|\,Y]^2\right] - \mathbb{E}[X]^2 . \end{equation} Adding the two lines, the middle terms cancel and var⁡(X)=𝔼[X2]−𝔼[X]2\operatorname{var}(X) = \mathbb{E}[X^2] - \mathbb{E}[X]^2 remains. ◻

The two terms have clean readings, and both outer operations are over YY. 𝔼Y[var⁡(X|Y)]\mathbb{E}_Y[\operatorname{var}(X \,|\,Y)] is the unexplained scatter, the variance still left inside XX once YY is known, averaged over YY. var⁡Y(𝔼[X|Y])\operatorname{var}_Y(\mathbb{E}[X \,|\,Y]) is the explained variation, how much the best guess itself moves as YY varies. Since the two terms sum to the fixed total var⁡(X)\operatorname{var}(X), an observation cannot remove uncertainty, only reassign it: a useful YY is one that shifts variance out of the first term and into the second.

Why the conditional mean is the best guess

Call 𝔼[(X−g(Y))2]\mathbb{E}[(X - g(Y))^2] the mean squared error of the guess g(Y)g(Y). Among all functions gg, one is unbeatable.

Theorem 2 (MMSE property). The mean squared prediction error 𝔼[(X−g(Y))2]\mathbb{E}[(X - g(Y))^2] is minimized over all functions gg by g(Y)=𝔼[X|Y]g(Y) = \mathbb{E}[X \,|\,Y].

Proof. Add and subtract 𝔼[X|Y]\mathbb{E}[X \,|\,Y] and expand: 𝔼[(X−g(Y))2]=𝔼[((X−𝔼[X|Y])+(𝔼[X|Y]−g(Y)))2]=𝔼[(X−𝔼[X|Y])2]+𝔼[(𝔼[X|Y]−g(Y))2]+2C,\begin{align} \mathbb{E}\left[(X - g(Y))^2\right] &= \mathbb{E}\left[\left(\big(X - \mathbb{E}[X \,|\,Y]\big) + \big(\mathbb{E}[X \,|\,Y] - g(Y)\big)\right)^2\right] \\ &= \mathbb{E}\left[\big(X - \mathbb{E}[X \,|\,Y]\big)^2\right] + \mathbb{E}\left[\big(\mathbb{E}[X \,|\,Y] - g(Y)\big)^2\right] + 2\, C, \end{align} where the cross term is C=𝔼[(X−𝔼[X|Y])h(Y)]C = \mathbb{E}\left[\big(X - \mathbb{E}[X \,|\,Y]\big)\, h(Y)\right] with h(Y)=𝔼[X|Y]−g(Y)h(Y) = \mathbb{E}[X \,|\,Y] - g(Y) a function of YY. Condition on YY and use the tower property: since h(Y)h(Y) is known once YY is, C=𝔼[h(Y)𝔼[X−𝔼[X|Y]|Y]]=𝔼[h(Y)(𝔼[X|Y]−𝔼[X|Y])]=0.\begin{equation} C = \mathbb{E}\left[h(Y)\, \mathbb{E}\left[X - \mathbb{E}[X \,|\,Y] \,\big|\, Y\right]\right] = \mathbb{E}\left[h(Y)\big(\mathbb{E}[X \,|\,Y] - \mathbb{E}[X \,|\,Y]\big)\right] = 0 . \end{equation} The cross term vanishes, so 𝔼[(X−g(Y))2]=𝔼[(X−𝔼[X|Y])2]⏟does not depend on g+𝔼[(𝔼[X|Y]−g(Y))2]⏟≥0,\begin{equation} \mathbb{E}\left[(X - g(Y))^2\right] = \underbrace{\mathbb{E}\left[\big(X - \mathbb{E}[X \,|\,Y]\big)^2\right]}_{\text{does not depend on } g} + \underbrace{\mathbb{E}\left[\big(\mathbb{E}[X \,|\,Y] - g(Y)\big)^2\right]}_{\ge 0}, \end{equation} which is smallest exactly when the second term is zero, i.e. when g(Y)=𝔼[X|Y]g(Y) = \mathbb{E}[X \,|\,Y]. ◻

This is Session 2’s Bayes rule, now read as an estimator: the posterior it produces gets compressed into one number by taking its mean.

An estimate is a compression of the posterior. The posterior mean 𝔼[X|Y]\mathbb{E}[X \,|\,Y] is the answer to “what single number should I report under squared-error loss?” An estimate is a compression of the posterior, chosen for a purpose; change the purpose and you change the summary. Other loss functions select other summaries (the median under absolute error, the mode when we detect in Session 10), but throughout this course, unless we say otherwise, the estimate is the posterior mean.

Random sums: a mean for free

The tower property shines when even the number of terms is random. Suppose NN targets are present, with NN itself random, and each present target is detected independently with probability qq; let DD be the detected count. Conditioning on NN makes DD an ordinary sum of NN indicators, so 𝔼[D|N]=qN\mathbb{E}[D \,|\,N] = qN, and the tower property finishes it: 𝔼[D]=𝔼[𝔼[D|N]]=𝔼[qN]=q𝔼[N].\begin{equation} \mathbb{E}[D] = \mathbb{E}\left[\mathbb{E}[D \,|\,N]\right] = \mathbb{E}[qN] = q\,\mathbb{E}[N]. \end{equation} The mean detected count is the detection probability times the mean target count, whatever the distribution of NN. The full distribution of DD (a thinned count) is HW4; here the tower property handed us its mean with almost no work.

Remark 1 (Freezing what you condition on). The step 𝔼[D|N]=qN\mathbb{E}[D \,|\,N] = qN quietly used two moves that recur whenever XX is built from YY and other randomness ZZ. First, given Y=yY = y, the value yy may be substituted for YY inside the expectation: 𝔼[h(Y,Z)|Y=y]=𝔼[h(y,Z)|Y=y]\mathbb{E}[h(Y, Z) \,|\,Y = y] = \mathbb{E}[h(y, Z) \,|\,Y = y]. Second, if ZZ is independent of YY, conditioning no longer changes the distribution of ZZ, so the condition can be dropped: 𝔼[h(y,Z)|Y=y]=𝔼[h(y,Z)]\mathbb{E}[h(y, Z) \,|\,Y = y] = \mathbb{E}[h(y, Z)]. Here Y=NY = N, Z=(B1,B2,…)Z = (B_1, B_2, \dots), and h(n,Z)=∑i=1nBih(n, Z) = \sum_{i=1}^n B_i, which gives 𝔼[D|N=n]=qn\mathbb{E}[D \,|\,N = n] = qn. So nothing in the tower property requires XX to be unrelated to YY: XX may be any function of YY and other random variables, and conditioning on YY freezes YY while leaving the rest random. Without independence the second move fails, and the conditional distribution of ZZ given Y=yY = y must be used instead.

Worked examples

(a) Regression on the ranging triangle

Return to Session 8’s uniform pair on T={0≤y≤2x,0≤x≤1}T = \{0 \le y \le 2x,\ 0 \le x \le 1\} (the range XX and the error magnitude YY). There the model’s conditional density was fY|X(y|x)=1/(2x)f_{Y \,|\,X}(y \,|\,x) = 1/(2x) on (0,2x)(0, 2x): given the range, the error is uniform up to twice the range. The mean of a uniform on (0,2x)(0, 2x) is its midpoint, so 𝔼[Y|X=x]=x.\begin{equation} \mathbb{E}[Y \,|\,X = x] = x . \end{equation} The best guess of the error equals the range: a regression line through the origin with slope 11 (Figure 1). Notice it is a genuine function of the data XX, exactly the promotion above.

The regression function 𝔼[Y|X=x]=x\mathbb{E}[Y \,|\,X = x] = x (dashed) is the midline of the support triangle: given X=xX = x, YY is uniform on (0,2x)(0, 2x), whose mean is xx.

Now verify the tower property 𝔼[𝔼[Y|X]]=𝔼[Y]\mathbb{E}[\mathbb{E}[Y \,|\,X]] = \mathbb{E}[Y] two ways. Averaging the conditional guess against the marginal fX(x)=2xf_X(x) = 2x, 𝔼[𝔼[Y|X]]=𝔼[X]=∫01x⋅2xdx=23.\begin{equation} \mathbb{E}\left[\mathbb{E}[Y \,|\,X]\right] = \mathbb{E}[X] = \int_0^1 x \cdot 2x\, dx = \frac{2}{3}. \end{equation} Computing 𝔼[Y]\mathbb{E}[Y] directly against the marginal fY(y)=∫y/211dx=1−y/2f_Y(y) = \int_{y/2}^{1} 1\, dx = 1 - y/2 on (0,2)(0, 2) (the slice at height yy runs from the edge x=y/2x = y/2 to x=1x = 1), 𝔼[Y]=∫02y(1−y2)dy=[y22−y36]02=2−43=23.✓\begin{equation} \mathbb{E}[Y] = \int_0^2 y\left(1 - \frac{y}{2}\right)\, dy = \left[\frac{y^2}{2} - \frac{y^3}{6}\right]_0^2 = 2 - \frac{4}{3} = \frac{2}{3}. \checkmark \end{equation} Both routes give 2/32/3: the roundabout tower computation and the direct one agree, as they must.

(b) The detection table, and a bridge between movements

For the 2×22 \times 2 table, the conditional expectations computed above, 𝔼[θ|Y=1]=2/3\mathbb{E}[\theta \,|\,Y = 1] = 2/3 and 𝔼[θ|Y=0]=2/53\mathbb{E}[\theta \,|\,Y = 0] = 2/53, are literally the posterior probabilities ℙ(θ=1|Y)\mathbb{P}(\theta = 1 \,|\,Y) of Session 2. The reason is that θ\theta is an indicator, and the expectation of an indicator is the probability of the event it flags. As a check, the tower property returns the prior: 23⋅2780+253⋅5380=14\tfrac{2}{3}\cdot\tfrac{27}{80} + \tfrac{2}{53}\cdot\tfrac{53}{80} = \tfrac{1}{4}, the marginal 𝔼[θ]=ℙ(θ=1)\mathbb{E}[\theta] = \mathbb{P}(\theta = 1).

Movements I and III meet. For an indicator θ\theta, “posterior probability” (Movement I) and “conditional expectation” (Movement III) are the same number. Detection was never a separate subject: it is conditional expectation of a 0/10/1 quantity, which is why Session 10 will need nothing new to decide present versus absent.

(c) How many floors does the elevator stop at?

A building has nn floors. M∼Poisson(10)M \sim \text{Poisson}(10) people board at floor 1, and each rider, independently of the others and of MM, exits at one of the floors 2,…,n2, \dots, n, all equally likely. On average, at how many floors does the elevator stop to let someone off?

The tempting route is to find the distribution of the number of stops SS first. That is genuinely messy: whether the elevator stops at floor 3 and whether it stops at floor 4 are dependent events, since the floors compete for the same MM riders. The mean does not need the distribution. Write SS as a sum of indicators, S=∑j=2nIj,Ij=𝟙{someone exits at floor j},\begin{equation} S = \sum_{j=2}^{n} I_j, \qquad I_j = \mathbb{1}\left\{\text{someone exits at floor } j\right\}, \end{equation} and use linearity of expectation, which holds whether or not the IjI_j are independent. The expectation of an indicator is a probability (example (b)), and by symmetry every floor has the same one, so 𝔼[S]=∑j=2nℙ(someone exits at floor j)=(n−1)(1−ℙ(nobody exits at floor j)).\begin{equation} \mathbb{E}[S] = \sum_{j=2}^{n} \mathbb{P}(\text{someone exits at floor } j) = (n - 1)\left(1 - \mathbb{P}(\text{nobody exits at floor } j)\right) . \end{equation} To find ℙ(nobody exits at floor j)\mathbb{P}(\text{nobody exits at floor } j), condition on MM and use the tower property. Given M=mM = m, freeze MM at mm; the riders’ floor choices are independent of MM, so the condition drops (Remark 1), and each of the mm riders independently avoids floor jj with probability r=1−1n−1r = 1 - \frac{1}{n - 1}: ℙ(nobody exits at floor j|M=m)=rm.\begin{equation} \mathbb{P}(\text{nobody exits at floor } j \,|\,M = m) = r^{m} . \end{equation} Averaging over the Poisson distribution of MM, the series is the exponential series: ℙ(nobody exits at floor j)=∑m=0∞e−1010mm!rm=e−10∑m=0∞(10r)mm!=e−10e10r=e−10/(n−1).\begin{equation} \mathbb{P}(\text{nobody exits at floor } j) = \sum_{m=0}^{\infty} e^{-10} \frac{10^m}{m!}\, r^{m} = e^{-10} \sum_{m=0}^{\infty} \frac{(10 r)^m}{m!} = e^{-10} e^{10 r} = e^{-10/(n - 1)} . \end{equation} Therefore 𝔼[S]=(n−1)(1−e−10/(n−1)).\begin{equation} \mathbb{E}[S] = (n - 1)\left(1 - e^{-10/(n - 1)}\right) . \end{equation} With n=11n = 11 there are ten exit floors and ten riders expected, one per floor on average, yet 𝔼[S]=10(1−e−1)≈6.32\mathbb{E}[S] = 10\left(1 - e^{-1}\right) \approx 6.32: riders clump, so the elevator skips more than a third of the floors. Two sanity checks at the extremes. With a single exit floor (n=2n = 2), 𝔼[S]=1−e−10=ℙ(M≥1)\mathbb{E}[S] = 1 - e^{-10} = \mathbb{P}(M \ge 1), as it must be. With very many floors, (n−1)(1−e−10/(n−1))→10(n - 1)\left(1 - e^{-10/(n-1)}\right) \to 10: riders almost never share a floor, so every rider is a stop and 𝔼[S]→𝔼[M]\mathbb{E}[S] \to \mathbb{E}[M].

(d) Choosing by noisy utility: Gumbel noise and the softmax

A commuter chooses among nn routes. Each route jj has a systematic appeal VjV_j that an analyst could estimate from travel time and cost, plus an idiosyncratic part (mood, weather, a podcast that runs long) that the analyst cannot see. Model the commuter’s utility for route jj as Uj=Vj+Gj,G1,…,Gn independent standard Gumbel,\begin{equation} U_j = V_j + G_j, \qquad G_1, \dots, G_n \text{ independent standard Gumbel}, \end{equation} and assume the commuter takes the route with the largest utility. The analyst sees only the choice. What is the probability that route jj is chosen?

Theorem 3 (Gumbel-max). Under this model, for each jj, ℙ(Uj>Uk for all k≠j)=eVj∑k=1neVk.\begin{equation} \label{eq:softmax} \mathbb{P}\!\left(U_j > U_k \text{ for all } k \ne j\right) = \frac{e^{V_j}}{\sum_{k=1}^n e^{V_k}}. \end{equation}

The right side is the softmax of (V1,…,Vn)(V_1, \dots, V_n). The proof reduces an nn-way race to a two-way race, and the two-way race is a tower-property computation on an indicator, the move of examples (b) and (c).

Lemma 1 (Two-way race). If A∼Gumbel(a)A \sim \mathrm{Gumbel}(a) and B∼Gumbel(b)B \sim \mathrm{Gumbel}(b) are independent, then ℙ(A>B)=ea/(ea+eb)\mathbb{P}(A > B) = e^{a} / (e^{a} + e^{b}).

Proof. Write fAf_A for the density of AA and FBF_B for the CDF of BB. The probability of an event is the expectation of its indicator, so by the tower property ℙ(B<A)=𝔼[𝟙{B<A}]=𝔼[𝔼[𝟙{B<A}|A]].\begin{equation} \mathbb{P}(B < A) = \mathbb{E}\left[\mathbb{1}\left\{B < A\right\}\right] = \mathbb{E}\left[\mathbb{E}\left[\mathbb{1}\left\{B < A\right\} \,|\,A\right]\right]. \end{equation} In the tower property’s terms, the variable being averaged is 𝟙{B<A}\mathbb{1}\left\{B < A\right\}, which depends on both AA and BB, and the variable conditioned on is AA. Given A=xA = x, freeze AA at xx; then, since BB is independent of AA, drop the condition (Remark 1): 𝔼[𝟙{B<A}|A=x]=𝔼[𝟙{B<x}|A=x]=ℙ(B<x)=FB(x).\begin{equation} \mathbb{E}\left[\mathbb{1}\left\{B < A\right\} \,|\,A = x\right] = \mathbb{E}\left[\mathbb{1}\left\{B < x\right\} \,|\,A = x\right] = \mathbb{P}(B < x) = F_B(x). \end{equation} Averaging over AA, ℙ(B<A)=∫−∞∞fA(x)FB(x)dx,\begin{equation} \mathbb{P}(B < A) = \int_{-\infty}^{\infty} f_A(x) F_B(x)\, dx, \end{equation} which is also what Session 8’s iterated integral of the product density fA(x)fB(y)f_A(x) f_B(y) over {y<x}\left\{y < x\right\} gives. Insert the Gumbel density and CDF and collect the double exponentials: ℙ(B<A)=∫−∞∞e−(x−a)exp⁡(−e−(x−a))exp⁡(−e−(x−b))dx=ea∫−∞∞e−xexp⁡(−e−x(ea+eb))dx.\begin{equation} \begin{split} \mathbb{P}(B < A) &= \int_{-\infty}^{\infty} e^{-(x - a)} \exp\!\left(-e^{-(x - a)}\right) \exp\!\left(-e^{-(x - b)}\right)\, dx \\ &= e^{a} \int_{-\infty}^{\infty} e^{-x} \exp\!\left(-e^{-x}\left(e^{a} + e^{b}\right)\right)\, dx. \end{split} \end{equation} Substitute s=e−xs = e^{-x}, so ds=−e−xdxds = -e^{-x}\, dx, and xx running from −∞-\infty to ∞\infty sends ss from ∞\infty down to 00: ℙ(B<A)=ea∫0∞e−s(ea+eb)ds=eaea+eb.\begin{equation} \mathbb{P}(B < A) = e^{a} \int_0^{\infty} e^{-s (e^{a} + e^{b})}\, ds = \frac{e^{a}}{e^{a} + e^{b}}. \end{equation} Because AA and BB are continuous, ℙ(A=B)=0\mathbb{P}(A = B) = 0, so ℙ(A>B)=ℙ(B<A)\mathbb{P}(A > B) = \mathbb{P}(B < A). ◻

Proof of Theorem 3. Route jj wins exactly when Uj>M−jU_j > M_{-j}, where M−j=max⁡k≠jUkM_{-j} = \max_{k \ne j} U_k is the best of the other routes. Each Uk=Vk+GkU_k = V_k + G_k is Gumbel(Vk)\mathrm{Gumbel}(V_k), so by Session 6’s max-stability proposition, M−j∼Gumbel(L−j)M_{-j} \sim \mathrm{Gumbel}(L_{-j}) with eL−j=∑k≠jeVke^{L_{-j}} = \sum_{k \ne j} e^{V_k}. And M−jM_{-j} is independent of UjU_j, because it is a function of GkG_k, k≠jk \ne j, only. Lemma 1 with a=Vja = V_j and b=L−jb = L_{-j} gives ℙ(Uj>M−j)=eVjeVj+∑k≠jeVk=eVj∑k=1neVk.\begin{equation} \mathbb{P}(U_j > M_{-j}) = \frac{e^{V_j}}{e^{V_j} + \sum_{k \ne j} e^{V_k}} = \frac{e^{V_j}}{\sum_{k=1}^n e^{V_k}}. \end{equation} This is the softmax, as claimed. ◻

Three routes. Take V=(0,1,2)V = (0, 1, 2). Route 3 faces the best of routes 1 and 2, which by max-stability is Gumbel(ln⁡(1+e))=Gumbel(1.313)\mathrm{Gumbel}(\ln(1 + e)) = \mathrm{Gumbel}(1.313): a soft maximum a little above route 2’s V2=1V_2 = 1. Route 3 wins that race with probability e2/(1+e+e2)≈0.665e^2 / (1 + e + e^2) \approx 0.665, and the full choice pmf is (0.090,0.245,0.665)(0.090, 0.245, 0.665). A Monte Carlo run of 10610^6 simulated commuters reproduces these to three decimals.

Two routes. With n=2n = 2, dividing through by eV1e^{V_1}, ℙ(U1>U2)=11+e−(V1−V2),\begin{equation} \mathbb{P}(U_1 > U_2) = \frac{1}{1 + e^{-(V_1 - V_2)}}, \end{equation} the logistic function of the difference in appeal. For pairwise comparisons this is the Bradley–Terry model, which is the probability model underneath Elo ratings in chess: a gap of one unit of appeal gives the stronger side a win probability of 0.7310.731. If you worked Homework 3 Problem 6, you have already met this two-route case from the other direction: there G1−G2G_1 - G_2 came out logistic from a wedge integral over two exponentials, and the hard switch was on with probability eμ/(1+eμ)e^{\mu}/(1 + e^{\mu}), which is this formula with V1−V2=μV_1 - V_2 = \mu.

Softmax is an argmax under noise. The softmax is not an arbitrary way to turn scores into probabilities. It is exactly the distribution of the winner when each score receives independent Gumbel noise and the largest noisy score wins. This random-utility reading is the foundation of discrete-choice modeling in economics (McFadden, Nobel 2000), and it is also the softmax in machine learning.

Back to Session 7’s token sampler. Take scores Vi=zi/TV_i = z_i / T for logits ziz_i and temperature TT. By the theorem, arg max⁡i(zi/T+Gi)\operatorname*{arg\,max}_i \left(z_i/T + G_i\right) has exactly the temperature pmf pi(T)∝exp⁡(zi/T)p_i(T) \propto \exp(z_i/T) of Session 7’s AI corner. Multiplying inside the argmax by T>0T > 0 does not change the winner, so the same draw is arg max⁡i(zi+TGi)\operatorname*{arg\,max}_i \left(z_i + T G_i\right): temperature is the noise level. As T→0T \to 0 the noise vanishes and the argmax becomes greedy decoding; as TT grows the noise swamps the logits and every token becomes nearly equally likely. This Gumbel-max trick draws a sample without ever computing the normalizing sum ∑kezk/T\sum_k e^{z_k/T}, using one Gi=−ln⁡(−ln⁡Ui)G_i = -\ln(-\ln U_i) per token from Session 7’s Gumbel sampler.

Pitfall. Only differences of the VjV_j matter. Adding the same constant cc to every VjV_j multiplies the numerator and the denominator of [eq:softmax] by ece^{c} and changes no choice probability. So a single appeal such as “V3=2V_3 = 2” carries no meaning on its own, and an analyst who estimates appeals from choices must fix one of them (say V1=0V_1 = 0) before the others are determined.

Consolidation

Work these in class.

  1. (Mechanical: conditional expectation and the tower check.) A pair (X,Y)(X, Y) with X∈{0,1}X \in \{0, 1\}, Y∈{1,2}Y \in \{1, 2\} has joint PMF p(0,1)=0.3p(0,1) = 0.3, p(1,1)=0.1p(1,1) = 0.1, p(0,2)=0.2p(0,2) = 0.2, p(1,2)=0.4p(1,2) = 0.4. Find 𝔼[X|Y=1]\mathbb{E}[X \,|\,Y = 1] and 𝔼[X|Y=2]\mathbb{E}[X \,|\,Y = 2], then confirm the tower property gives 𝔼[X]\mathbb{E}[X].
    Answer: column totals pY(1)=0.4p_Y(1) = 0.4, pY(2)=0.6p_Y(2) = 0.6, so 𝔼[X|Y=1]=0.1/0.4=1/4\mathbb{E}[X \,|\,Y = 1] = 0.1/0.4 = 1/4 and 𝔼[X|Y=2]=0.4/0.6=2/3\mathbb{E}[X \,|\,Y = 2] = 0.4/0.6 = 2/3. Tower: 0.4⋅14+0.6⋅23=0.1+0.4=0.5=ℙ(X=1)=𝔼[X]0.4 \cdot \tfrac14 + 0.6 \cdot \tfrac23 = 0.1 + 0.4 = 0.5 = \mathbb{P}(X = 1) = \mathbb{E}[X].

  2. (Conceptual: does conditioning reduce variance?) A classmate says “knowing YY always shrinks the variance of XX.” Correct the statement.
    Answer: Only on average. The law of total variance gives 𝔼Y[var⁡(X|Y)]=var⁡(X)−var⁡Y(𝔼[X|Y])≤var⁡(X)\mathbb{E}_Y[\operatorname{var}(X \,|\,Y)] = \operatorname{var}(X) - \operatorname{var}_Y(\mathbb{E}[X \,|\,Y]) \le \operatorname{var}(X), so the average conditional variance cannot exceed var⁡(X)\operatorname{var}(X); but a particular var⁡(X|Y=y)\operatorname{var}(X \,|\,Y = y) can be larger than var⁡(X)\operatorname{var}(X) (an unusual reading can leave you more uncertain, not less).

Synthesis

The course thesis asks how observation should change belief and action. When the action is a number, the best it can be under squared error is the conditional expectation 𝔼[X|Y]\mathbb{E}[X \,|\,Y], the mean of the posterior. The hardest idea was that this best guess is a random variable, a function of the data, which is what makes it an estimator rather than a static answer. The tower property let us average conditional guesses back to the unconditional mean and, through the add-and-subtract argument, certified 𝔼[X|Y]\mathbb{E}[X \,|\,Y] as the minimizer of mean squared error; the law of total variance split uncertainty into what an observation explains and what it leaves behind. Writing a count as a sum of indicators and conditioning on the random number of riders gave the elevator’s expected stops without ever finding their distribution. Applied to an indicator, the tower property also showed that adding independent Gumbel noise to a set of scores and taking the argmax produces exactly the softmax, the probability model behind discrete choice and behind sampling from a language model. Reading an estimate as a compression of the posterior chosen for a purpose is the throughline into the estimation half of the course. Next session specializes all of this to a 0/10/1 target: detection is conditional expectation of an indicator, compared to a threshold, and Session 2’s likelihood ratio returns as the decision statistic.

Self-check questions

  1. Is 𝔼[X|Y]\mathbb{E}[X \,|\,Y] a number or a random variable, and why does the distinction matter?
    Answer: A random variable, the function g(Y)g(Y) with g(y)=𝔼[X|Y=y]g(y) = \mathbb{E}[X \,|\,Y = y]. It matters because an estimator must be a function of the data; 𝔼[X|Y=y]\mathbb{E}[X \,|\,Y = y] (a specific reading plugged in) is the number, 𝔼[X|Y]\mathbb{E}[X \,|\,Y] is the rule.

  2. State the tower property and use it in one line to find 𝔼[D]\mathbb{E}[D] when D=∑i=1NBiD = \sum_{i=1}^N B_i with the BiB_i independent Bernoulli(q)(q) and NN random.
    Answer: 𝔼[𝔼[X|Y]]=𝔼[X]\mathbb{E}[\mathbb{E}[X \,|\,Y]] = \mathbb{E}[X]. Here 𝔼[D]=𝔼[𝔼[D|N]]=𝔼[qN]=q𝔼[N]\mathbb{E}[D] = \mathbb{E}[\mathbb{E}[D \,|\,N]] = \mathbb{E}[qN] = q\,\mathbb{E}[N].

  3. Why is the posterior mean, and not the whole posterior, what we usually report, and when might that be the wrong choice?
    Answer: Under squared-error loss the posterior mean is the optimal single-number summary (the MMSE property), a useful compression of the full posterior. It is the wrong choice when the loss is different: absolute error wants the median, and a detect/no-detect decision wants the mode (Session 10).