---
title: "Problem set 11: designing learning systems"
heading: "Problem set 11: design problems for thresholds from costs, test and label budgets, regularization and data for a target uncertainty, network sizes for a parameter budget, compute-optimal training, optimizers, ensembles, kernels, detectors, recurrent memory, context lengths and Monte Carlo budgets"
eyebrow: S14 · Problem set 11
type: problems
---

::: hook
Each problem here starts from a requirement and asks for the design that meets it: a threshold that minimizes expected cost, a test set that can certify a recall, a network that fits a parameter budget, a training run that fits a compute budget, a context that fits in memory. Most draw on two or three parts of the course at once.
:::

::: pool
pick: 12

::: check
kind: parts
given: d = 1.5 | 2.5 | 3.5; p = 0.01 | 0.1; c = 1 | 5; m = 20 | 200

## Scores are N(0, 1) for good units and N({d}, 1) for faulty ones, and {p} of units are faulty. A false alarm costs {c} and a missed fault {m}.

::: part
answer: d/2 + ln(c*(1 - p)/(m*p))/d
tolerance: 0.5%

### What score threshold minimizes the expected cost?

::: misses
- [d/2] That ignores the costs and the prior.
- [any] Flag where the likelihood ratio exceeds $c(1 - p)/(mp)$.
:::
:::

::: part
answer: 0.5*erfc(-(d/2 + ln(c*(1 - p)/(m*p))/d - d)/sqrt(2))
tolerance: 0.5%

### What fraction of faulty units does it miss?

::: misses
- [any] $\Phi(x^* - d)$.
:::
:::

::: part
answer: 0.5*erfc((d/2 + ln(c*(1 - p)/(m*p))/d)/sqrt(2))
tolerance: 0.5%

### What fraction of good units does it flag?

::: misses
- [any] $1 - \Phi(x^*)$.
:::
:::
:::

::: check
kind: parts
given: r = 0.8 | 0.95; s = 1 | 2; p = 0.005 | 0.05

## A detector's recall is about {r}. It must be measured with a standard error of {s} percentage points, and positives make up {p} of the data.

::: part
answer: r*(1 - r)/(s/100)^2
unit: positives
tolerance: 1%

### How many positive examples does the test set need?

::: misses
- [any] $r(1 - r)/\text{SE}^2$.
:::
:::

::: part
answer: r*(1 - r)/(s/100)^2/p
unit: examples
tolerance: 1%

### How many examples must be labeled in all?

::: misses
- [any] Divide by the prevalence.
:::
:::
:::

::: check
kind: parts
given: E = 0.03 | 0.05; a = 20 | 80; T = 0.06 | 0.08

## A learning curve fits test error as {E} + {a}/N, with N training examples.

::: part
answer: a/(T - E)
unit: examples
tolerance: 0.5%

### How many examples reach a test error of {T}?

::: misses
- [a/T] Subtract the error floor first.
- [any] $N = a/(T - E_\infty)$.
:::
:::

::: part
answer: a/(T - E) - a/(T + 0.01 - E)
unit: examples
tolerance: 0.5%

### How many more is that than for an error 0.01 higher?

::: misses
- [any] Difference of the two N's.
:::
:::
:::

::: check
kind: parts
given: S = 10 | 100; v = 0.5 | 4; w = 0.3 | 1

## A weight expected to be about {w} in size is estimated from data with Σx² = {S} and noise variance {v}.

::: part
answer: v/w^2
tolerance: 0.5%

### What ridge λ minimizes the mean squared error?

::: misses
- [w^2/v] Invert it.
- [any] $\lambda = \sigma^2/w^2$.
:::
:::

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

### What mean squared error does it achieve?

::: misses
- [v/S] That's least squares; ridge does better.
- [any] $\sigma^2/(S + \lambda)$ at the optimum.
:::
:::
:::

::: check
kind: parts
given: a = 0.1 | 1; b = 4 | 25; x = 2 | 5; t = 0.6 | 0.8

## A one-weight Bayesian model (prior precision {a}, noise precision {b}) must predict at x = {x} with a predictive standard deviation of {t}.

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

### How large must Σx² be?

::: misses
- [x^2/(t^2*b)] The noise variance 1/β is part of the predictive variance and doesn't shrink.
- [any] Solve $1/\beta + x^2/(\alpha + \beta\Sigma x^2) = t^2$.
:::
:::
:::

::: check
kind: parts
given: G = 20 | 100; k = 5 | 10; c = 3 | 40

## A grid of {G} hyperparameter settings is searched by {k}-fold cross-validation, then the best is refitted on all the data. One fit on all the data takes {c} minutes, and fits scale with training size.

::: part
answer: G*k + 1
unit: fits
tolerance: 0

### How many fits does it run?

::: misses
- [G*k] Count the final refit.
- [any] Gk + 1.
:::
:::

::: part
answer: (G*k*(k - 1)/k + 1)*c/60
unit: h
tolerance: 0.5%

### How long does it take?

::: misses
- [(G*k + 1)*c/60] Each fold trains on only (k − 1)/k of the data.
- [any] Weight each fold's fit by its size.
:::
:::
:::

::: check
kind: parts
given: D = 64 | 784; K = 2 | 10; P = 100000 | 1000000

## A network with {D} inputs, two hidden layers of equal width H and {K} outputs (with biases) must have about {P} parameters.

::: part
answer: (-(D + K + 2) + sqrt((D + K + 2)^2 - 4*(K - P)))/2
unit: units
tolerance: 0.5%

### What width H gives exactly that many?

::: misses
- [sqrt(P)] The input and output layers count too.
- [any] Solve $H^2 + (D + K + 2)H + K = P$.
:::
:::
:::

::: check
kind: parts
given: C = 1e21 | 1e23 | 1e24

## A training run has a budget of {C} operations, and follows the rule of thumb of about 20 training tokens per parameter.

::: part
answer: sqrt(C/120)/1e9
unit: billion
tolerance: 0.5%

### How many billion parameters should the model have?

::: misses
- [sqrt(C/6)/1e9] With D = 20N, C = 6ND = 120N².
- [any] $N = \sqrt{C/120}$.
:::
:::

::: part
answer: 20*sqrt(C/120)/1e9
unit: billion
tolerance: 0.5%

### On how many billion tokens of data?

::: misses
- [any] Twenty per parameter.
:::
:::
:::

::: check
kind: parts
given: a = 0.01 | 0.1; b = 10 | 100; e = 0.001 | 0.000001

## A quadratic training problem's Hessian eigenvalues run from {a} to {b}; the error must shrink by a factor of {e}.

::: part
answer: ln(e)/ln((b/a - 1)/(b/a + 1))
unit: steps
tolerance: 0.5%

### How many steps does gradient descent at its best fixed rate need?

::: misses
- [any] Factor $(\kappa - 1)/(\kappa + 1)$ per step.
:::
:::

::: part
answer: ln(e)/ln((sqrt(b/a) - 1)/(sqrt(b/a) + 1))
unit: steps
tolerance: 0.5%

### And with optimally tuned momentum?

::: misses
- [any] Factor $(\sqrt\kappa - 1)/(\sqrt\kappa + 1)$ per step.
:::
:::
:::

::: check
kind: parts
given: r = 0.1 | 0.3; e = 0.05 | 0.2; c = 2 | 15

## Trees in a forest have pairwise error correlation {r}. Each tree takes {c} ms to evaluate.

::: part
answer: (1 - r)/(r*e)
unit: trees
tolerance: 0.5%

### How many trees bring the forest's variance within {e} of its floor?

::: misses
- [any] Solve $(1 - \rho)\sigma^2/B = \epsilon\rho\sigma^2$.
:::
:::

::: part
answer: (1 - r)/(r*e)*c
unit: ms
tolerance: 0.5%

### How long does a prediction then take on one core?

::: misses
- [any] Trees times time per tree.
:::
:::
:::

::: check
kind: parts
given: d = 0.5 | 2; c = 0.5 | 0.9

## A Gaussian process's squared-exponential kernel must keep function values {d} apart correlated by at least {c}.

::: part
answer: d/sqrt(2*ln(1/c))
tolerance: 0.5%

### What is the smallest length scale that does?

::: misses
- [d/ln(1/c)] Solve $e^{-d^2/2\ell^2} = c$: a square root appears.
- [any] $\ell = d/\sqrt{2\ln(1/c)}$.
:::
:::
:::

::: check
kind: parts
given: k = 3 | 4 | 5; R = 10 | 1000

## A monitor flags any sample more than {k} standard deviations from a Gaussian model's mean, at {R} samples a second.

::: part
answer: erfc(k/sqrt(2))
tolerance: 0.5%

### What fraction of normal samples does it flag?

::: misses
- [0.5*erfc(k/sqrt(2))] Both tails count.
- [any] $\text{erfc}(k/\sqrt2)$.
:::
:::

::: part
answer: erfc(k/sqrt(2))*R*86400
tolerance: 0.5%

### How many false alarms does it raise per day (a number of alarms)?

::: misses
- [any] Rate times samples per day.
:::
:::
:::

::: check
kind: parts
given: T = 50 | 200 | 1000; f = 0.01 | 0.1

## A recurrent model must keep at least {f} of a gradient signal across {T} steps.

::: part
answer: f^(1/T)
tolerance: 0.5%

### What per-step gain does that require?

::: misses
- [any] $\rho^T = f$.
:::
:::

::: part
answer: ln(f^(1/T)/(1 - f^(1/T)))
tolerance: 0.5%

### What forget-gate bias would hold an LSTM cell at that gain?

::: misses
- [any] $b = \ln[g/(1 - g)]$.
:::
:::
:::

::: check
kind: parts
given: L = 32 | 64; d = 4096 | 5120; G = 80 | 141; W = 16 | 32; B = 4 | 16

## A model with {L} layers of width {d} and {W} GB of weights serves batches of {B} on a {G} GB device with a 16-bit key–value cache.

::: part
answer: floor((G - W)*1e9/(2*L*d*2*B))
unit: tokens
tolerance: 0

### What is the longest context that fits?

::: misses
- [floor((G - W)*1e9/(L*d*2*B))] Keys and values both take space.
- [any] Free memory over $2Ld \times 2$ bytes per token per sequence.
:::
:::
:::

::: check
kind: parts
given: s = 1 | 5; e = 0.01 | 0.05; r = 0.5 | 0.9

## A Monte Carlo estimate of a quantity with standard deviation {s} must reach a standard error of {e}, using a Markov chain whose successive samples are correlated by {r}.

::: part
answer: s^2/e^2
unit: samples
tolerance: 0.5%

### How many independent samples would that take?

::: misses
- [s/e] The error falls as $1/\sqrt N$.
- [any] $N = \sigma^2/\epsilon^2$.
:::
:::

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

### How many chain samples does it take?

::: misses
- [any] Scale by $(1 + r)/(1 - r)$.
:::
:::
:::
:::
