Skip to content

13.10 Probability problem set, part b: joint distributions, covariance, MLE

Once a system has text, it turns counts into probabilities everywhere. MLE, Laplace, absolute discounting estimates a categorical distribution from token counts and smooths it so unseen words keep some mass. The Unigram language model tokenizer in AI Engineering trains a tokenizer whose training data never says which segmentation produced a word, so it re-estimates piece probabilities from expected counts, again and again: that is EM. The statistical language models of n-gram language model with interpolated modified Kneser-Ney are tables of conditional distributions over pairs of tokens, which is a joint distribution read one row at a time. And when you evaluate, per-token losses on one document are correlated, so the variance of their mean is not σ2/n\sigma^2/n.

Concepts from other sections (8)

This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.

This problem set covers the tools behind all of that: joint and conditional distributions, covariance, and maximum likelihood, including one EM step of the kind the Unigram trainer runs. It is a pen-and-paper set with 15 exact answers (counting lettered parts) and one proof. A short review and two examples by hand come first; then the problems, each followed by a collapsed worked answer with the final result, the derivation, and the common wrong answers and why they are wrong. Try each problem before opening its answer. Read it alongside MLE, Laplace, absolute discounting and before the Unigram tokenizer; problem set C follows the limit-theorems section.

The set builds on problem set A (axioms, conditioning, expectation, and variance of one variable) and on the joint-distribution and estimation material in the chapter opening.

Learning objectives

  • Read marginals, conditionals, and independence off a joint table.
  • Compute covariance and use it in the variance of a linear combination, and explain why zero covariance is not independence.
  • Derive maximum-likelihood estimates for Bernoulli, exponential, and categorical models, and apply Laplace smoothing.
  • Run one EM step by hand: expected counts from posteriors, then the categorical MLE.
  • Prove that count over total maximizes the categorical log-likelihood.

The set uses these symbols.

SymbolMeaningType / shape
pX,Y(x,y)p_{X,Y}(x, y)joint mass function, P(X=x,Y=y)P(X = x, Y = y)real
pX(x)=∑ypX,Y(x,y)p_X(x) = \sum_y p_{X,Y}(x, y)marginal of XXreal
P(X=x∣Y=y)P(X = x \mid Y = y)conditional, pX,Y(x,y)/pY(y)p_{X,Y}(x, y) / p_Y(y) for pY(y)>0p_Y(y) > 0real
Cov⁡(X,Y)\operatorname{Cov}(X, Y)covariance, E[(X−EX)(Y−EY)]=E[XY]−E[X]E[Y]E[(X - E X)(Y - E Y)] = E[XY] - E[X]E[Y]real
σX2\sigma_X^2 (vx)variance of XX, Cov⁡(X,X)\operatorname{Cov}(X, X)real
ρ\rhocorrelation, Cov⁡(X,Y)/(σXσY)\operatorname{Cov}(X, Y) / (\sigma_X \sigma_Y)real in [−1,1][-1, 1]
θ\thetathe parameter of a model, pθp_\thetareal or vector
L(θ)L(\theta), ℓ(θ)\ell(\theta)likelihood ∏ipθ(xi)\prod_i p_\theta(x_i) and log-likelihood ∑iln⁡pθ(xi)\sum_i \ln p_\theta(x_i)real
θ^\hat\thetathe maximum-likelihood estimate, arg⁡max⁡θℓ(θ)\arg\max_\theta \ell(\theta)real or vector
ckc_k, NN, VVcount of outcome kk, total count, vocabulary sizeintegers

Two discrete random variables on the same outcome have a joint mass function pX,Yp_{X,Y}, a table that sums to 1. Summing a row gives the marginal of one variable; dividing a cell by its column sum gives the conditional of the row variable given the column. XX and YY are independent when pX,Y(x,y)=pX(x) pY(y)p_{X,Y}(x, y) = p_X(x)\,p_Y(y) for every cell, so one cell that fails is enough to refute it. A bigram model is exactly a table of conditionals P(next∣current)P(\text{next} \mid \text{current}).

Cov⁡(X,Y)=E[XY]−E[X]E[Y]\operatorname{Cov}(X, Y) = E[XY] - E[X]E[Y] is positive when the variables tend to be large together and negative when one is large while the other is small. Expanding the square of aX+bY−E[aX+bY]aX + bY - E[aX + bY] gives Var⁡(aX+bY)=a2σX2+b2σY2+2ab Cov⁡(X,Y).\operatorname{Var}(aX + bY) = a^2 \sigma_X^2 + b^2 \sigma_Y^2 + 2ab\,\operatorname{Cov}(X, Y). Independence makes the covariance 0 (because E[XY]=E[X]E[Y]E[XY] = E[X]E[Y]), but not the other way round: covariance only sees linear dependence, and Y=X2Y = X^2 with XX symmetric around 0 is completely determined by XX yet has zero covariance with it (Problem 4). For nn losses with common variance σ2\sigma^2 and pairwise covariance cc, the variance of their mean is σ2/n+(n−1)c/n\sigma^2/n + (n - 1)c/n, which does not go to 0 when c>0c > 0: correlated evaluation tokens give wider error bars than independent ones.

Given data x1,…,xnx_1, \dots, x_n drawn independently from pθp_\theta, the likelihood L(θ)=∏ipθ(xi)L(\theta) = \prod_i p_\theta(x_i) is how probable the data is under θ\theta, and the MLE θ^\hat\theta maximizes it. Take logs first: products become sums, and ln⁡\ln is increasing, so the maximizer is the same. For a smooth one-parameter model, solve ℓ′(θ)=0\ell'(\theta) = 0 and check that it is a maximum. Three models recur.

  • Bernoulli. kk successes in nn trials: ℓ(p)=kln⁡p+(n−k)ln⁡(1−p)\ell(p) = k \ln p + (n - k)\ln(1 - p), and ℓ′(p)=0\ell'(p) = 0 at the success fraction (Problem 6).
  • Exponential. Gaps xix_i with density λe−λx\lambda e^{-\lambda x}: ℓ(λ)=nln⁡λ−λ∑ixi\ell(\lambda) = n \ln \lambda - \lambda \sum_i x_i (Problem 7).
  • Categorical. Counts ckc_k: ℓ(p)=∑kckln⁡pk\ell(p) = \sum_k c_k \ln p_k subject to ∑kpk=1\sum_k p_k = 1; the maximizer is pk=ck/Np_k = c_k / N (Problem 9 is the proof). An outcome never seen gets probability 0, which is why the estimation section smooths: Laplace (add-one) uses (ck+1)/(N+V)(c_k + 1)/(N + V), one pseudo-count for every entry of the vocabulary, seen or not (Problem 5).

Sometimes the data that would make counting easy is hidden. A Unigram tokenizer sees the word “ab” but not whether it was produced as a+ba + b or as abab. EM replaces each count by its expected value under the current model: weight each possible segmentation by its posterior probability given the word (its probability divided by the sum over all segmentations), count the pieces in each, and add up. Then take the categorical MLE of those expected counts, count over total. Repeating never lowers the likelihood of the observed words.

These are siblings of Problems 1, 2, and 8, not problems of the set.

Joint table. Let X,Y∈{0,1}X, Y \in \{0, 1\} with P(0,0)=1/2P(0, 0) = 1/2, P(0,1)=0P(0, 1) = 0, P(1,0)=1/4P(1, 0) = 1/4, P(1,1)=1/4P(1, 1) = 1/4. The marginals are P(X=1)=1/2P(X = 1) = 1/2 and P(Y=1)=1/4P(Y = 1) = 1/4. The conditional is P(Y=1∣X=1)=(1/4)/(1/2)=1/2P(Y = 1 \mid X = 1) = (1/4)/(1/2) = 1/2. Independence fails at the cell (0,1)(0, 1): 0≠(1/2)(1/4)0 \ne (1/2)(1/4). E[XY]=1⋅1⋅1/4=1/4E[XY] = 1 \cdot 1 \cdot 1/4 = 1/4 and E[X]E[Y]=1/8E[X] E[Y] = 1/8, so Cov⁡(X,Y)=1/8>0\operatorname{Cov}(X, Y) = 1/8 > 0: YY is 1 only when XX is.

One EM step. Take a Unigram with pieces xx, yy, xyxy at probabilities 1/21/2, 1/41/4, 1/41/4, and one observed word “xy”. The segmentations are x+yx + y with probability 1/2⋅1/4=1/81/2 \cdot 1/4 = 1/8, and xyxy with 1/41/4. Their sum is 3/83/8, so the posteriors are 1/31/3 and 2/32/3. Expected counts: xx is used once in the first, so 1/31/3; yy also 1/31/3; xyxy is 2/32/3. The total is 4/34/3, and the M-step gives P(xy)=(2/3)/(4/3)=1/2P(xy) = (2/3)/(4/3) = 1/2, up from 1/41/4, and P(x)=P(y)=1/4P(x) = P(y) = 1/4. Keep it as the exact fraction 1/21/2: every answer in this set is exact.

Probabilities are exact fractions (3/83/8, not 0.375), and lettered parts are answered separately. σX2\sigma_X^2 is written vx, σY2\sigma_Y^2 is vy, the covariance is cc, and the sum of the gaps in Problem 7 is ss. The tag after each problem says what kind of answer is expected.

The first four problems work with one joint table and then with a pair of variables that are dependent but uncorrelated.

Problem 1. X∈{0,1}X \in \{0, 1\} and Y∈{0,1,2}Y \in \{0, 1, 2\} have this joint mass function P(X=x,Y=y)P(X = x, Y = y):

Y=0Y = 0Y=1Y = 1Y=2Y = 2
X=0X = 01/81/81/41/41/81/8
X=1X = 11/41/41/81/81/81/8

(a) P(Y=1)P(Y = 1). (b) P(X=1∣Y=0)P(X = 1 \mid Y = 0). [number] (c) Are XX and YY independent? [bool]

Answer

(a) 3/83/8. (b) 2/32/3. (c) No. (a) A marginal sums the joint over the other variable: P(Y=1)=1/4+1/8=3/8P(Y = 1) = 1/4 + 1/8 = 3/8. (b) A conditional renormalizes a column: P(Y=0)=1/8+1/4=3/8P(Y = 0) = 1/8 + 1/4 = 3/8, so P(X=1∣Y=0)=(1/4)/(3/8)=2/3P(X = 1 \mid Y = 0) = (1/4)/(3/8) = 2/3. (c) Independence needs every cell to factor. P(X=0)=1/8+1/4+1/8=1/2P(X = 0) = 1/8 + 1/4 + 1/8 = 1/2 and P(Y=0)=3/8P(Y = 0) = 3/8, so independence would need P(0,0)=3/16P(0, 0) = 3/16, but the table says 1/81/8; one failing cell is enough. Common mistakes: 1/41/4 for (a), reading one cell instead of the column sum; 1/41/4 for (b), the joint P(X=1,Y=0)P(X = 1, Y = 0) rather than the conditional; 1/21/2 for (b), the marginal P(X=1)P(X = 1).

Problem 2. For the same table: (a) E[XY]E[XY]. (b) Cov⁡(X,Y)\operatorname{Cov}(X, Y). [number]

Answer

(a) 3/83/8. (b) −1/16-1/16. (a) Only cells with X=1X = 1 and Y≠0Y \ne 0 contribute: E[XY]=1⋅1⋅18+1⋅2⋅18=38E[XY] = 1 \cdot 1 \cdot \frac18 + 1 \cdot 2 \cdot \frac18 = \frac38. (b) E[X]=1/2E[X] = 1/2 and E[Y]=0⋅38+1⋅38+2⋅14=78E[Y] = 0 \cdot \frac38 + 1 \cdot \frac38 + 2 \cdot \frac14 = \frac78, so Cov⁡(X,Y)=38−12⋅78=6−716=−116\operatorname{Cov}(X, Y) = \frac38 - \frac12 \cdot \frac78 = \frac{6 - 7}{16} = -\frac1{16}. The sign says YY tends to be a little smaller when X=1X = 1 (row X=1X = 1 puts its weight on Y=0Y = 0). Common mistakes: 7/167/16 for (a), which is E[X]E[Y]E[X]E[Y] and equals E[XY]E[XY] only when the covariance is zero; +1/16+1/16 for (b), the subtraction reversed; 3/83/8 for (b), E[XY]E[XY] without centering.

Problem 3. XX and YY have variances σX2\sigma_X^2 (vx) and σY2\sigma_Y^2 (vy) and covariance cc; aa and bb are constants. Give Var⁡(aX+bY)\operatorname{Var}(aX + bY). [expr in a, b, vx, vy, c]

Answer

a2σX2+b2σY2+2abca^2\sigma_X^2 + b^2\sigma_Y^2 + 2abc (a^2*vx + b^2*vy + 2*a*b*c). Let X~=X−EX\tilde X = X - E X and Y~=Y−EY\tilde Y = Y - E Y. Then Var⁡(aX+bY)=E[(aX~+bY~)2]=a2E[X~2]+2ab E[X~Y~]+b2E[Y~2]\operatorname{Var}(aX + bY) = E[(a\tilde X + b\tilde Y)^2] = a^2 E[\tilde X^2] + 2ab\,E[\tilde X\tilde Y] + b^2 E[\tilde Y^2], which is the formula. The cross term is why correlated per-token losses average down slower than independent ones. Common mistakes: dropping the covariance term (true only when c=0c = 0); a σX2+b σY2+2abca\,\sigma_X^2 + b\,\sigma_Y^2 + 2abc, forgetting that scaling a variable by aa scales its variance by a2a^2; and abcabc instead of 2abc2abc, counting the cross term once when the square has two of them.

Problem 4. XX is uniform on {−1,0,1}\{-1, 0, 1\} and Y=X2Y = X^2. (a) Cov⁡(X,Y)\operatorname{Cov}(X, Y). [number] (b) Are XX and YY independent? [bool]

Answer

(a) 00. (b) No. (a) E[X]=0E[X] = 0 by symmetry and E[XY]=E[X3]=13(−1+0+1)=0E[XY] = E[X^3] = \frac13(-1 + 0 + 1) = 0, so Cov⁡(X,Y)=0−0⋅E[Y]=0\operatorname{Cov}(X, Y) = 0 - 0 \cdot E[Y] = 0. (b) YY is a function of XX: P(X=0,Y=1)=0P(X = 0, Y = 1) = 0, while P(X=0) P(Y=1)=13⋅23=29P(X = 0)\,P(Y = 1) = \frac13 \cdot \frac23 = \frac29. Zero covariance rules out only a linear relation. Common mistakes: 2/32/3 for (a), which is E[Y]E[Y]; “yes” for (b), reading zero covariance as independence.

The remaining five problems estimate parameters: smoothing a categorical, two calculus MLEs, one EM step, and the proof that count over total is optimal.

Problem 5. A tokenized corpus holds N=10N = 10 tokens: “the” 4 times, “cat” 3, “sat” 2, “mat” 1. The vocabulary also has a fifth word, “dog”, never seen, so V=5V = 5. (a) The maximum-likelihood estimate of p(cat)p(\text{cat}). (b) The Laplace (add-one) estimate of p(dog)p(\text{dog}) over the V=5V = 5 words. [number]

Answer

(a) 3/103/10. (b) 1/151/15. (a) The categorical MLE is count over total: 3/103/10. (b) Laplace adds one pseudo-count to every vocabulary entry, so the denominator grows by VV: (0+1)/(10+5)=1/15(0 + 1)/(10 + 5) = 1/15. The five smoothed estimates 5/15,4/15,3/15,2/15,1/155/15, 4/15, 3/15, 2/15, 1/15 sum to 1. Common mistakes: 1/41/4 for (a), one over the number of distinct seen words; 4/154/15 for (a), the Laplace estimate of “cat” when the MLE was asked; 00 for (b), the unsmoothed MLE; 1/141/14 for (b), a vocabulary of the 4 seen words only; 1/111/11 for (b), adding one to NN only, after which the estimates no longer sum to 1.

Problem 6. nn independent Bernoulli(pp) trials give kk successes (0<k<n0 < k < n). (a) Give the log-likelihood ℓ(p)=ln⁡P(data∣p)\ell(p) = \ln P(\text{data} \mid p) of the observed sequence. [expr in k, n, p] (b) Give the pp that maximizes it. [expr in k, n]

Answer

(a) ℓ(p)=kln⁡p+(n−k)ln⁡(1−p)\ell(p) = k\ln p + (n - k)\ln(1 - p). (b) p^=k/n\hat p = k/n. (a) The observed sequence has probability pk(1−p)n−kp^k(1 - p)^{n - k} (independent trials multiply); its log is the sum. (b) ℓ′(p)=kp−n−k1−p=0\ell'(p) = \frac kp - \frac{n - k}{1 - p} = 0 gives k(1−p)=(n−k)pk(1 - p) = (n - k)p, so p=k/np = k/n. It is a maximum because ℓ′′(p)=−kp2−n−k(1−p)2<0\ell''(p) = -\frac k{p^2} - \frac{n - k}{(1 - p)^2} < 0. Common mistakes: kln⁡pk \ln p for (a), dropping the failures (its maximizer is p=1p = 1); pk(1−p)n−kp^k(1-p)^{n-k} for (a), the likelihood rather than its log; (k+1)/(n+2)(k + 1)/(n + 2) for (b), Laplace’s rule of succession, a smoothed estimate rather than the MLE; and n/kn/k.

Problem 7. The gaps between requests at your gateway are modeled as independent Exponential(λ\lambda) with density λe−λx\lambda e^{-\lambda x} for x≥0x \ge 0. You observe nn gaps whose sum is ss. Give the maximum-likelihood estimate of λ\lambda. [expr in n, s]

Answer

λ^=n/s\hat\lambda = n/s. The log-likelihood is ℓ(λ)=∑i(ln⁡λ−λxi)=nln⁡λ−λs\ell(\lambda) = \sum_i (\ln\lambda - \lambda x_i) = n\ln\lambda - \lambda s. Setting ℓ′(λ)=n/λ−s=0\ell'(\lambda) = n/\lambda - s = 0 gives λ=n/s\lambda = n/s, and ℓ′′(λ)=−n/λ2<0\ell''(\lambda) = -n/\lambda^2 < 0 makes it a maximum. The rate is the reciprocal of the mean gap s/ns/n; the arrival schedule of the open-loop load generator is fitted this way. Common mistakes: s/ns/n, the mean gap instead of the rate; (n−1)/s(n - 1)/s, the unbiased estimator of λ\lambda, which is not the MLE.

Problem 8. A Unigram tokenizer has three pieces with probabilities P(a)=1/4P(a) = 1/4, P(b)=1/4P(b) = 1/4, P(ab)=1/2P(ab) = 1/2, and the training corpus is the single word “ab”. It can be segmented as a+ba + b or as abab, and a segmentation’s probability is the product of its pieces’ probabilities. One EM step computes each piece’s expected count (each segmentation’s count of the piece, weighted by the segmentation’s posterior probability given the word), then sets each probability to its expected count divided by the total expected count. Give (a) the expected count of aa and (b) the new P(ab)P(ab). [number]

Answer

(a) 1/91/9. (b) 4/54/5. E-step: P(a+b)=14⋅14=116P(a + b) = \frac14 \cdot \frac14 = \frac1{16} and P(ab)=12=816P(ab) = \frac12 = \frac8{16}, total 916\frac9{16}, so the posteriors given the word are 19\frac19 and 89\frac89. Expected counts: aa appears once in a+ba + b, so 19\frac19; bb also 19\frac19; abab is 89\frac89. The total expected count is 109\frac{10}9. M-step: P(ab)=8/910/9=45P(ab) = \frac{8/9}{10/9} = \frac45 (and P(a)=P(b)=110P(a) = P(b) = \frac1{10}; the three sum to 1). Common mistakes: 1/41/4 for (a), the prior probability of aa rather than its expected count; 1/21/2 for (a), weighting both segmentations equally instead of by their posteriors; 8/98/9 for (b), the expected count without dividing by the total 10/910/9; 1/21/2 for (b), the old probability, with no M-step.

Problem 9. Counts c1,…,cV≥0c_1, \dots, c_V \ge 0 with N=c1+⋯+cV>0N = c_1 + \dots + c_V > 0 are observed from a categorical distribution p=(p1,…,pV)p = (p_1, \dots, p_V). Prove that the log-likelihood ∑kckln⁡pk\sum_k c_k \ln p_k is maximized over all probability vectors pp by pk=ck/Np_k = c_k / N. [proof]

Answer

Claim. Let c1,…,cV≥0c_1, \dots, c_V \ge 0 with N=c1+⋯+cV>0N = c_1 + \dots + c_V > 0. Over all probability vectors pp (pk≥0p_k \ge 0, ∑kpk=1\sum_k p_k = 1), ℓ(p)=∑kckln⁡pk\ell(p) = \sum_k c_k \ln p_k is maximized by p^k=ck/N\hat p_k = c_k / N, with the convention 0ln⁡0=00 \ln 0 = 0.

Zero counts. If some pk=0p_k = 0 with ck>0c_k > 0, then ℓ(p)=−∞\ell(p) = -\infty, so such a pp is never a maximizer; assume pk>0p_k > 0 wherever ck>0c_k > 0. Terms with ck=0c_k = 0 contribute 0 whatever pkp_k is, and p^k=0\hat p_k = 0 there.

Proof (Gibbs’ inequality). Let S={k:ck>0}S = \{k : c_k > 0\}. Then ℓ(p)=N∑k∈Sp^kln⁡pk=N∑k∈Sp^kln⁡p^k−N∑k∈Sp^kln⁡p^kpk=−N(H(p^)+KL(p^ ∥ p)),\ell(p) = N \sum_{k \in S} \hat p_k \ln p_k = N \sum_{k \in S} \hat p_k \ln \hat p_k - N \sum_{k \in S} \hat p_k \ln \frac{\hat p_k}{p_k} = -N\bigl(H(\hat p) + \mathrm{KL}(\hat p \,\Vert\, p)\bigr), where H(p^)H(\hat p) does not depend on pp. Since ln⁡t≤t−1\ln t \le t - 1 with equality only at t=1t = 1, −KL(p^∥p)=∑k∈Sp^kln⁡pkp^k≤∑k∈Sp^k(pkp^k−1)=∑k∈Spk−1≤0,-\mathrm{KL}(\hat p \Vert p) = \sum_{k \in S} \hat p_k \ln \frac{p_k}{\hat p_k} \le \sum_{k \in S} \hat p_k \Bigl(\frac{p_k}{\hat p_k} - 1\Bigr) = \sum_{k \in S} p_k - 1 \le 0, with equality only if pk=p^kp_k = \hat p_k for every k∈Sk \in S and pk=0p_k = 0 off SS. So ℓ(p)≤−NH(p^)=ℓ(p^)\ell(p) \le -N H(\hat p) = \ell(\hat p), with equality exactly at p=p^p = \hat p: count over total is the unique maximizer.

A Lagrange-multiplier argument also works: stationarity of ∑kckln⁡pk−μ(∑kpk−1)\sum_k c_k \ln p_k - \mu(\sum_k p_k - 1) gives ck/pk=μc_k/p_k = \mu, so pk∝ckp_k \propto c_k and μ=N\mu = N; it must then be argued that this stationary point is the maximum (the objective is concave). A complete proof states the claim, handles zero counts, and proves the maximum is attained only at c/Nc/N. The model proof is also in course/solutions/solve/S-M07b/q9.md.

Most wrong answers here come from reading the wrong piece of a table or dropping a term. Reading one cell as a marginal quotes P(Y=1)P(Y = 1) as a joint probability; sum the column instead (Problem 1a). Confusing a joint with a conditional answers P(X=1∣Y=0)P(X = 1 \mid Y = 0) as P(X=1,Y=0)P(X = 1, Y = 0); divide the cell by its column sum (Problem 1b). Assuming E[XY]=E[X]E[Y]E[XY] = E[X]E[Y] without independence reports zero covariance for dependent variables; compute E[XY]E[XY] cell by cell (Problem 2). And reading zero covariance as independence treats a deterministic relation as noise; check a cell of the joint, not the covariance (Problem 4b).

Warning: Dropping or halving the covariance term makes error bars on correlated losses too narrow. Expand the square and keep both cross terms, 2abc2abc (Problem 3).

The estimation pitfalls are just as specific. Applying Laplace over the seen words only, or adding one to NN only, gives unseen words the wrong mass and leaves the smoothed rows of the estimation section not summing to 1; add one per vocabulary entry and VV to the denominator (Problem 5b). Differentiating the likelihood instead of its log, or dropping the failures, gives a derivative that cannot be solved by hand, or p^=1\hat p = 1; differentiate the full log-likelihood (Problem 6). Reporting the mean gap instead of the rate inverts arrival rates in the load generator; solve ℓ′(λ)=0\ell'(\lambda) = 0 for the rate, n/sn/s (Problem 7). And skipping the M-step normalization in EM leaves probabilities that do not sum to 1 after one step; divide each expected count by the total, 10/910/9 in Problem 8b.

This set extends the single-variable expectation and variance of problem set A, and MLE, Laplace, absolute discounting implements mle and laplace, which are Problems 5 and 9 in code. In AI Engineering, The Unigram language model tokenizer computes the expected counts of Problem 8 by forward-backward and then takes count over total (Problem 9); n-gram language model with interpolated modified Kneser-Ney builds bigram and n-gram tables that are joint and conditional distributions over tokens (Problem 1); and the open-loop load generator uses Poisson arrivals with exponential gaps, whose rate Problem 7 fits from a trace. Problem set C builds the law of large numbers and confidence intervals on Problem 3’s variance of a sum.

  • Blitzstein and Hwang, Introduction to Probability (free), ch. 7 “Joint Distributions”.
  • Wasserman, All of Statistics, ch. 9 “Parametric Inference”.
  • Joint distribution: the table P(X=x,Y=y)P(X = x, Y = y) over pairs of values; it determines marginals and conditionals.
  • Marginal: the distribution of one variable, obtained by summing the joint over the other.
  • Covariance: E[XY]−E[X]E[Y]E[XY] - E[X]E[Y], a measure of linear co-movement; zero does not imply independence.
  • Likelihood: ∏ipθ(xi)\prod_i p_\theta(x_i), the probability of the observed data as a function of the parameter.
  • Maximum-likelihood estimate: the parameter value that maximizes the (log-)likelihood.
  • Laplace smoothing: adding one pseudo-count per vocabulary entry, (ck+1)/(N+V)(c_k + 1)/(N + V).
  • EM: expectation-maximization; replace hidden counts by expected counts under the current model, then take the MLE, and repeat.
  • A joint distribution holds everything: marginals are its row and column sums, conditionals are a renormalized row or column, and independence means every cell factors (Problem 1).
  • Covariance E[XY]−E[X]E[Y]E[XY] - E[X]E[Y] measures linear co-movement; it is the cross term in Var⁡(aX+bY)\operatorname{Var}(aX + bY), and zero covariance does not mean independence (Problems 2, 3, and 4).
  • The maximum-likelihood estimate of a categorical is count over total; Laplace smoothing adds one to every vocabulary entry, seen or not (Problems 5 and 9).
  • MLE by calculus: write the log-likelihood, differentiate, set to zero; the Bernoulli MLE is the success fraction and the exponential rate is the reciprocal of the mean gap (Problems 6 and 7).
  • When the data is hidden (which segmentation produced a word), EM replaces counts by expected counts and then takes the same MLE; one step of the Unigram trainer fits on a page (Problem 8).