---
title: "Problem set 10: machine learning across the course"
heading: "Problem set 10: problems that combine priors and regression, classifiers and their evaluation, network sizes, gradients and training, kernels, Gaussian processes, mixtures, components, sampling, ensembles and hardware"
eyebrow: S14 · Problem set 10
type: problems
---

::: hook
These problems draw on the whole course, and most chain several ideas: a classifier's posterior turned into a decision and a precision, a network's size turned into a memory budget and a token rate, a covariance turned into components and a compression ratio. Work them as a review before the final.
:::

::: pool
pick: 12

::: check
kind: parts
given: a = 1 | 2; b = 1 | 3; m = 2 | 6; N = 10 | 20; c = 1 | 10; d = 50 | 200

## A defect rate has a beta({a}, {b}) prior and {m} defects are seen in {N} units; a false alarm costs {c} and a missed defect {d}.

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

### Posterior probability that the next unit is defective?

::: misses
- [any] Posterior mean.
:::
:::

::: part
answer: c/(c + d)
tolerance: 0.5%

### Probability above which a unit should be flagged?

::: misses
- [any] $c_{FA}/(c_{FA} + c_{miss})$.
:::
:::

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

### Expected cost of flagging the next unit?

::: misses
- [any] P(good) times the false-alarm cost.
:::
:::
:::

::: check
kind: parts
given: a = 0.5 | 2; b = 4 | 16; S = 5 | 20; T = 4 | 18; x = 2 | 5

## Bayesian regression of one weight: α = {a}, β = {b}, Σx² = {S}, Σxt = {T}.

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

### Posterior mean weight?

::: misses
- [any] $\beta T/(\alpha + \beta S)$.
:::
:::

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

### Predicted value at x = {x}?

::: misses
- [any] Mean weight times x.
:::
:::

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

### Its predictive standard deviation?

::: misses
- [any] Noise plus weight uncertainty.
:::
:::
:::

::: check
kind: parts
given: m = 2 | 3; n = 0 | -1; s = 0.8 | 1.5; P = 0.1 | 0.3; x = 1 | 2.5

## Gaussian classes (means {m} and {n}, variance {s}²) with class 1's prior {P}; a point at {x}.

::: part
answer: 1/(1 + exp(-((m - n)/s^2*x - (m^2 - n^2)/(2*s^2) + ln(P/(1 - P)))))
tolerance: 0.5%

### Posterior of class 1?

::: misses
- [any] $\sigma(wx + w_0)$.
:::
:::

::: part
answer: (m + n)/2 - s^2*ln(P/(1 - P))/(m - n)
tolerance: 0.5%

### Decision boundary?

::: misses
- [any] Where $wx + w_0 = 0$.
:::
:::
:::

::: check
kind: parts
given: s = 0.8 | 0.95; f = 0.9 | 0.99; p = 0.01 | 0.05; n = 2000 | 10000

## A detector with sensitivity {s} and specificity {f} screens {n} units with fault rate {p}.

::: part
answer: s*p*n
tolerance: 0.5%

### Expected true positives?

::: misses
- [any] Sensitivity × faulty units.
:::
:::

::: part
answer: (1 - f)*(1 - p)*n
tolerance: 0.5%

### Expected false positives?

::: misses
- [any] (1 − specificity) × good units.
:::
:::

::: part
answer: s*p/(s*p + (1 - f)*(1 - p))
tolerance: 0.5%

### Precision?

::: misses
- [any] TP/(TP + FP).
:::
:::

::: part
answer: 2*s*p/(2*s*p + (1 - f)*(1 - p) + (1 - s)*p)
tolerance: 0.5%

### F1?

::: misses
- [any] $2\text{TP}/(2\text{TP} + \text{FP} + \text{FN})$.
:::
:::
:::

::: check
kind: parts
given: D = 512 | 2048; H = 2048 | 8192; L = 12 | 48; b = 8 | 16; W = 200 | 1000

## A network of {L} identical blocks, each two dense layers {D} → {H} → {D} (no biases), stored at {b} bits and run at batch 1 on {W} GB/s.

::: part
answer: L*2*D*H
tolerance: 0.5%

### Parameters?

::: misses
- [any] $2DH$ per block.
:::
:::

::: part
answer: L*2*D*H*b/8/1e9
tolerance: 0.5%

### Weight memory in GB?

::: misses
- [any] Parameters × bits/8.
:::
:::

::: part
answer: W/(L*2*D*H*b/8/1e9)
tolerance: 0.5%

### Upper bound on forward passes per second?

::: misses
- [any] Bandwidth over model size.
:::
:::
:::

::: check
kind: parts
given: u = 0.4 | 1.2; v = -1.5 | 2; t = 0 | 1; x = 1 | 2; e = 0.05 | 0.2

## $y = w_2\tanh(w_1x)$ with $w_1$ = {u}, $w_2$ = {v}, input {x}, target {t}; one gradient step with rate {e}.

::: part
answer: (v*tanh(u*x) - t)*v*(1 - tanh(u*x)^2)*x
tolerance: 0.5%

### $\partial E/\partial w_1$?

::: misses
- [any] $(y - t)w_2(1 - z^2)x$.
:::
:::

::: part
answer: u - e*(v*tanh(u*x) - t)*v*(1 - tanh(u*x)^2)*x
tolerance: 0.5%

### $w_1$ after the step?

::: misses
- [any] $w_1 - \eta\,\partial E/\partial w_1$.
:::
:::

::: part
answer: v - e*(v*tanh(u*x) - t)*tanh(u*x)
tolerance: 0.5%

### $w_2$ after the step?

::: misses
- [any] $w_2 - \eta(y - t)z$.
:::
:::
:::

::: check
kind: parts
given: a = 0.2 | 1; b = 50 | 500; N = 64 | 224; K = 3 | 5; C = 16 | 64; F = 32 | 128

## A training problem with Hessian eigenvalues from {a} to {b}; a stride-1, padded {K} × {K} convolution from {C} to {F} channels on an {N} × {N} map.

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

### Best learning rate?

::: misses
- [any] $2/(\lambda_\min + \lambda_\max)$.
:::
:::

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

### Per-step factor with tuned momentum?

::: misses
- [any] $(\sqrt{\kappa} - 1)/(\sqrt{\kappa} + 1)$.
:::
:::

::: part
answer: N^2*F*K^2*C
tolerance: 0.5%

### Convolution multiply-accumulates (same-size output)?

::: misses
- [any] $N^2F \times K^2C$.
:::
:::
:::

::: check
kind: parts
given: d = 0.5 | 1.5; s = 1 | 2; t = 1 | 3; n = 0.05 | 0.25

## Two inputs {d} apart under a squared-exponential kernel with $\sigma_f$ = 1 and ℓ = {s}; a Gaussian process with noise variance {n} observes {t} at one of them.

::: part
answer: exp(-d^2/(2*s^2))
tolerance: 0.5%

### Kernel value?

::: misses
- [any] $e^{-d^2/2\ell^2}$.
:::
:::

::: part
answer: exp(-d^2/(2*s^2))*t/(1 + n)
tolerance: 0.5%

### Posterior mean at the other input?

::: misses
- [any] $kt/(1 + \sigma_n^2)$.
:::
:::

::: part
answer: 1 - exp(-d^2/s^2)/(1 + n)
tolerance: 0.5%

### Posterior variance there?

::: misses
- [any] $1 - k^2/(1 + \sigma_n^2)$.
:::
:::
:::

::: check
kind: parts
given: w = 3 | 4; v = 4 | 2; x = 1 | 2; y = 0.5 | 1; t = 1 | -1; C = 1 | 10

## A linear SVM with w = ({w}, {v}); ({x}, {y}) is a support vector labeled {t}; the soft-margin constant is C = {C} and the total slack is 0.6.

::: part
answer: 1/sqrt(w^2 + v^2)
tolerance: 0.5%

### Margin?

::: misses
- [any] $1/\|\mathbf{w}\|$.
:::
:::

::: part
answer: t - (w*x + v*y)
tolerance: 0.5%

### Bias?

::: misses
- [any] $t_s - \mathbf{w}^T\mathbf{x}_s$.
:::
:::

::: part
answer: (w^2 + v^2)/2 + C*0.6
tolerance: 0.5%

### Objective?

::: misses
- [any] $\frac{1}{2}\|\mathbf{w}\|^2 + C\sum\xi$.
:::
:::
:::

::: check
kind: parts
given: a = 0 | 1; b = 3 | 4; P = 0.3 | 0.6; x = 1.5 | 2; K = 3 | 6; D = 4 | 16

## A mixture of unit-variance components at {a} and {b} with weights {P} and 1 − {P}; a {K}-component full-covariance mixture in {D} dimensions.

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

### Responsibility of the first component at {x}?

::: misses
- [any] Bayes' theorem over components.
:::
:::

::: part
answer: K*(D + D*(D + 1)/2) + K - 1
tolerance: 0.5%

### Parameters of the {D}-dimensional mixture?

::: misses
- [any] $K(D + D(D + 1)/2) + K - 1$.
:::
:::
:::

::: check
kind: parts
given: a = 3 | 8; b = 1 | 2; c = 0.5 | 1.5; N = 2000 | 10000; D = 64 | 256

## Two-dimensional data with variances {a} and {b} and covariance {c}; separately, {N} samples of dimension {D} compressed to 8 components.

::: part
answer: ((a + b)/2 + sqrt((a - b)^2/4 + c^2))/(a + b)
tolerance: 0.5%

### Fraction of variance in the first component?

::: misses
- [any] First eigenvalue over the trace.
:::
:::

::: part
answer: (a + b)/2 - sqrt((a - b)^2/4 + c^2)
tolerance: 0.5%

### One-component reconstruction error?

::: misses
- [any] The discarded eigenvalue.
:::
:::

::: part
answer: N*D/(N*8 + 8*D + D)
tolerance: 0.5%

### Compression factor?

::: misses
- [any] $ND/(NM + MD + D)$.
:::
:::
:::

::: check
kind: parts
given: s = 0.5 | 2; e = 0.005 | 0.02; r = 0.7 | 0.9; q = 0.1 | 0.3; B = 20 | 100

## A Monte Carlo average of a quantity with standard deviation {s}, drawn from a Markov chain with neighbor correlation {r}; separately, an ensemble of {B} models with error correlation {q}.

::: part
answer: (s/e)^2
tolerance: 0.5%

### Independent samples needed for standard error {e}?

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

::: part
answer: (s/e)^2*(1 + r)/(1 - r)
tolerance: 0.5%

### Chain steps needed?

::: misses
- [any] Divide by $(1 - \rho)/(1 + \rho)$.
:::
:::

::: part
answer: q + (1 - q)/B
tolerance: 0.5%

### Ensemble variance as a fraction of one model's?

::: misses
- [any] $\rho + (1 - \rho)/B$.
:::
:::
:::

::: check
kind: parts
given: s = 1 | 2; v = 0.5 | 2; y = 0.5 | 1.5; c = 1 | 2; m = 3 | 10

## A quantity x has prior N(0, {s}²) and is measured as y = {y} with noise variance {v}. Acting when x > 0 gains {m}; acting when x ≤ 0 costs {c}.

::: part
answer: (y/v)/(1/s^2 + 1/v)
tolerance: 0.5%

### What is the posterior mean of x?

::: misses
- [y] Shrink toward the prior.
- [any] Precision-weighted.
:::
:::

::: part
answer: 0.5*erfc(-((y/v)/(1/s^2 + 1/v))*sqrt(1/s^2 + 1/v)/sqrt(2))
tolerance: 0.5%

### What is P(x > 0 | y)?

::: misses
- [any] $\Phi(\mu/\sigma)$ for the posterior.
:::
:::

::: part
answer: c/(c + m)
tolerance: 0.5%

### Above what posterior probability is acting worthwhile?

::: misses
- [m/(c + m)] Act when $pm > (1 - p)c$.
- [any] $p > c/(c + m)$.
:::
:::
:::

::: check
kind: parts
given: d = 2048 | 4096; L = 24 | 32; W = 1 | 2; B = 1 | 16

## A transformer with width {d} and {L} layers (ignore its embedding) stores 16-bit weights and serves batch {B} from {W} TB/s of memory bandwidth, memory-bound.

::: part
answer: 12*d^2*L*2/1e9
unit: GB
tolerance: 0.5%

### How much do its weights take?

::: misses
- [12*d^2*L/1e9] Two bytes per weight.
- [any] $12d^2L$ weights at 2 bytes.
:::
:::

::: part
answer: B*W*1e12/(12*d^2*L*2)
unit: tokens/s
tolerance: 0.5%

### How many tokens per second does it generate in all?

::: misses
- [any] Each step reads all the weights and yields B tokens.
:::
:::
:::

::: check
kind: parts
given: N = 500 | 3000; c = 0.95 | 0.99; M = 10 | 1000

## A classifier makes no errors on {N} independent test examples.

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

### What error rate does that bound with confidence {c}?

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

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

### What bound holds if the classifier was the best of {M} candidates checked on the same examples?

::: misses
- [any] Share the failure probability among the M candidates: δ/M.
:::
:::
:::
:::
