---
title: "Problem set 8: PCA, sequences, sampling, ensembles and hardware"
heading: "Problem set 8: principal components and explained variance, Markov chains and the forward algorithm, Monte Carlo and MCMC, trees, bagging and boosting, and the cost of running networks"
eyebrow: S14 · Problem set 8
type: problems
---

::: hook
These problems cover lessons 40 to 47: eigenvalues and angles of covariance matrices, explained variance and compression, random projections, stationary distributions, filtering and path probabilities, Monte Carlo sample sizes, inverse-CDF and Metropolis steps, effective sample sizes, impurity and ensemble variance, AdaBoost's weights, and FLOPs, bytes, rooflines and quantization.
:::

::: pool
pick: 12

::: check
kind: parts
given: a = 2 | 6; b = 1 | 1.5; c = 0.4 | 1.2

## A covariance matrix with variances {a} and {b} and covariance {c}.

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

### First eigenvalue?

::: misses
- [any] $\frac{a + b}{2} + \sqrt{(\frac{a - b}{2})^2 + c^2}$.
:::
:::

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

### Fraction of variance it explains?

::: misses
- [any] Over the trace.
:::
:::

::: part
answer: atan(2*c/(a - b))/2*180/pi
unit: °
tolerance: 0.5%

### Its angle from the first axis?

::: misses
- [any] $\frac{1}{2}\tan^{-1}(2c/(a - b))$.
:::
:::
:::

::: check
kind: parts
given: p = 6 | 12; q = 2 | 4; r = 0.8 | 1.5; s = 0.1 | 0.4; N = 1000 | 20000; D = 200 | 800

## Eigenvalues {p}, {q}, {r}, {s}; {N} samples of dimension {D} kept with two components.

::: part
answer: (p + q)/(p + q + r + s)
tolerance: 0.5%

### Variance explained by two components?

::: misses
- [any] Kept over total.
:::
:::

::: part
answer: r + s
tolerance: 0.5%

### Mean squared reconstruction error?

::: misses
- [any] Discarded eigenvalues.
:::
:::

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

### Compression factor?

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

::: check
kind: parts
given: a = 0.05 | 0.15; b = 0.2 | 0.5; q = 0 | 1; n = 2 | 4

## A two-state chain leaving state 1 with probability {a} and state 2 with probability {b}, starting in state 1 with probability {q}.

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

### Stationary probability of state 1?

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

::: part
answer: 1/a
tolerance: 0.5%

### Mean stay in state 1?

::: misses
- [any] $1/(1 - A_{11})$.
:::
:::

::: part
answer: b/(a + b) + (q - b/(a + b))*(1 - a - b)^n
tolerance: 0.5%

### Probability of state 1 after {n} steps?

::: misses
- [any] The gap shrinks by $1 - a - b$ per step.
:::
:::
:::

::: check
kind: parts
given: p = 0.6 | 0.85; s = 0.85 | 0.95; e = 0.05 | 0.15; f = 0.6 | 0.8

## A machine is healthy with prior {p}, stays healthy with probability {s}, and raises an alarm with probability {e} when healthy and {f} when faulty. Hour 1 has an alarm.

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

### P(faulty | alarm)?

::: misses
- [any] Normalize $\alpha_1$.
:::
:::

::: part
answer: p*e
tolerance: 0.5%

### $\alpha_1$(healthy)?

::: misses
- [any] $\pi_HP(\text{alarm}|H)$.
:::
:::

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

### Probability of the path healthy–healthy with alarms in both hours?

::: misses
- [any] Multiply along the path.
:::
:::
:::

::: check
kind: parts
given: s = 0.3 | 3; e = 0.002 | 0.02; u = 0.3 | 0.8; L = 0.5 | 4

## Monte Carlo with per-sample standard deviation {s}; an inverse-CDF draw from an exponential of rate {L}.

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

### Samples for standard error {e}?

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

::: part
answer: -ln(1 - u)/L
tolerance: 0.5%

### Sample for u = {u}?

::: misses
- [any] $-\ln(1 - u)/\lambda$.
:::
:::
:::

::: check
kind: parts
given: x = 0.5 | 1.2; d = 0.4 | 0.8; s = 1 | 1.5; N = 5000 | 50000; r = 0.8 | 0.95

## A Metropolis sampler for a zero-mean Gaussian with σ = {s} at x = {x} proposes a step {d} outward; separately, a chain of {N} steps with neighbor correlation {r}.

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

### Acceptance probability?

::: misses
- [any] Density ratio.
:::
:::

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

### Effective sample size?

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

::: check
kind: parts
given: a = 0.4 | 1; b = 1 | 3; c = 0.2 | 0.6; L = 1 | 2; p = 2 | 5

## Importance weights {a}, {b}, {c}; rejection sampling a density of maximum {p} on an interval of length {L} with a uniform proposal.

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

### Effective sample size of the weights?

::: misses
- [any] $(\sum w)^2/\sum w^2$.
:::
:::

::: part
answer: 1/(p*L)
tolerance: 0.5%

### Acceptance rate?

::: misses
- [any] $1/(p_\max L)$.
:::
:::
:::

::: check
kind: parts
given: a = 25 | 40; b = 5 | 10; c = 10 | 20; d = 40 | 70

## A split sends {a} positive and {b} negative left, {c} positive and {d} negative right.

::: part
answer: 2*(a + c)*(b + d)/(a + b + c + d)^2
tolerance: 0.5%

### Parent Gini impurity?

::: misses
- [any] $2p(1 - p)$.
:::
:::

::: part
answer: ((a + b)*2*a*b/(a + b)^2 + (c + d)*2*c*d/(c + d)^2)/(a + b + c + d)
tolerance: 0.5%

### Weighted Gini of the children?

::: misses
- [any] Weight each child by its share.
:::
:::
:::

::: check
kind: parts
given: r = 0.2 | 0.5; s = 1 | 3; B = 5 | 50; N = 4 | 20

## An ensemble of {B} models with variance {s} and correlation {r}; bootstrap samples of size {N}.

::: part
answer: r*s + (1 - r)*s/B
tolerance: 0.5%

### Ensemble variance?

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

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

### Fraction of distinct examples in a bootstrap sample?

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

::: check
kind: parts
given: e = 0.1 | 0.15 | 0.2 | 0.25 | 0.3 | 0.35 | 0.4

## An AdaBoost learner with weighted error {e}.

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

### Its vote α?

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

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

### Multiplier for misclassified weights?

::: misses
- [any] $e^\alpha$.
:::
:::

::: part
answer: e*sqrt((1 - e)/e)/(e*sqrt((1 - e)/e) + (1 - e)*sqrt(e/(1 - e)))
tolerance: 0.5%

### Share of the weight on misclassified examples after renormalizing?

::: misses
- [any] Multiply and renormalize.
:::
:::
:::

::: check
kind: parts
given: D = 1024 | 4096; H = 1024 | 8192; B = 1 | 16; P = 3e9 | 3e10; b = 4 | 8; W = 100 | 1000

## A dense {D}-to-{H} layer at batch {B}; a {P}-parameter model at {b} bits on {W} GB/s.

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

### Layer FLOPs?

::: misses
- [any] $2BDH$.
:::
:::

::: part
answer: P*b/8/1e9
tolerance: 0.5%

### Model size in GB?

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

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

### Token-rate bound at batch 1?

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

::: check
kind: parts
given: F = 50 | 400; W = 1 | 3; B = 1 | 8 | 64; m = 0.25 | 1

## A chip with {F} TFLOP/s and {W} TB/s runs an int8 layer at batch {B} (intensity about 2B); weights up to ±{m} are quantized to int8.

::: part
answer: F/W
tolerance: 0.5%

### Ridge point in FLOP/byte?

::: misses
- [any] F/W.
:::
:::

::: part
answer: (F + 2*B*W - abs(F - 2*B*W))/2
tolerance: 0.5%

### Attainable TFLOP/s?

::: misses
- [any] min(F, I·W).
:::
:::

::: part
answer: m/127/sqrt(12)
tolerance: 0.5%

### RMS rounding error?

::: misses
- [any] $\Delta/\sqrt{12}$.
:::
:::
:::

::: check
kind: parts
given: a = 3 | 6; b = 1 | 2; c = 0.5 | 1.2

## A covariance matrix has variances {a} and {b} and covariance {c}.

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

### What is its smaller eigenvalue?

::: misses
- [any] $\frac{a + b}2 - \sqrt{(\frac{a - b}2)^2 + c^2}$.
:::
:::

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

### By what factor does whitening stretch that direction?

::: misses
- [any] $1/\sqrt{\lambda_2}$.
:::
:::
:::

::: check
kind: parts
given: r = 0.7 | 0.95; y = 1 | -2; N = 2000 | 50000

## A Gibbs sampler for a standard bivariate Gaussian with correlation {r} runs {N} sweeps.

::: part
answer: r*y
tolerance: 0.5%

### Where is x | y = {y} centered?

::: misses
- [any] ρy.
:::
:::

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

### What effective sample size do its x values give?

::: misses
- [N*(1 - r)/(1 + r)] The lag-one correlation is ρ².
- [any] $N(1 - \rho^2)/(1 + \rho^2)$.
:::
:::
:::

::: check
kind: parts
given: a = 2 | 4; b = 6 | 7; c = 12 | 15; v = 0.3 | 1

## Gradient boosting with squared loss and learning rate {v} starts from the mean of the targets {a}, {b} and {c}, and adds a stump splitting {a} and {b} from {c}.

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

### What is the starting mean squared error?

::: misses
- [any] The targets' variance.
:::
:::

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

### What is it after one step?

::: misses
- [any] Each leaf adds ν times its mean residual.
:::
:::
:::

::: check
kind: parts
given: n = 1e4 | 1e6; e = 0.1 | 0.2; k = 64 | 1024

## A dataset of {n} points is randomly projected.

::: part
answer: 4*ln(n)/(e^2/2 - e^3/3)
tolerance: 0.5%

### What dimension does the JL bound require at ε = {e}?

::: misses
- [4*log(n)/(e^2/2 - e^3/3)] Natural logarithm.
- [any] Not yet. $4\ln n/(\varepsilon^2/2 - \varepsilon^3/3)$.
:::
:::

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

### Projected to {k} dimensions, what's the typical relative spread of a squared length?

::: misses
- [1/sqrt(k)] Each term has variance 2.
- [any] Not yet. $\sqrt{2/k}$.
:::
:::

::: right
Right. The bound depends on the number of points and the accuracy, never on the original dimension.
:::
:::
:::
