---
title: Final exam
heading: "Final exam: machine learning"
eyebrow: S14 · Final exam
type: problems
---

::: hook
Twelve problems from the whole course: fitting and generalization, likelihood, decisions and information, Bayesian inference and regression, linear classifiers and their evaluation, neural networks and their training, kernels, support vector machines and Gaussian processes, mixtures, principal components and hidden Markov models, sampling, ensembles, and the cost of running models on hardware. Give yourself three hours and work without the lessons open. "Another set" deals a different exam.
:::

::: pool
pick: 12

::: check
kind: parts
given: a = 0 | 2; b = 3 | 5; c = 7 | 10; s = 0.05 | 0.3; p = 5 | 15; N = 50 | 300

## Points (0, {a}), (1, {b}), (3, {c}); a correct model with {p} parameters fitted to {N} examples of noise variance {s}.

::: part
answer: (3*(b + 3*c) - 4*(a + b + c))/(3*10 - 16)
tolerance: 0.5%

### Least-squares slope?

::: misses
- [any] The normal equations.
:::
:::

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

### Expected training error?

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

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

### Expected test error?

::: misses
- [any] $\sigma^2(1 + p/N)$.
:::
:::
:::

::: check
kind: parts
given: p = 0.002 | 0.02; s = 0.9 | 0.99; f = 0.01 | 0.05; v = 3 | 8; N = 5 | 20

## A test with detection rate {s} and false-alarm rate {f} for a condition of prevalence {p}; {N} samples with maximum-likelihood variance {v}.

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

### P(condition | positive)?

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

::: part
answer: v*N/(N - 1)
tolerance: 0.5%

### Unbiased variance estimate?

::: misses
- [any] $\sigma^2_{ML}N/(N - 1)$.
:::
:::
:::

::: check
kind: parts
given: d = 1.5 | 3; P = 0.7 | 0.9; c = 2 | 5; m = 40 | 400

## Unit-variance Gaussian classes {d} apart with priors {P} and 1 − {P}; a false alarm costs {c}, a miss {m}.

::: part
answer: Q(d/2)
tolerance: 0.5%

### Bayes error with equal priors?

::: misses
- [any] $Q(d/2)$.
:::
:::

::: part
answer: P*Q(d/2 + ln(P/(1 - P))/d) + (1 - P)*Q(d/2 - ln(P/(1 - P))/d)
tolerance: 0.5%

### Bayes error with these priors?

::: misses
- [any] Shift the boundary by $\ln(P_1/P_2)/d$.
:::
:::

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

### Posterior threshold for deciding positive?

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

::: check
kind: parts
given: p = 0.7 | 0.95; q = 0.5 | 0.85; a = 0.4 | 0.8; b = 0.6 | 0.9

## A true probability {p} modeled as {q}; a classifier gives the correct class probabilities {a} and {b} on two examples.

::: part
answer: p*ln(p/q) + (1 - p)*ln((1 - p)/(1 - q))
tolerance: 0.5%

### KL divergence in nats?

::: misses
- [any] $\sum p\ln(p/q)$.
:::
:::

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

### Average cross-entropy loss in nats?

::: misses
- [any] Mean of $-\ln q_\text{correct}$.
:::
:::
:::

::: check
kind: parts
given: a = 2 | 5; b = 2 | 5; m = 3 | 12; N = 15 | 40

## A beta({a}, {b}) prior and {m} successes in {N} trials.

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

### Posterior mean?

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

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

### Posterior variance?

::: misses
- [any] $AB/((A + B)^2(A + B + 1))$.
:::
:::
:::

::: check
kind: parts
given: u = 0 | 1; s = 1 | 3; v = 0.25 | 1; N = 5 | 25; x = 3 | 6; r = 0.5 | 0.8; b = 2 | 4

## A prior N({u}, {s}²) on a mean, {N} observations averaging {x} with noise variance {v}; separately, y with σ = {b} and correlation {r} with x.

::: part
answer: (u/s^2 + N*x/v)/(1/s^2 + N/v)
tolerance: 0.5%

### Posterior mean?

::: misses
- [any] Precision-weighted average.
:::
:::

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

### var(y | x)?

::: misses
- [any] $\sigma_y^2(1 - \rho^2)$.
:::
:::
:::

::: check
kind: parts
given: S = 6 | 30; w = 0.5 | 2.5; v = 2 | 8; d = 10 | 40; e = 0.5 | 2; f = 0.05 | 0.2; l = 1 | 3

## Ridge on one weight (Σx² = {S}, true w = {w}, noise variance {v}); a design whose $\Phi^T\Phi$ has eigenvalues {d}, {e}, {f}, with λ = {l}.

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

### Best λ for the weight?

::: misses
- [any] $\sigma^2/w^2$.
:::
:::

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

### Mean squared error at that λ?

::: misses
- [any] $\sigma^2/(S + \lambda^*)$.
:::
:::

::: part
answer: d/(d + l) + e/(e + l) + f/(f + l)
tolerance: 0.5%

### Effective parameters of the design?

::: misses
- [any] $\sum d/(d + \lambda)$.
:::
:::
:::

::: check
kind: parts
given: p = 1 | 3; q = 2 | 4; a = 0.5 | 2; b = 4 | 9; R = 4 | 10; g = 0.25 | 1

## Classes whose means differ by ({p}, {q}) with diagonal within-class variances {a} and {b}; separable data of radius {R} and margin {g}.

::: part
answer: p^2/a + q^2/b
tolerance: 0.5%

### Fisher's separation?

::: misses
- [any] $\Delta\mathbf{m}^TS_W^{-1}\Delta\mathbf{m}$.
:::
:::

::: part
answer: atan((q/b)/(p/a))*180/pi
unit: °
tolerance: 0.5%

### Fisher's direction from the first axis?

::: misses
- [any] $S_W^{-1}\Delta\mathbf{m}$.
:::
:::

::: part
answer: (R/g)^2
tolerance: 0.5%

### Perceptron mistake bound?

::: misses
- [any] $(R/\gamma)^2$.
:::
:::
:::

::: check
kind: parts
given: a = -4 | -2; b = 1 | 2.5; x = 1 | 3; p = 0.05 | 0.3; r = 6 | 20; k = 0.3 | 0.7

## A logistic model with $w_0$ = {a}, $w_1$ = {b}; a naive Bayes filter with prior {p} and two features with likelihood ratios {r} and {k}.

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

### Logistic probability at x = {x}?

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

::: part
answer: -a/b
tolerance: 0.5%

### Its decision boundary?

::: misses
- [any] $-w_0/w_1$.
:::
:::

::: part
answer: 1/(1 + exp(-(ln(p/(1 - p)) + ln(r) + ln(k))))
tolerance: 0.5%

### Naive Bayes posterior?

::: misses
- [any] Sigmoid of the summed log-odds.
:::
:::
:::

::: check
kind: parts
given: T = 40 | 120; F = 5 | 30; N = 10 | 40; p = 0.8 | 0.95; n = 400 | 4000; d = 1 | 2.5

## A confusion matrix with TP = {T}, FP = {F}, FN = {N}; an accuracy {p} measured on {n} examples; scores {d} standard deviations apart.

::: part
answer: 2*T/(2*T + F + N)
tolerance: 0.5%

### F1?

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

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

### Standard error of the accuracy?

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

::: part
answer: 1 - Q(d/sqrt(2))
tolerance: 0.5%

### AUC?

::: misses
- [any] $\Phi(d/\sqrt{2})$.
:::
:::
:::

::: check
kind: parts
given: D = 100 | 784; H = 64 | 256; K = 10 | 26; a = 0.5 | 2; b = -1 | 1; c = 0 | 1.5

## A {D}–{H}–{K} network with biases; separately, a three-class softmax with activations {a}, {b} and {c}.

::: part
answer: (D + 1)*H + (H + 1)*K
tolerance: 0.5%

### Parameters?

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

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

### Softmax probability of the first class?

::: misses
- [any] Softmax.
:::
:::
:::

::: check
kind: parts
given: u = 0.5 | 1.5; v = -2 | 1.5; t = 0 | 1; x = 1 | 2; k = 30 | 300; e = 1e-4 | 1e-6

## $y = w_2\tanh(w_1x)$ with $w_1$ = {u}, $w_2$ = {v}, input {x}, target {t}; a quadratic training problem with condition number {k}.

::: 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: ceil(ln(e)/ln((k - 1)/(k + 1)))
tolerance: 0.5%

### Gradient-descent steps to reduce the error by {e}?

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

::: check
kind: parts
given: N = 64 | 128; K = 3 | 5; P = 1 | 2; S = 2 | 1; C = 3 | 32; F = 32 | 64; L = 4 | 10

## A {K} × {K} convolution with padding {P} and stride {S} from {C} to {F} channels on an {N} × {N} input; a stack of {L} such layers at stride 1.

::: part
answer: floor((N - K + 2*P)/S) + 1
tolerance: 0.5%

### Output width?

::: misses
- [any] $\lfloor(N - K + 2P)/S\rfloor + 1$.
:::
:::

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

### Parameters?

::: misses
- [any] $K^2CF + F$.
:::
:::

::: part
answer: L*(K - 1) + 1
tolerance: 0.5%

### Receptive field of the stride-1 stack?

::: misses
- [any] $L(K - 1) + 1$.
:::
:::
:::

::: check
kind: parts
given: d = 0.8 | 2; s = 1 | 1.5; t = 0.5 | 2; n = 0.1 | 0.4; a = 1 | 2; b = 1 | 2.5; e = 0.1 | 0.3

## A Gaussian process with $\sigma_f$ = 1, ℓ = {s}, noise variance {n}, observing {t} at a point {d} away; a linear SVM with w = ({a}, {b}); an AdaBoost learner with error {e}.

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

### GP posterior mean?

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

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

### SVM margin?

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

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

### AdaBoost vote?

::: misses
- [any] $\frac{1}{2}\ln((1 - \varepsilon)/\varepsilon)$.
:::
:::
:::

::: check
kind: parts
given: a = 2 | 6; b = 1 | 1.5; c = 0.3 | 1; m = -1 | 0; n = 2 | 3; P = 0.4 | 0.75; x = 0.5 | 1

## A covariance with variances {a} and {b} and covariance {c}; a mixture of unit-variance components at {m} and {n} with weights {P} and 1 − {P}.

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

### First principal variance?

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

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

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

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

::: check
kind: parts
given: a = 0.05 | 0.2; b = 0.1 | 0.4; s = 0.5 | 3; e = 0.005 | 0.02; r = 0.5 | 0.9; P = 7e9 | 7e10; B = 4 | 8; W = 100 | 800

## A two-state chain leaving state 1 with probability {a} and state 2 with {b}; Monte Carlo with σ = {s}, target error {e}, on a chain with correlation {r}; a {P}-parameter model at {B} bits on {W} GB/s.

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

### Stationary probability of state 1?

::: misses
- [any] $b/(a + b)$.
:::
:::

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

### Chain steps needed?

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

::: part
answer: W/(P*B/8/1e9)
tolerance: 0.5%

### Token-rate bound at batch 1?

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