---
title: "Problem set 3: generalization, inference and model selection"
heading: "Problem set 3: test-set sizes and generalization bounds, conjugate updates and predictions, Gaussian fusion and conditioning, ridge and Bayesian regression, cross-validation, information criteria and the evidence"
eyebrow: S14 · Problem set 3
type: problems
---

::: hook
These problems cover lessons 5 to 13: how many examples a claim about error needs, Bayesian updates and the predictions they give, combining and conditioning Gaussian measurements, regression with and without priors, and choosing a model's complexity by cross-validation, information criteria or the evidence. Several follow one data set through two or three of those steps.
:::

::: pool
pick: 12

::: check
kind: parts
given: p = 0.02 | 0.1; e = 0.005 | 0.01; d = 0.05 | 0.01

## A defect detector's error rate is near {p}. It must be measured to within ±{e} with failure probability {d}.

::: part
answer: ln(2/d)/(2*e^2)
unit: examples
tolerance: 1%

### How many test examples does Hoeffding's inequality call for?

::: misses
- [any] $\ln(2/\delta)/(2\epsilon^2)$.
:::
:::

::: part
answer: p*(1 - p)*(2.5758*step(0.03 - d) + 1.96*step(d - 0.03))^2/e^2
unit: examples
tolerance: 1%

### And the normal approximation (z = 1.96 for δ = 0.05, 2.576 for δ = 0.01)?

::: misses
- [any] $z^2p(1 - p)/\epsilon^2$.
:::
:::
:::

::: check
kind: parts
given: p = 0.001 | 0.01; c = 0.9 | 0.95 | 0.99; N = 200 | 2000

## A safety function must be shown to fail less often than {p} per demand with confidence {c}.

::: part
answer: ln(1 - c)/ln(1 - p)
unit: demands
tolerance: 1%

### How many failure-free demands does that take?

::: misses
- [-ln(1 - c)*p] Divide by the rate, don't multiply.
- [any] $(1 - p)^N = 1 - c$.
:::
:::

::: part
answer: (1 - (1 - c)^(1/N))*100
unit: %
tolerance: 0.5%

### What rate is demonstrated by {N} failure-free demands at that confidence?

::: misses
- [any] $1 - (1 - c)^{1/N}$.
:::
:::
:::

::: check
kind: parts
given: N = 1000 | 5000; M = 20 | 500; d = 0.05 | 0.01

## A team tunes {M} hyperparameter settings on a validation set of {N} examples.

::: part
answer: sqrt(ln(2*M/d)/(2*N))
tolerance: 0.5%

### How far might the best setting's validation error sit from its true error, with failure probability {d}?

::: misses
- [sqrt(ln(2/d)/(2*N))] That's for a single model fixed in advance.
- [any] $\sqrt{\ln(2M/\delta)/(2N)}$.
:::
:::

::: part
answer: N*ln(2*M/d)/ln(2/d)
unit: examples
tolerance: 0.5%

### How large a validation set would bring that bound down to a single model's on {N} examples?

::: misses
- [any] Scale N by $\ln(2M/\delta)/\ln(2/\delta)$.
:::
:::
:::

::: check
kind: parts
given: a = 1 | 2; b = 1 | 3; m = 1 | 3; N = 5 | 10

## A yield has a beta({a}, {b}) prior; {m} of {N} parts then fail.

::: part
answer: (a + m)/(a + b + N)
tolerance: 0.5%

### What is the posterior mean failure rate?

::: misses
- [m/N] That ignores the prior.
- [any] $(a + m)/(a + b + N)$.
:::
:::

::: part
answer: sqrt((a + m)*(b + N - m)/((a + b + N)^2*(a + b + N + 1)))
tolerance: 0.5%

### What is its posterior standard deviation?

::: misses
- [any] The beta variance $\alpha\beta/[(\alpha + \beta)^2(\alpha + \beta + 1)]$ at the posterior's parameters.
:::
:::

::: part
answer: ((b + N - m)/(a + b + N))*((b + N - m + 1)/(a + b + N + 1))
tolerance: 0.5%

### What probability does it give the next two parts both passing?

::: misses
- [((b + N - m)/(a + b + N))^2] Update on the first pass before predicting the second.
- [any] $\frac{\beta'}{\alpha' + \beta'}\cdot\frac{\beta' + 1}{\alpha' + \beta' + 1}$.
:::
:::
:::

::: check
kind: parts
given: a = 1 | 3; b = 1000 | 5000; k = 2 | 7; T = 8000 | 30000; R = 10000 | 30000

## A failure rate has a gamma({a}, {b} h) prior; a fleet then logs {k} failures in {T} hours.

::: part
answer: (a + k)/(b + T)*1e4
tolerance: 0.5%

### What is the posterior mean rate, per 10,000 hours?

::: misses
- [k/T*1e4] Include the prior.
- [any] $(\alpha + k)/(\beta + T)$.
:::
:::

::: part
answer: ((b + T)/(b + T + R))^(a + k)
tolerance: 0.5%

### What probability does the posterior give a unit running {R} hours with no failure?

::: misses
- [exp(-(a + k)/(b + T)*R)] That plugs in the mean rate; averaging over the rate's uncertainty gives $(\beta'/(\beta' + R))^{\alpha'}$.
- [any] $E[e^{-\lambda R}]$ under gamma(α′, β′).
:::
:::
:::

::: check
kind: parts
given: x = 10 | 12; y = 14 | 16; z = 8 | 9; a = 1 | 4; b = 0.5 | 2; c = 3 | 9

## Three independent unbiased sensors read {x}, {y} and {z}, with noise variances {a}, {b} and {c}.

::: part
answer: (x/a + y/b + z/c)/(1/a + 1/b + 1/c)
tolerance: 0.5%

### What is the best combined estimate?

::: misses
- [(x + y + z)/3] Weight each reading by its precision.
- [any] $\sum(x_i/\sigma_i^2)/\sum(1/\sigma_i^2)$.
:::
:::

::: part
answer: 1/sqrt(1/a + 1/b + 1/c)
tolerance: 0.5%

### What is its standard deviation?

::: misses
- [1/(1/a + 1/b + 1/c)] That's the variance.
- [any] $1/\sqrt{\sum 1/\sigma_i^2}$.
:::
:::
:::

::: check
kind: parts
given: u = 20 | 25; s = 2 | 5; v = 3 | 10; r = 0.5 | 0.9; X = 22 | 30; w = 60 | 75

## A component's temperature y and a sensor's reading x are jointly Gaussian: y has mean {w} and standard deviation {v}, x has mean {u} and standard deviation {s}, and their correlation is {r}. The sensor reads {X}.

::: part
answer: w + r*v/s*(X - u)
tolerance: 0.5%

### What is the expected temperature?

::: misses
- [w + r*s/v*(X - u)] The regression slope is $\rho\sigma_y/\sigma_x$.
- [any] $\mu_y + \rho(\sigma_y/\sigma_x)(x - \mu_x)$.
:::
:::

::: part
answer: v*sqrt(1 - r^2)
tolerance: 0.5%

### What is its conditional standard deviation?

::: misses
- [v*(1 - r^2)] Take the square root of $1 - \rho^2$.
- [any] $\sigma_y\sqrt{1 - \rho^2}$.
:::
:::
:::

::: check
kind: parts
given: a = 4 | 10; b = 2 | 6; c = 1 | -1.5; u = 5 | 12; v = 3 | 8; l = 0.5 | 2; p = 1 | 2; q = -1 | 1

## A two-feature fit has $\Phi^T\Phi = \begin{bmatrix}a & c \\ c & b\end{bmatrix}$ with a = {a}, b = {b}, c = {c}, and $\Phi^T\mathbf t$ = ({u}, {v}). It's fitted by ridge regression with λ = {l}.

::: part
answer: ((b + l)*u - c*v)/((a + l)*(b + l) - c^2)
tolerance: 0.5%

### What is $w_1$?

::: misses
- [(b*u - c*v)/(a*b - c^2)] That's least squares; add λ to the diagonal.
- [any] Invert $\Phi^T\Phi + \lambda I$.
:::
:::

::: part
answer: (((b + l)*u - c*v)*p + ((a + l)*v - c*u)*q)/((a + l)*(b + l) - c^2)
tolerance: 0.5%

### What does the fit predict for features ({p}, {q})?

::: misses
- [any] $w_1x_1 + w_2x_2$.
:::
:::
:::

::: check
kind: parts
given: a = 5 | 20; b = 1 | 4; S = 5 | 30; T = 6 | 40; x = 1 | 4

## A one-weight Bayesian regression has prior precision {a}, noise precision {b}, Σx² = {S} and Σxt = {T}.

::: part
answer: b*T/(a + b*S)
tolerance: 0.5%

### What is the posterior mean of the weight?

::: misses
- [T/S] That's least squares; the prior pulls toward zero.
- [any] $\beta\Sigma xt/(\alpha + \beta\Sigma x^2)$.
:::
:::

::: part
answer: sqrt(1/b + x^2/(a + b*S))
tolerance: 0.5%

### What is the predictive standard deviation at x = {x}?

::: misses
- [sqrt(x^2/(a + b*S))] Add the noise variance 1/β.
- [any] $\sqrt{1/\beta + x^2/(\alpha + \beta\Sigma x^2)}$.
:::
:::
:::

::: check
kind: parts
given: e = 0.2 | -0.4; f = 0.3 | 0.1; g = -0.5 | 0.25; h = 0.3 | 0.5; k = 0.15 | 0.6; m = 0.45 | 0.2

## Three points of a least-squares fit have residuals {e}, {f} and {g}, and leverages {h}, {k} and {m}.

::: part
answer: e/(1 - h)
tolerance: 0.5%

### What is the first point's leave-one-out residual?

::: misses
- [any] $e/(1 - h)$.
:::
:::

::: part
answer: (e/(1 - h))^2 + (f/(1 - k))^2 + (g/(1 - m))^2
tolerance: 0.5%

### What do the three contribute to the leave-one-out sum of squared errors?

::: misses
- [e^2 + f^2 + g^2] Use the leave-one-out residuals.
- [any] $\sum[e_i/(1 - h_{ii})]^2$.
:::
:::
:::

::: check
kind: parts
given: a = 50 | 200; b = 5 | 20; c = 0.5 | 2; l = 1 | 10; N = 30 | 100; m = 0.4 | 1.5

## A ridge fit with λ = {l} on {N} points has $\Phi^T\Phi$ eigenvalues {a}, {b} and {c}, and a mean squared training residual of {m}.

::: part
answer: a/(a + l) + b/(b + l) + c/(c + l)
tolerance: 0.5%

### How many effective parameters does it have?

::: misses
- [3] Ridge shrinks the weak directions.
- [any] $\sum\lambda_i/(\lambda_i + \lambda)$.
:::
:::

::: part
answer: m/(1 - (a/(a + l) + b/(b + l) + c/(c + l))/N)^2
tolerance: 0.5%

### What is its GCV score?

::: misses
- [any] $\overline{e^2}/(1 - p_\text{eff}/N)^2$.
:::
:::
:::

::: check
kind: parts
given: L = -412 | -95; M = 4 | 7; d = 4 | 9; k = 3 | 6; N = 80 | 5000

## A model with {M} parameters reaches ln L = {L} on {N} examples; a larger one with {k} more parameters gains {d} nats.

::: part
answer: d - k
tolerance: 0.5%

### By how much does the larger model change the AIC score (ln L − M)?

::: misses
- [any] $\Delta\ln L - \Delta M$.
:::
:::

::: part
answer: d - k/2*ln(N)
tolerance: 0.5%

### And the BIC score?

::: misses
- [d - k*ln(N)] BIC charges half of ln N per parameter.
- [any] $\Delta\ln L - \frac{\Delta M}2\ln N$.
:::
:::

::: part
answer: L + d - (M + k)/2*ln(N)
tolerance: 0.5%

### What is the larger model's BIC score?

::: misses
- [any] $\ln L - \frac M2\ln N$.
:::
:::
:::

::: check
kind: parts
given: x = 1 | 2 | 3; t = 1.2 | 2 | 3; b = 1 | 4

## A line through the origin, with noise precision {b}, is fitted to the single point ({x}, {t}), and its prior precision chosen by the evidence.

::: part
answer: x^2/(t^2 - 1/b)
tolerance: 0.5%

### What prior precision maximizes the evidence?

::: misses
- [x^2/t^2] That's $1/w_\text{ML}^2$; correct for the noise in the measured slope.
- [any] $\alpha = S^2/(T^2 - S/\beta)$ with S = x² and T = xt, which is $x^2/(t^2 - 1/\beta)$.
:::
:::

::: part
answer: b*x*t/(x^2/(t^2 - 1/b) + b*x^2)
tolerance: 0.5%

### What slope does the posterior then give?

::: misses
- [t/x] That's least squares.
- [any] $\beta xt/(\alpha + \beta x^2)$.
:::
:::
:::

::: check
kind: parts
given: B = 10 | 20 | 50; e = 0.01 | 0.05; d = 0.05 | 0.01

## A learner outputs a conjunction of literals (each of {B} Boolean variables appears plain, negated, or not at all) consistent with its training data.

::: part
answer: B*ln(3)
tolerance: 0.5%

### What is ln M for this hypothesis class?

::: misses
- [B*ln(2)] Each variable has three options.
- [any] $M = 3^B$.
:::
:::

::: part
answer: (B*ln(3) + ln(1/d))/e
unit: examples
tolerance: 1%

### How many training examples guarantee error below {e} with failure probability {d}?

::: misses
- [any] $(\ln M + \ln(1/\delta))/\epsilon$.
:::
:::
:::

::: check
kind: parts
given: D = 5 | 20; N = 200 | 2000; k = 5 | 10

## A linear classifier with a bias is trained on {N} examples with {D} features, and evaluated by {k}-fold cross-validation.

::: part
answer: D + 1
tolerance: 0

### What is its VC dimension?

::: misses
- [any] d + 1.
:::
:::

::: part
answer: N*(k - 1)/k/(D + 1)
tolerance: 0.5%

### How many training examples per unit of VC dimension does each fold's fit get?

::: misses
- [N/(D + 1)] Each fold trains on (k − 1)/k of the data.
- [any] $N(k - 1)/[k(d + 1)]$.
:::
:::
:::
:::
