ADS · End Term · Weeks 1–12

Algorithms for Data Science · End Term · Weeks 1–12

Three uses of randomness

Twelve weeks, one tool, three jobs. Randomness first makes computation cheap, then lets us prove that learning generalises, and finally becomes a shield that protects the people in the data. The concentration inequalities of Week 1 are the engine underneath all three.

The through-line

Prof. Rajkumar opens Week 1 by writing "Randomization as a tool to deal with Scale" on the board. He opens Week 7 by writing two more lines:

Probability → algorithmic toolWeeks 1–6
Probability → analysis toolWeeks 7–10

And Weeks 11–12 add a third: probability as a privacy tool. Nothing is discarded when the course turns — Hoeffding, the union bound, and the subset bound $A\subseteq B \Rightarrow P(A)\le P(B)$ do the load-bearing work in every unit, all the way to the last lecture.

W1–6 · Algorithmic

Exact is too expensive. Randomise the computation — a Gaussian matrix, a random hyperplane, a random sketch, a random edge sample — then use a tail bound plus a union bound to show the answer is right with high probability.

W7–10 · Analytical

The data itself is the random thing. Same Hoeffding, new question: does a train error measured on $n$ random points predict behaviour on data you have never seen? The union bound is again what makes it hold for a whole hypothesis class at once.

W11–12 · Protective

Noise on purpose. Inject a calibrated amount so the released statistic reveals the population but not the person. A single parameter $\epsilon$ dials between "useless and private" and "accurate and exposed".

Read this before planning your revision

The end term is not Quiz 2 with extra topics bolted on. Across the two available papers, Weeks 1–6 — the entire Quiz 2 syllabus — carry only about a quarter of the marks, and when they appear it is only ever the statements: the JL guarantee, the two LSH sensitivity conditions, $L=D-W$, Eckart–Young. No JL derivation, no randomized-SVD trace, no effective resistance.

Roughly two-thirds of the paper is statistical learning theory, and within that, VC dimension alone outweighs all of Weeks 1–6 combined. Both papers ask you to compute the VC dimension of a class you have never seen. Start at the solved end-term papers if you want the evidence before the argument.

What is actually examinable

UnitLecturesYou must be able to…
Concentration inequalitiesW1 L1–L5State each bound with its exact hypotheses; plug numbers in; know which is tightest and why; apply union & subset bounds
Johnson–LindenstraussW1 L6–L9, W2 L1–L3State the lemma on the dataset's pairs; know $M=R/\sqrt{k}$ and $k \in O(\log n/\epsilon^2)$, independent of $d$; know $a^\top r\sim\mathcal N(0,\|a\|^2)$
ANN & LSHW3 L1–L8Write the $(r,c,p_1,p_2)$ conditions in the right direction; TPR/FPR after AND and OR; know TPR $>$ FPR strictly
SVD & randomized SVDW4 L1–L5Eckart–Young and the $\sigma_{k+1}$ off-by-one; read a best rank-$k$ approximation off a given SVD
Spectral clusteringW5 L1–L3, W6 L1Build $W, D, L$; know $L\mathbf1=0$, PSD not PD, $\lambda_1=0$
Spectral sparsificationW6 L2–L4State the $(1\pm\epsilon)$ quadratic-form condition with $L_H$ in the middle
SLT: the setupW7 L1–L3Train vs test error; find $h^*$ by crossing densities; compute $\mathrm{er}_D^*$; state the three-way decomposition and the sign of each gap
Generalisation errorW8 L1–L2Unbiasedness; Hoeffding on $\{0,1\}$ losses; the $A\subseteq B$ trick; union bound; $n\ge\frac{1}{2\epsilon^2}\log\frac{2|H|}{\delta}$ and its monotonicity
VC dimensionW9 L1–L5Why $2^n$ kills the bound and $n^d$ saves it; the two-player game; derive a VC dimension for an unfamiliar class; the $H_{\mathrm{lin}}=d$ proof both ways
ERM, SRM, compressionW10 L1–L4ERM maximises accuracy and is NP-hard; the $\epsilon/2$ estimation bound; SRM's penalty; compression sizes $2$ and $4$
PrivacyW11–W12Randomized response and $P(Y=b\mid X)=p^{a}q^{f}$; the $e^\epsilon$ proof; $\epsilon$-DP and $(\epsilon,\delta)$-DP; sensitivity $\tfrac1n$; Laplace vs Gaussian; post-processing and composition; the exponential mechanism
How to use this page

Read a unit, then open its practice questions before looking at the answer — recall beats re-reading. Reveal all in the top bar opens every answer at once if you'd rather skim, and the page prints cleanly with all answers expanded.

If you are short on time, the ordering that matches the marks is: Unit 09 (VC dimension) → Unit 07 (the decomposition and Bayes) → Unit 10 (ERM numerics) → Unit 08 → Unit 11 (privacy — only randomized response has ever been asked numerically) → the Weeks 1–6 units for their statements only. The cheat sheet and traps list are the two things to re-read in the last thirty minutes.


Unit 01 · Week 1, Lectures 1–5

Concentration inequalities

Three bounds that say the same thing with increasing force: a random variable rarely strays far from its mean. They differ only in how much you're allowed to assume, and you pay for stronger assumptions with a tighter bound.

Markov's inequality

Theorem

If $X$ is a non-negative random variable and $a > 0$:

$$P(X \ge a) \;\le\; \frac{\mathbb{E}[X]}{a}$$

Non-negativity is not decoration — it is the whole proof. Drop it and the bound is false. Notice what Markov needs: only the mean. That is its strength (you almost always know the mean) and its weakness (it ignores everything about the shape).

The professor's die example

Fair die, $X \in \{1,\dots,6\}$, so $\mathbb{E}[X] = 21/6 = 3.5$.

Truth: $P(X \ge 5) = P(X \in \{5,6\}) = 2/6 = 0.33$.

Markov says: $P(X \ge 5) \le 3.5/5 = 0.7$.

Correct, and useless. $0.7$ vs. a true $0.33$ — Markov is loose. That looseness is exactly the motivation for Chebyshev.

The data-science framing he gives

Let $X$ = distance of a data point to its $k$-means cluster centre, with $\mathbb{E}[X] = 5$. "For a randomly picked point, what is the chance its distance to the centre is at least 20?"

$$P(X \ge 20) \;\le\; \frac{5}{20} \;=\; 0.25$$

Distances are non-negative, so Markov applies with no further assumptions. This is the pattern: you know an average, you want a tail.

Chebyshev's inequality

Markov cannot tell apart two variables with the same mean but wildly different spread — the professor draws exactly this: one number line with points scattered far, another with points hugging the mean, both with the same red mean marker. To separate them you need the variance.

Theorem

If $X$ has finite $\mathbb{E}[X]$ and finite variance $\sigma^2$, then for any $k > 0$:

$$P\big(|X - \mathbb{E}[X]| \ge k\sigma\big) \;\le\; \frac{1}{k^2}$$
Trap

The deviation is measured in units of $\sigma$, not in absolute units. $P(|X-\mu| \ge k\sigma) \le 1/k^2$, so if a question gives you an absolute threshold $t$, you must first set $k = t/\sigma$ and the bound is $\sigma^2/t^2$. Writing $1/t^2$ is the single most common slip here.

Also: this is a two-sided bound (the absolute value). Markov and the Hoeffding form below are one-sided.

Chebyshev decays like $1/k^2$ — polynomial. Better than Markov, still not fast. And it needs only one random variable, no independence.

Hoeffding's inequality

Now assume more: many variables, independent, each bounded. In exchange you get exponential decay.

Theorem

Let $X_1,\dots,X_n$ be independent with each $X_i \in [a,b]$, and let $\bar X = \frac{1}{n}\sum_{i=1}^n X_i$. Then for $t > 0$:

$$P\big(\bar X - \mathbb{E}[\bar X] \ge t\big) \;\le\; \exp\!\left(-\frac{2nt^2}{(b-a)^2}\right)$$

Read the exponent as a checklist of what helps you: $n$ up → bound shrinks (more samples, more concentration); $t$ up → bound shrinks (asking about a bigger deviation); $(b-a)$ up → bound grows (wider range, more room to wander).

Coin-toss example

Coin with bias $p$. Each $X_i \in [0,1]$ so $b - a = 1$ and $\mathbb{E}[\bar X] = p$:

$$P(\bar X - p \ge t) \;\le\; e^{-2nt^2}$$

With $t = 0.15$, the bound reaches $\approx 0.01$ around $n \approx 102$ — a hundred tosses already pin the empirical frequency to within $15\%$ with $99\%$ confidence.

Why the ranking is Markov < Chebyshev < Hoeffding

It is a trade of assumptions for decay rate. Nothing more.

BoundNeedsDecaySided
Markov$X \ge 0$; mean exists$1/a$ — harmonicone
Chebyshevfinite mean and variance$1/k^2$ — polynomialtwo
Hoeffdingindependent, bounded in $[a,b]$$e^{-2nt^2/(b-a)^2}$ — exponentialone (as stated)

Two utility inequalities

Small, and they carry the entire final step of the JL proof.

Union bound

Since $P(A \cup B) = P(A) + P(B) - P(A\cap B)$ and $P(A \cap B) \ge 0$:

$$P(A_1 \cup \cdots \cup A_n) \;\le\; \sum_{i=1}^{n} P(A_i)$$

No independence needed. That is precisely why it is usable — the $\binom{n}{2}$ pairwise-distortion events in JL are anything but independent.

Subset / implication inequality

If $A \subseteq B$ (equivalently $A \Rightarrow B$), then $P(A) \le P(B)$.

Used whenever you replace an event by a weaker, easier-to-bound one. In the Chernoff step, "$\|x\|^2 \ge c$" is rewritten as "$e^{\lambda\|x\|^2} \ge e^{\lambda c}$" — same event, monotone map, so equality actually holds; the inequality direction matters when the implication is strict.

Practice — Unit 01

MCQ
A non-negative random variable $X$ has $\mathbb{E}[X] = 4$. Which is the tightest guaranteed upper bound on $P(X \ge 16)$?
  • A$0.0625$
  • B$0.25$
  • C$0.5$
  • DCannot be determined without the variance
Answer — B

Markov: $P(X \ge 16) \le 4/16 = 0.25$. Option A is $(4/16)^2$ — the tempting move of "squaring because Chebyshev has a square", but you have no variance, so Chebyshev is unavailable. D is wrong because Markov needs only non-negativity and the mean, both of which you have.

NAT
$X$ has $\mathbb{E}[X] = 50$ and $\sigma = 5$. Using Chebyshev, what is the smallest upper bound you can state for $P(|X - 50| \ge 20)$? (Answer to 2 decimals.)
Answer — 0.06

Convert the absolute threshold into $\sigma$-units first: $k\sigma = 20 \Rightarrow k = 20/5 = 4$. Then $P \le 1/k^2 = 1/16 = 0.0625 \approx \mathbf{0.06}$.

The trap answer is $1/20^2 = 0.0025$, from forgetting to divide by $\sigma$.

MSQ
Which statements are true?
  • AMarkov's inequality can be applied to a random variable taking values in $[-3, 3]$.
  • BHoeffding's bound decreases as the number of samples $n$ increases, all else fixed.
  • CChebyshev's inequality requires the $X_i$ to be independent.
  • DFor a fixed deviation, Hoeffding's bound is tighter than Chebyshev's for large $n$.
Answer — B and D

A is false: Markov demands $X \ge 0$. (You could apply it to $X + 3$, but not to $X$.)

C is false: Chebyshev is a statement about a single random variable — no independence anywhere. Independence is Hoeffding's requirement.

D is true: $e^{-2nt^2}$ beats $\sigma^2/(nt^2)$ eventually, and "eventually" arrives fast.

NAT
You toss a fair coin $n$ times and want $P(\bar X - 0.5 \ge 0.1) \le 0.05$. Using Hoeffding, what is the smallest integer $n$ that guarantees this?
Answer — 150

Here $X_i \in [0,1]$ so $b-a=1$, and $t = 0.1$. Require $e^{-2n(0.01)} \le 0.05$, i.e. $-0.02n \le \ln 0.05 = -2.9957$, giving $n \ge 149.79$. So $n = \mathbf{150}$.

Note this is the one-sided form. If the question had asked for $P(|\bar X - 0.5| \ge 0.1)$, you would first union-bound the two tails to get $2e^{-2nt^2} \le 0.05$, and $n$ would rise to $185$.

MCQ
Events $A_1, \dots, A_{100}$ each have probability $0.001$. What can you say about $P(A_1 \cup \cdots \cup A_{100})$?
  • AIt equals $0.1$
  • BIt is at most $0.1$
  • CIt is at least $0.1$
  • DIt equals $1 - (0.999)^{100}$
Answer — B

Union bound gives $\le 100 \times 0.001 = 0.1$, and that is all you can say. A and D both assume something extra: D is the answer if the events were independent, which you were never told. This distinction is the entire reason the union bound is the tool of choice in the JL proof — the pairwise events there are dependent, and $1-(1-p)^m$ is not available.


Unit 02 · Week 1 L6–L9, Week 2 L1–L3

The Johnson–Lindenstrauss lemma

You can crush $n$ points from $\mathbb{R}^{10{,}000}$ down to $\mathbb{R}^{2000}$ and every pairwise distance survives to within $\pm 10\%$ — using a matrix you generate without ever looking at the data.

The lemma

Given $n$ points $D = \{x_1,\dots,x_n\} \subset \mathbb{R}^d$ and $\epsilon \in (0,1)$, there exists a linear map $f : \mathbb{R}^d \to \mathbb{R}^k$ with

$$k \in O\!\left(\frac{\log n}{\epsilon^2}\right)$$

such that for every pair $x_i, x_j \in D$:

$$(1-\epsilon)\|x_i - x_j\|^2 \;\le\; \|f(x_i) - f(x_j)\|^2 \;\le\; (1+\epsilon)\|x_i - x_j\|^2$$
The one line examiners test

$k$ depends on $\log n$ and $\epsilon$ — it does not depend on $d$ at all. The professor writes this in capitals on the slide. Any option claiming $k$ grows with $d$ is wrong; any option with $\log d$ is wrong.

The numbers he works out

$n = 10^6$, $d = 10{,}000$, $\epsilon = 0.1$ so $1/\epsilon^2 = 100$:

$$k = O\!\left(\frac{\log 10^6}{\epsilon^2}\right) = O\big(6\log 10 \times 100\big) \approx 20 \times 100 = 2000$$

Guarantee obtained: $0.9\|x-y\|^2 \le \|f(x)-f(y)\|^2 \le 1.1\|x-y\|^2$. A million points, $10{,}000 \to 2000$ dimensions, all $\approx 5\times10^{11}$ pairwise distances preserved to $\pm10\%$.

Read this as an order-of-magnitude illustration. It takes the constant inside the $O(\cdot)$ to be $1$ and uses $\log_2$; a different constant or a different log base moves the number substantially. That is exactly why the lemma is stated as $k \in O(\log n/\epsilon^2)$ — the scaling is the content, and the constant is not.

Step 1 — Why no exact isometry exists

An isometry is a norm-preserving map: $\|Ru\| = \|u\|$ for all $u$. Expand what that demands of $R \in \mathbb{R}^{k\times d}$:

$$\|Ru\|^2 = (Ru)^\top(Ru) = u^\top (R^\top R) u \;\stackrel{!}{=}\; u^\top u \quad\Longrightarrow\quad R^\top R = I_{d\times d}$$

Now read off what $R^\top R = I_d$ means. Writing $R$'s columns as $a_1,\dots,a_d \in \mathbb{R}^k$, the condition says those $d$ vectors are mutually orthonormal — $d$ orthonormal vectors living inside $\mathbb{R}^k$. Impossible when $k < d$: a $k$-dimensional space holds at most $k$ mutually orthogonal directions.

So?

Exact is off the table. Settle for an approximate isometry, and only for the $\binom{n}{2}$ distances we actually care about — not for all of $\mathbb{R}^d$. That restriction is what buys us everything.

Step 2 — The construction

The map

Let $R \in \mathbb{R}^{k\times d}$ have i.i.d. entries $r_{ij} \sim \mathcal{N}(0,1)$, and set

$$M = \frac{R}{\sqrt{k}}$$

That is the whole construction. No data is consulted.

Fix any $u \in \mathbb{R}^d$ (later $u$ will be a difference $x_i - x_j$). Look at one coordinate of $Ru$, namely $r_1^\top u = \sum_{i=1}^d r_{1i}u_i$.

Mean $$\mathbb{E}[r_1^\top u] = \sum_{i=1}^d \mathbb{E}[r_{1i}]\,u_i = 0$$
Variance $$\operatorname{Var}(r_1^\top u) = \mathbb{E}\big[(r_1^\top u)^2\big] = \sum_{i=1}^d \underbrace{\mathbb{E}[r_{1i}^2]}_{=1}u_i^2 \;+\; 2\!\!\sum_{j \ne l}\underbrace{\mathbb{E}[r_{1j}r_{1l}]}_{=\,\mathbb{E}[r_{1j}]\mathbb{E}[r_{1l}]\,=\,0}\!\!u_j u_l \;=\; \sum_i u_i^2 = \|u\|^2$$

The cross terms die because the entries are independent. That is the only place independence is used here.

So every coordinate of $Ru$ is an independent $\mathcal{N}(0, \|u\|^2)$ draw. We have $k$ samples from a zero-mean Gaussian whose variance is exactly the quantity we want. The natural estimator of that variance is the average of squares:

$$\widehat{\|u\|^2} \;=\; \frac{1}{k}\sum_{i=1}^k (r_i^\top u)^2 \;=\; \left\|\frac{R u}{\sqrt k}\right\|^2 = \|Mu\|^2$$
Where the $\sqrt{k}$ comes from

It is not a fudge factor. Dividing by $\sqrt{k}$ is precisely what turns "sum of $k$ squares" into "average of $k$ squares", which is the unbiased variance estimator. Hence $\mathbb{E}\big[\|Mu\|^2\big] = \|u\|^2$ — unbiased, exactly, for every $k$.

Step 3 — From unbiased to concentrated

Unbiased is not enough; we need the estimate to be close, not merely right on average. Standardise. Define

$$V = \tfrac{1}{\sqrt k}Ru \in \mathbb{R}^k, \qquad x = \frac{\sqrt{k}\,V}{\|u\|} \in \mathbb{R}^k \quad\Longrightarrow\quad \|x\|^2 = \frac{k\|V\|^2}{\|u\|^2}$$

A short computation gives $\mathbb{E}[x] = \vec 0$ and $\operatorname{Cov}(x) = I_{k\times k}$, so

$$x \sim \mathcal{N}(\vec 0, I_{k\times k}), \qquad \mathbb{E}\big[\|x\|^2\big] = \sum_{i=1}^k \mathbb{E}[x_i^2] = k$$

Now rewrite the bad event. Dividing by $\|u\|^2$ and multiplying by $k$:

$$P\Big(\|V\|^2 \ge (1+\epsilon)\|u\|^2\Big) \;=\; P\Big(\|x\|^2 \ge (1+\epsilon)k\Big)$$

We have reduced everything to one clean question: how far can the squared norm of a standard $k$-dimensional Gaussian stray above its own mean $k$?

Step 4 — Concentration

Unbiasedness alone is not enough — we need $\|Mu\|^2$ to concentrate around its mean. Applying a Chernoff-style bound to $\|x\|^2$ gives, for some positive constant $c$:

One-vector bound $$P\Big(\|Mu\|^2 \ge (1+\epsilon)\|u\|^2\Big) \;\le\; e^{-c\,k\epsilon^2}$$

A similar bound holds on the other side, for $(1-\epsilon)$. Increasing $k$ makes the bound tighter — that is the whole lever we have.

Step 5 — Union bound over all pairs, and out pops $k$

That bound is for one fixed vector. But we only care about the $\binom{n}{2}$ pairwise distances in $\mathcal{D}$. Let $E$ be the event that at least one pair is distorted beyond $1+\epsilon$:

$$E = \exists\,(x_i,x_j) \ \text{ s.t. } \ \|Mx_i - Mx_j\|^2 \ge (1+\epsilon)\|x_i-x_j\|^2$$

The events are dependent (they share the same $M$), so the union bound is the only tool available. With $\binom{n}{2} \le n^2$:

$$P(E) \;\le\; n^2 e^{-c\,k\epsilon^2}$$

Requiring this probability to be small gives an estimate for $k$, and in big-oh terms:

$$\boxed{\;k \in O\!\left(\frac{\log n}{\epsilon^2}\right)\;}$$

The lemma is proved. Read the shape of it: the $\log n$ comes from the union bound over $\sim n^2$ pairs, and the $\epsilon^{-2}$ from the $\epsilon^2$ sitting in the exponent.

On the constant $c$

The course notes deliberately leave $c$ unnamed, and the examinable statement is $k \in O(\log n/\epsilon^2)$ — every JL question on the two past papers turns on "$k$ does not depend on $d$" or on the $(1\pm\epsilon)$ distortion, never on the value of $c$.

If you want to see where it comes from: apply Markov to $e^{\lambda\|x\|^2}$, split over coordinates by independence, use the $\chi^2_1$ moment generating function $\mathbb{E}[e^{\lambda x_i^2}] = (1-2\lambda)^{-1/2}$, Taylor-expand, and minimise $2\lambda^2 - \lambda\epsilon$ over $\lambda$. That is a standard Chernoff argument and it pins $c$ to a specific number — but nothing in the lemma depends on which number.

Highlights the notes call out

  • The analysis is probabilistic, but the lemma asserts the existence of a deterministic $f$. Probability is the proof technique, not the conclusion.
  • To actually build $f$: keep drawing random $M$ until one works. Each draw succeeds with probability $\ge 1-\delta$, so you rarely need many.
  • $M$ is oblivious to the data — you only need $d$, $n$ and $\epsilon$ to generate it, never the points themselves. You can build the map before the dataset arrives.
  • Applying the map costs $O(ndk)$ — $n$ points, each a $k\times d$ matrix-vector product.
  • The win is real only when $d \gg \log n/\epsilon^2$. For small $d$, $k$ may exceed $d$ and there was nothing to reduce.

The linear-algebra reading

Take the SVD $M = U\Sigma V^\top$ with $M \in \mathbb{R}^{k\times d}$: $U$ is $k\times k$ orthonormal, $\Sigma$ is $k \times d$ "diagonal", $V^\top$ is $d\times d$ orthonormal. So $Mu$ is three moves:

  1. $V^\top$ — a random rotation in $\mathbb{R}^d$. Length preserved, direction randomised.
  2. $\Sigma$ — scale and truncate. Keep the first $k$ coordinates, scaled by $\sigma_1,\dots,\sigma_k$; discard the remaining $d-k$. This is the actual dimension reduction.
  3. $U$ — another rotation, now inside $\mathbb{R}^k$. Length preserved again.
Why the norm survives

A random rotation spreads a unit vector's mass evenly over all $d$ coordinates, so each entry of $V^\top u$ is $\approx 1/\sqrt d$. Meanwhile the singular values of $\frac{1}{\sqrt k}R$ all concentrate near $\sqrt{d/k}$ (within roughly $\pm 1$). Multiply: each surviving coordinate is $\approx \sqrt{d/k}\cdot 1/\sqrt{d} = 1/\sqrt k$. Summing $k$ of them:

$$\|Mu\|^2 \approx \underbrace{\tfrac1k + \cdots + \tfrac1k}_{k\ \text{terms}} = 1 = \|u\|^2$$

Truncating to $k$ coordinates loses almost nothing precisely because the rotation was random — no coordinate carried disproportionate mass. In high dimensions, a random direction is nearly orthogonal to any fixed direction, and mass is democratically distributed. That is the geometric heart of JL.

Geometrically: $M$ maps the unit sphere to an ellipsoid whose axis lengths are the singular values. Because those singular values are all nearly equal, the ellipsoid is nearly a sphere — and a nearly-spherical image is exactly what "approximate isometry" means.

Practice — Unit 02

MCQ
A dataset has $n = 10^4$ points in $\mathbb{R}^{50{,}000}$. A colleague adds $50{,}000$ more features (so $d$ doubles) but keeps $n$ the same. How does the JL target dimension $k$ change?
  • AIt doubles
  • BIt grows by $\log 2$
  • CIt is unchanged
  • DIt halves
Answer — C

$k \in O(\log n/\epsilon^2)$ has no $d$ in it. Doubling $d$ changes nothing about $k$; it only makes the reduction more worthwhile. What does change is the cost of applying the map, $O(ndk)$, which doubles.

NAT
A dataset grows from $n = 10^3$ to $n = 10^6$ points, with $\epsilon$ unchanged. By what factor does the JL target dimension $k$ grow?
Answer — 2

$k \in O(\log n/\epsilon^2)$, so the ratio is $\dfrac{\log 10^6}{\log 10^3} = \dfrac{6}{3} = \mathbf{2}$ (the base of the log cancels, and so does the unnamed constant).

A thousand-fold increase in data costs only a doubling of the embedding dimension — the $\log n$ is what makes JL practical at scale. The trap answer is $1000$, from reading $k$ as linear in $n$.

MSQ
About the JL map $M$ built from a random Gaussian matrix, which are true?
  • A$\mathbb{E}\big[\|Mu\|^2\big] = \|u\|^2$ for every $u$ and every $k$.
  • B$M$ must be recomputed if a new data point is added.
  • C$M^\top M = I_d$.
  • DThe lemma guarantees a map exists, though the construction is randomized.
Answer — A and D

Recall the construction: $M = \dfrac{R}{\sqrt k}$ with $R \in \mathbb{R}^{k\times d}$ and $R_{ij} \sim \mathcal N(0,1)$.

B is false: $M$ never depends on the data — only on $d$, $n$, $\epsilon$. (Strictly, $n$ enters through $k$, so adding enough points eventually nudges $k$; but no recomputation is triggered by the point's values, which is what the option claims.)

C is false: that is exactly the exact-isometry condition proved impossible for $k < d$.

A is true — unbiasedness is exact, not asymptotic. D is true — probabilistic method, deterministic conclusion.

MCQ
In the JL proof, why is the union bound used instead of $1-(1-p)^m$ for the $\binom{n}{2}$ pairwise events?
  • AThe union bound gives a tighter estimate
  • BThe pairwise distortion events are not independent
  • C$\binom{n}{2}$ is too large for the product formula to converge
  • DBecause the events are disjoint
Answer — B

All $\binom{n}{2}$ events are driven by the same random matrix $M$, so they are heavily dependent — the product formula is simply invalid. The union bound is looser (A is backwards) but it needs no independence, which is the entire point. D is wrong too: the events overlap freely.

MCQ
Halving $\epsilon$ from $0.2$ to $0.1$, with $n$ and $\delta$ fixed, multiplies the required $k$ by roughly:
  • A$2$
  • B$4$
  • C$\sqrt2$
  • D$\log 2$
Answer — B

$k \propto 1/\epsilon^2$, so halving $\epsilon$ quadruples $k$. Accuracy is expensive: the $\epsilon^{-2}$ dependence, not the $\log n$, is what usually makes $k$ large in practice.


Unit 03 · Week 3, Lectures 1–8

Approximate nearest neighbours & LSH

JL got the dimension down but the query still touches all $n$ points. To go sub-linear in $n$ you must stop measuring distances altogether — and instead build a hash that makes near points collide on purpose.

Why JL is not the answer here

ApproachPreprocessingPer query
Naive NN in $\mathbb{R}^d$—$O(nd)$
JL, then NN in $\mathbb{R}^k$$O(ndk)$$O(dk + nk)$
LSHbuild $L$ tables$O(n^\rho)$ with $\rho < 1$

The JL query cost is $O(dk)$ to project the query plus $O(nk)$ for $n$ distance computations. The $d$ shrank to $k$, but the $n$ is untouched — that is the term that hurts at a billion points. What survives from JL is only the intuition: close points map to close points. LSH pushes that idea to its extreme — instead of preserving distance, only preserve "same bucket or not".

The definition

$(r,c,p_1,p_2)$-sensitive hash family

A family $\mathcal{H}$ is $(r,c,p_1,p_2)$-sensitive, for $r > 0$, $c > 1$, $0 \le p_2 < p_1 \le 1$, if for any $x,y \in \mathbb{R}^d$ and a randomly chosen $h \in \mathcal{H}$:

$$\|x-y\| \le r \;\;\Longrightarrow\;\; \Pr_{h\sim\mathcal H}\big(h(x)=h(y)\big) \;\ge\; p_1 \qquad \textsf{[TPR]}$$ $$\|x-y\| \ge cr \;\;\Longrightarrow\;\; \Pr_{h\sim\mathcal H}\big(h(x)=h(y)\big) \;\le\; p_2 \qquad \textsf{[FPR]}$$

The randomness is over the choice of $h$, not over the data.

Trap — memorise the directions

Close $\Rightarrow$ collide a lot: $\;\le r$ pairs with $\ge p_1$. Far $\Rightarrow$ collide rarely: $\;\ge cr$ pairs with $\le p_2$. Flipping either inequality is the single most common error on this topic. Sanity check that always works: $p_1$ is the big probability and goes with the small distance.

Also note: nothing at all is asserted about the annulus $r < \|x-y\| < cr$. That grey ring is the price of approximation.

Language the professor uses throughout: points within $r$ are "good points" / neighbours / positives; points beyond $cr$ are "bad points" / strangers / negatives. So $p_1$ literally is the true positive rate and $p_2$ is the false positive rate of a single hash.

The hash family: Datar et al. (2004)

Euclidean ($p$-stable) LSH $$\mathcal{H}_w = \big\{h_{ab} : a \in \mathbb{R}^d,\; b \in [0,w]\big\}, \qquad h_{ab}(x) = \left\lfloor \frac{a^\top x + b}{w}\right\rfloor$$ $$a \sim \mathcal{N}(0, I_d), \qquad b \sim \mathrm{Unif}[0,w], \qquad w > 0 \text{ is the bucket width}$$

Read it geometrically: $a^\top x$ projects $x$ onto a random direction, $b$ shifts the ruler by a random offset, and $\lfloor\cdot/w\rfloor$ chops the line into intervals of length $w$. Two points collide iff their projections land in the same interval.

Collision probability — the derivation in four moves
  1. Condition on $a$. Write $\Delta = a^\top(x-y)$, the gap between the two projections on the line.
  2. Necessary condition. If $|\Delta| \ge w$ the two points can never share an interval of width $w$. So collision requires $|\Delta| < w$.
  3. Probability over $b$. Given $\Delta$, the random offset $b$ must fall in a sub-interval of length $w - |\Delta|$ out of $w$: $$\Pr_b\big(h(x)=h(y) \mid a\big) = \max\!\left(0,\; 1 - \frac{|\Delta|}{w}\right)$$
  4. Average over $a$. Since $a \sim \mathcal N(0,I_d)$, the scalar $\Delta = a^\top(x-y) \sim \mathcal{N}\big(0, \|x-y\|^2\big)$. Integrating: $$\Pr\big(h(x)=h(y)\big) = \frac{2}{\sqrt{2\pi}\,\|x-y\|}\int_0^\infty \max\!\left(0, 1-\frac tw\right) e^{-\frac{t^2}{2\|x-y\|^2}}\,dt$$
What you actually need from that integral

Not its closed form — the professor never evaluates it. Only that it is a monotonically decreasing function of $\|x-y\|$. Call it $f(\cdot)$. Then $p_1 = f(r)$ and $p_2 = f(cr)$, and since $cr > r$ and $f$ decreases, $p_2 < p_1$ automatically. That is the entire justification that $\mathcal H_w$ is a sensitive family.

Step 4 is also where the Gaussian is doing real work: a Gaussian $a$ makes $a^\top(x-y)$ a one-dimensional Gaussian whose variance is exactly $\|x-y\|^2$. The projection converts a $d$-dimensional distance into a one-dimensional spread — which is why this family is tuned to Euclidean distance specifically.

Trap

This is not random-hyperplane / cosine LSH. Do not substitute $1 - \theta/\pi$ into anything here. In the Datar family the hash output is an integer (a bucket index), not a bit, and the buckets are slabs, not wedges.

Cosine LSH — not lectured, but it has appeared on a paper

The 2025 T3 paper asked which picture matches cosine similarity, so know the contrast even though the lectures only derive the Euclidean family:

FamilyHashBuckets look likeCollision prob.
Euclidean (Datar) — taught$\big\lfloor\frac{a^\top x + b}{w}\big\rfloor$parallel slabs / stripes of width $w$decreasing in $\|x-y\|$
Cosine (SimHash)$\mathrm{sign}(a^\top x)$angular wedges through the origin$1 - \theta/\pi$

The discriminator: cosine similarity is scale-invariant ($x$ and $2x$ have similarity $1$), so its buckets must be cones through the origin. Euclidean distance is not scale-invariant, so its buckets are translation-covariant stripes. Concentric circles or squares are wrong for both — they bucket by norm, so two antipodal points on the same ring always collide despite being maximally far apart.

Why one hash is not enough — the professor's running example

$n = 10{,}000$, $r = 1$, $c = 2$, $p_1 = 0.8$, $p_2 = 0.4$

The query has $T = 10$ good points nearby and $B = 8000$ bad points far away.

  • Expected good points retrieved: $0.8 \times 10 = \mathbf{8}$ ✓
  • Expected bad points retrieved: $0.4 \times 8000 = \mathbf{3200}$ ✗

3208 points retrieved in total — worse than useless. Even though $p_2$ is "small", it is multiplied by a huge $B$. This is the entire motivation for what follows.

Step 1 — AND: crush the FPR

Concatenate $k$ independent hashes into one vector-valued hash:

$$g(x) = \big[h_1(x)\;\; h_2(x)\;\;\cdots\;\;h_k(x)\big], \qquad h_i \sim \mathcal H \text{ independently}$$

Two points collide under $g$ only if all $k$ coordinates match. By independence:

$$\mathrm{TPR} = p_1^k, \qquad \mathrm{FPR} = p_2^k$$
Choosing $k$

Expected number of false-positive collisions is $n\,p_2^k$. Set it to $1$ — a constant, independent of $n$:

$$n\,p_2^k = 1 \;\Longrightarrow\; p_2^k = \frac 1n \;\Longrightarrow\; \boxed{\;k = \frac{\log n}{\log(1/p_2)}\;}$$

In the example: $k = \log(10{,}000)/\log(1/0.4) \approx 10$.

The AND result — and its cost

$\mathrm{FPR} = (0.4)^{10} = 0.000105$  →  about $1$ bad point. Excellent.

$\mathrm{TPR} = (0.8)^{10} = 0.107$  →  $10 \times 0.107 \approx 1$ good point. Terrible.

We traded "finds the neighbour but retrieves 3208 points" for "retrieves 3 points but almost never finds the neighbour". Neither is acceptable.

Step 2 — OR: rescue the TPR

Build $L$ independent tables, each one an AND of $k$ hashes. Two points collide if at least one table matches. Taking complements and using independence across tables:

$$\Pr(\text{collide}) = 1 - \prod_{i=1}^{L}\Pr\big(g_i(x) \ne g_i(y)\big) = 1 - \big(1 - p^k\big)^L$$
Combined AND-then-OR $$\mathrm{TPR} = 1 - \big(1 - p_1^k\big)^L, \qquad \mathrm{FPR} = 1 - \big(1 - p_2^k\big)^L$$
00.25 0.50.75 1.0 00.51.0 base collision probability p retrieval probability p₂=0.4 p₁=0.8 k=10, L=20 k=10, L=1 k=1, L=1
The S-curve. A single hash (dashed) is a straight line — no separation. Pure AND (crimson) kills the FPR but drags the TPR down with it. AND-then-OR (teal) bends the curve into a step: at $p_2 = 0.4$ it reads $0.002$, at $p_1 = 0.8$ it reads $0.90$. $k$ sets where the step sits; $L$ sets how sharp it is.

The exponent $\rho$ — where sub-linearity comes from

Substitute the chosen $k = \log n/\log(1/p_2)$ into $p_1^k$:

$$p_1^k = \exp\!\left[\log n \cdot \frac{\log p_1}{\log(1/p_2)}\right] = \exp\!\left[\log n \cdot \left(-\frac{\log(1/p_1)}{\log(1/p_2)}\right)\right]$$
Definition and the key identity $$\rho \;:=\; \frac{\log(1/p_1)}{\log(1/p_2)} \qquad\Longrightarrow\qquad p_1^k = n^{-\rho}$$

Since $p_2 < p_1$, we have $\log(1/p_1) < \log(1/p_2)$, so $\rho < 1$ always.

Now choose $L = \theta n^{\rho}$ for a constant $\theta$. Then:

$$\mathrm{TPR} = 1 - \big(1 - n^{-\rho}\big)^{\theta n^{\rho}} = 1 - \Big[\big(1-n^{-\rho}\big)^{n^{\rho}}\Big]^{\theta} \;\xrightarrow[\;n\to\infty\;]{}\; \boxed{\;1 - e^{-\theta}\;}$$

using $(1 - 1/x)^x \to 1/e$. And for the FPR, since $p_2^k = 1/n$ by construction:

$$\mathrm{FPR} = 1 - \left(1 - \tfrac1n\right)^{L} \approx 1 - e^{-L/n} = 1 - e^{-\theta n^{\rho-1}} \approx \boxed{\;\theta\, n^{\rho-1}\;}$$

(the last step uses $1 - e^{-z}\approx z$ for small $z$, valid because $\rho < 1 \Rightarrow n^{\rho-1}\to 0$). Multiply the FPR by $n$ points to get the expected number of bad points retrieved:

$$\#\text{false positives} \approx n \cdot \theta n^{\rho-1} = \theta\, n^{\rho} \quad \text{— sub-linear, because } \rho < 1.$$
The example, finished ($\theta = 2$)

$\rho = \dfrac{\log(1/0.8)}{\log(1/0.4)} = 0.2435$, so $L = 2 \times (10{,}000)^{0.2435} \approx 2\times 10 = 20$ tables.

$\mathrm{TPR} = 1 - e^{-2} = 0.86$  →  $10 \times 0.86 \approx \mathbf{9}$ of the $10$ good points.

Bad points $\approx \theta n^{\rho} = \mathbf{20}$ of the $8000$.

ConstructionTPRFPRPoints retrieved
Single hash, $k=1, L=1$0.80.43208
Pure AND, $k=10, L=1$0.1070.00013
AND-then-OR, $k=10, L=20$0.860.00229
$\theta$ is a dial you can read off a table

$\theta=1 \Rightarrow$ TPR $=0.63$;   $\theta=2 \Rightarrow 0.86$;   $\theta=3 \Rightarrow 0.96$. Higher $\theta$ means more tables, more memory, more query work — and a better chance of finding the neighbour. That is the whole tuning story.

What $\rho$ controls, and how to make it small

  • Number of tables: $L = \theta n^\rho$. Larger $\rho$ → more tables → more query time and more storage.
  • FPR: $\theta n^{\rho-1}$. Larger $\rho$ → more junk retrieved.
  • Sub-linearity: $n^\rho \ll n$ precisely because $\rho < 1$. Everything hinges on this.

So you want $\rho$ small, which means you want the gap between $p_1$ and $p_2$ to be large. The performance of the whole algorithm is decided by the quality of the hash family — the professor's closing design principle for the week.

Tuning $w$ in practice

For the Datar family, $w$ controls bucket granularity: small $w$ → fine buckets, both probabilities drop; large $w$ → coarse buckets, both rise toward 1. Neither extreme separates. The recipe: sample a subset $D'$ of the data (say 100 points), empirically estimate $\hat p_1(w)$ and $\hat p_2(w)$ from observed collisions, form $\hat\rho(w)$, and grid-search $w$ for the smallest $\hat\rho(w)$.

Practice — Unit 03

MCQ
A family is $(2, 3, 0.7, 0.2)$-sensitive. Two points are at distance $5$. What does the definition guarantee about their collision probability?
  • AIt is at least $0.7$
  • BIt is at most $0.2$
  • CIt is between $0.2$ and $0.7$
  • DNothing is guaranteed
Answer — D

Compute both radii first: $r = 2$ and $cr = 3 \times 2 = 6$.

Distance $5$ satisfies neither condition — it is not $\le 2$, and it is not $\ge 6$. It lies strictly inside the annulus $r < 5 < cr$, and there the definition asserts nothing at all.

The trap: compare against $cr$, not against $c$. Reading "$c = 3$ and $5 \ge 3$" leads straight to B. Change the numbers and the answer moves: at distance $7 \ge 6$ it would be B, and at distance $1 \le 2$ it would be A. C is never right for any distance — each regime gives a one-sided bound, never a two-sided sandwich.

NAT
With $p_1 = 0.9$, $p_2 = 0.3$, compute $\rho$ to three decimals.
Answer — 0.088

$\rho = \dfrac{\log(1/0.9)}{\log(1/0.3)} = \dfrac{0.10536}{1.20397} = \mathbf{0.0875}$.

The base of the logarithm cancels — use whichever you like. Note how a wide $p_1/p_2$ gap gives a tiny $\rho$, hence very few tables: $L = \theta n^{0.0875}$ is almost constant.

MSQ
Increasing $k$ (the number of AND-ed hashes), holding $L$ fixed:
  • Adecreases the FPR
  • Bdecreases the TPR
  • Cincreases the number of hash tables
  • Dmakes collisions harder
Answer — A, B and D

AND requires all $k$ coordinates to match, so collisions get strictly harder — both $p_1^k$ and $p_2^k$ shrink. C confuses the two knobs: $k$ is the depth of each table, $L$ is the number of tables. Increasing $k$ does not change $L$.

The mnemonic: AND ↓ both rates (fixes FPR, damages TPR). OR ↑ both rates (fixes TPR, damages FPR). You need both, in that order.

NAT
A dataset has $n = 10^6$ points and the family has $p_2 = 0.5$. Choose the number of AND-ed hashes $k$ so that the expected number of false-positive collisions is $1$. (Use base-2 logarithms.)
Answer — 20

Setting $n\,p_2^k = 1$ and solving gives the standard choice

$$k = \frac{\log n}{\log(1/p_2)}$$

$\log_2(10^6) = 6\log_2 10 = 6 \times 3.3219 = 19.93$, and $\log_2(1/0.5) = 1$. So $k = 19.93 \approx \mathbf{20}$.

Check it does what it is supposed to: $n\,p_2^k = 10^6 \times 2^{-20} = 10^6/1{,}048{,}576 \approx 0.95 \approx 1$. ✓ The choice of $k$ is precisely "make expected false-positive collisions equal to one".

MCQ
In the tuned AND-then-OR construction, the number of tables is chosen to scale as a power of $n$. What does the resulting true positive rate depend on?
  • ATPR improves as $n$ grows
  • BTPR is independent of $n$ and controlled entirely by $\theta$
  • CTPR degrades as $n$ grows
  • DTPR depends only on $\rho$
Answer — B

With $L = \theta n^{\rho}$ and $p_1^k = n^{-\rho}$, the rate collapses to $\mathrm{TPR} = 1 - (1-n^{-\rho})^{\theta n^{\rho}} \approx 1 - e^{-\theta}$.

The $n$ cancels exactly — that is the point of choosing $L$ proportional to $n^\rho$. You get a fixed recall guarantee that does not degrade as the dataset grows, and you pay for it in $n^\rho$ tables rather than $n$ distance computations. $\rho$ governs cost and FPR, $\theta$ governs recall.

MSQ
About the Datar-style hash family used for Euclidean LSH, which are true?
  • AEach bucket is a slab (a region between two parallel hyperplanes) in $\mathbb{R}^d$.
  • BBuckets are convex regions.
  • CIncreasing $w$ increases the collision probability for every pair.
  • DThe collision probability depends on $x$ and $y$ only through $\|x-y\|$.
Answer — A, B, C and D (all four)

The family is $h_{ab}(x) = \left\lfloor \dfrac{a^\top x + b}{w}\right\rfloor$ with $a \sim \mathcal N(0, I_d)$ and $b \sim \mathrm{Unif}[0,w]$.

A, B: the pre-image of a fixed integer is $\{x : jw \le a^\top x + b < (j+1)w\}$ — the region between two parallel hyperplanes with normal $a$. An intersection of two half-spaces, hence convex.

C: the conditional probability $\max(0, 1-|\Delta|/w)$ increases in $w$ for every $\Delta$, so the average does too. Wider buckets, more collisions — for good and bad pairs alike, which is why $w$ must be tuned via $\hat\rho(w)$ rather than simply maximised.

D: $\Delta \sim \mathcal N(0, \|x-y\|^2)$ depends on the pair only through that norm. The collision probability is rotation- and translation-invariant.

NAT
$n = 10^4$, $p_1 = 0.8$, $p_2 = 0.4$, $k = 10$, $L = 20$. What is the expected number of bad points retrieved if there are $8000$ bad points? (Nearest integer.)
Answer — 17

Exact: $\mathrm{FPR} = 1 - (1 - 0.4^{10})^{20}$. Since $0.4^{10} = 1.0486\times10^{-4}$, this is $\approx 20 \times 1.0486\times10^{-4} = 2.097\times10^{-3}$. Times $8000$ gives $\mathbf{16.8 \approx 17}$.

The professor's slide quotes $\approx 20$, using the cleaner asymptotic $\theta n^{\rho} = 2 \times 10^{0.2435\times4} \approx 20$, which counts against all $n = 10^4$ points rather than only the $8000$ bad ones. Both are right at this level of precision — but if a paper gives you exact $k$, $L$ and a bad-point count, compute directly from $1-(1-p_2^k)^L$.


Unit 04 · Week 4, Lectures 1–5

SVD & randomized SVD

Exact SVD costs $O(mn^2)$. Randomized SVD gets you a near-optimal rank-$k$ approximation for $O(mn\ell)$ with $\ell = k+p$ — and the whole trick is that a random sketch of a matrix lands, with high probability, in the subspace that matters.

Notation

Following the course notes, $A \in \mathbb{R}^{m\times n}$ with $m > n$ — $m$ data points down the rows, $n$ features across the columns. (The handwritten lecture slides write $d$ for the column count; same object, read $n \leftrightarrow d$.) Track shapes obsessively — almost every SVD exam question is really a shape question.

SVD: the statement

Decomposition $$A_{\,m\times n} = U_{\,m\times m}\;\Sigma_{\,m\times n}\;V^\top_{\,n\times n}$$
  • $U, V$ are orthogonal; columns of $U$ are left singular vectors, columns of $V$ are right singular vectors.
  • $\Sigma$ carries $\sigma_1 \ge \sigma_2 \ge \cdots \ge \sigma_n \ge 0$ on the diagonal, zeros elsewhere (including the bottom $m-n$ rows).
  • If $\mathrm{rank}(A) = r$ then $\sigma_1 \ge \cdots \ge \sigma_r > 0 = \sigma_{r+1} = \cdots$.
  • $Av_i = \sigma_i u_i$ and $A^\top u_i = \sigma_i v_i$ for $1 \le i \le r$.

Read $Aw = U\Sigma(V^\top w)$ as three moves: rotate by $V^\top$, scale coordinate-wise by $\Sigma$, rotate by $U$ — the same decomposition you met in the JL linear-algebra lecture.

Two identities that get examined constantly $$A^\top A = V\Sigma^2 V^\top \qquad\text{($n\times n$)}, \qquad\qquad AA^\top = U\Sigma^2 U^\top \qquad\text{($m\times m$)}$$

So: eigenvectors of $A^\top A$ are the right singular vectors; eigenvectors of $AA^\top$ are the left singular vectors; the eigenvalues of both are $\sigma_i^2$. Singular values are the square roots of those eigenvalues, never the squares.

Rank-1 expansion and spectral norm $$A = \sum_{i=1}^{n}\sigma_i u_i v_i^\top, \qquad \|A\|_2 := \sigma_{\max}(A) = \sigma_1$$
Best rank-$k$ approximation (Eckart–Young)

Among all matrices $B$ of rank $k$, the minimiser of $\|A - B\|_2$ is obtained by truncating the SVD sum:

$$B^\star = \sum_{i=1}^{k}\sigma_i u_i v_i^\top = U_k\Sigma_k V_k^\top, \qquad \|A - B^\star\|_2 = \sigma_{k+1}$$

The error you pay is exactly the first singular value you threw away. The professor states only the spectral-norm ($\|\cdot\|_2$) version — that is what is in scope.

Applications actually taught

PCA

The covariance/scatter matrix is $A^\top A$ ($n\times n$), whose eigenvectors are $V$. Projecting $a_i \mapsto [a_i^\top v_1, \dots, a_i^\top v_k] \in \mathbb{R}^k$ gives the top-$k$ principal components. PCA is SVD.

Recommender systems

A ratings matrix $A_{m\times n}$ (users × movies), mostly missing, factorised as $A = B_{m\times k}C_{k\times n}$ with $k \ll n$. A row of $B$ is a user's latent taste vector; a column of $C$ is a movie's latent profile. This is matrix completion.

The unifying idea: "data lies near a low-dimensional subspace" and "the matrix is approximately low rank" are the same sentence.

Fast SVD — what an oracle for $u_1,\dots,u_k$ buys you

Suppose someone hands you $Q = [u_1 \cdots u_k] \in \mathbb{R}^{m\times k}$, the top $k$ left singular vectors. Then $QQ^\top$ is the projection onto their span, and:

$$\big(QQ^\top\big)A \;=\; \text{the best rank-}k\text{ approximation of }A, \qquad \big\|A - QQ^\top A\big\|_2 = \sigma_{k+1}$$
Fast SVD, given $Q$
  1. $B = Q^\top A$   — shapes $(k\times m)(m\times n) = k \times n$. This is the compression step.
  2. $\mathrm{SVD}(B) = \tilde U \tilde\Sigma \tilde V^\top$   — cost $O(nk^2)$, because $B$ is tiny.
  3. Pull back: $\hat U = Q\tilde U$,  $\hat\Sigma = \tilde\Sigma$,  $\hat V = \tilde V$.
  4. $\hat A = \hat U\hat\Sigma\hat V^\top = QQ^\top A$.

Cost drops from $O(mn^2)$ to $O(nk^2)$ for the decomposition itself — you do the expensive SVD on a $k\times n$ matrix instead of an $m\times n$ one.

The realisation that makes randomization possible

Look at what the algorithm actually used: only that $Q$ has orthonormal columns and that $\operatorname{span}(Q) = \operatorname{span}(u_1,\dots,u_k)$. The individual vectors never mattered — only the subspace. And $\operatorname{span}(u_1,\dots,u_k)$ sits inside the column space of $A$. So if we can cheaply grab any orthonormal basis for roughly the right subspace of $\mathrm{col}(A)$, we are done. That is what a random sketch does.

Randomized SVD

Draw $\omega \sim \mathcal N(\vec 0, I_n)$. Then $A\omega = \sum_i \omega_i a_i$ is a random linear combination of the columns of $A$, and:

$$\mathbb{E}[A\omega] = A\,\mathbb{E}[\omega] = \vec 0, \qquad \operatorname{Cov}(A\omega) = A\,\mathbb{E}[\omega\omega^\top]A^\top = AA^\top$$
Why this captures the dominant subspace

The sketch vector is a zero-mean Gaussian with covariance $AA^\top$ — and the eigenvectors of $AA^\top$ are precisely $u_1,\dots,u_m$, with eigenvalues $\sigma_i^2$. A Gaussian spreads most of its mass along its high-variance directions. So samples $A\omega$ preferentially align with the top singular directions, weighted by $\sigma_i^2$. Draw $\ell$ of them and their span is, with high probability, close to $\operatorname{span}(u_1,\dots,u_\ell)$.

Equivalently, in the rank-1 expansion $A\omega = \sum_i \sigma_i u_i (v_i^\top \omega)$: the coefficients $v_i^\top\omega$ are i.i.d. $\mathcal N(0,1)$ — no direction is favoured by the randomness — so the $\sigma_i$ alone decide which $u_i$ dominate.

The algorithm — shapes and costs

Input $A \in \mathbb{R}^{m\times n}$, target rank $k$, oversampling $p$, and $\ell = k + p \;(\ll m, n)$.

StepOperationResult shapeCost
1Draw $\Omega$ with $\omega_i \sim \mathcal N(\vec0, I_n)$$n \times \ell$$O(n\ell)$
2Sketch: $Y = A\Omega$$m \times \ell$$O(mn\ell)$
3Orthonormalise: $Q = \mathrm{orth}(Y)$ (QR / Gram–Schmidt)$m \times \ell$$O(m\ell^2)$
4Project: $B = Q^\top A$$\ell \times n$$O(mn\ell)$
5Small SVD: $B = \tilde U\tilde\Sigma\tilde V^\top$$\tilde U$ is $\ell\times\ell$$O(n\ell^2)$
6Pull back: $\hat U = Q\tilde U_k$, $\hat\Sigma = \tilde\Sigma_k$, $\hat V = \tilde V$$\hat U$ is $m\times k$$O(m\ell k)$
Total cost $$O(mn\ell) \quad\text{versus naive}\quad O(mn^2), \qquad \ell = k+p \ll n$$

The win is $n^2 \to n\ell$. Steps 2 and 4 dominate; everything else is lower order.

How good is it?

Start from the ideal case. If $QQ^\top$ were exactly $U_kU_k^\top$, we already know the answer: $\|A - QQ^\top A\|_2 = \sigma_{k+1}$. But $Q$ comes from a random sketch, so we only have an approximation — and the guarantee becomes probabilistic.

Error guarantee

With probability at least $1-\delta$:

$$\big\|A - QQ^\top A\big\|_2 \;=\; \sigma_{k+1}\,(1+\epsilon)$$

where $\epsilon$ is an error term depending on $\delta$, $k$ and $p$ — not on $m$ or $n$.

Compare to the benchmark: the best possible rank-$k$ error is exactly $\sigma_{k+1}$, so you land within a $(1+\epsilon)$ factor of optimal. The professor's illustration: if $\epsilon = 1$ then $\|A - QQ^\top A\| \le 2\sigma_{k+1}$ — within a factor of two of the best any rank-$k$ matrix can achieve.

Why oversampling $p > 0$ is not optional

$\epsilon$ shrinks as $p$ grows, and blows up as $p \to 0$. The reason is geometric: with $\ell = k$ exactly, the $k$ random vectors must span the top-$k$ subspace perfectly — one unlucky draw nearly parallel to another and the sketch misses a direction outright. A handful of spare columns gives it room to fail on a few directions and still cover the subspace.

Practical values: $p = 5$ or $p = 10$ works quite well. And $\delta$ enters only logarithmically, so very high confidence is very cheap.

Subspace quality (Davis–Kahan) $$\big\|QQ^\top - U_kU_k^\top\big\|_2 \;\lesssim\; \frac{\sigma_{k+1}(A)}{\sigma_k(A)}$$

The recovered subspace is good exactly when the spectral gap at $k$ is large. If $\sigma_{k+1}/\sigma_k \approx 1$ — a flat spectrum — the sketch cannot tell direction $k$ from direction $k+1$, and the method struggles. (Written "Davidson–Kahan" on the slide.)

Power iteration — fixing a flat spectrum

If the singular values decay slowly, manufacture a gap. The algebra:

$$AA^\top = U\Sigma^2U^\top \quad\Longrightarrow\quad (AA^\top)A = U\Sigma^3V^\top \quad\Longrightarrow\quad (AA^\top)^qA = U\,\Sigma^{2q+1}\,V^\top$$

Same singular vectors, singular values raised to $2q+1$. Ratios are driven toward zero geometrically:

$$\left(\frac{\sigma_{k+1}}{\sigma_k}\right) \;\longrightarrow\; \left(\frac{\sigma_{k+1}}{\sigma_k}\right)^{2q+1}$$
The professor's number

A mediocre ratio of $0.9$ with $q=1$ (so $2q+1=3$): $0.9^3 = 0.729$. With $q=3$: $0.9^7 = 0.478$. Each power step compounds the separation.

Never form $AA^\top$ explicitly

$AA^\top$ is $m\times m$ — for a million rows that is a $10^{12}$-entry matrix, and forming it costs $O(m^2d)$. Instead alternate multiplications by $A^\top$ and $A$, re-orthonormalising each time for numerical stability.

Randomized SVD with power iteration
  1. $Y = A\Omega$   $O(mn\ell)$
  2. for $i = 1 \dots q$:
    • $Q = \mathrm{orth}(Y)$   $m\times\ell$
    • $Z = A^\top Q$   $n\times\ell$
    • $Y = AZ$   $m\times\ell$ — net effect $Y = (AA^\top)Q$
  3. $Q = \mathrm{orth}(Y)$, then $B = Q^\top A$, $\;\mathrm{SVD}(B) = \tilde U\tilde\Sigma\tilde V^\top$, $\;\hat U = Q\tilde U$, $\;\hat A = \hat U\hat\Sigma\hat V^\top$.

Loop cost $O(mn\ell q)$. The improved guarantees:

$$\big\|QQ^\top - U_kU_k^\top\big\|_2 \le \left(\frac{\sigma_{k+1}}{\sigma_k}\right)^{2q+1}, \qquad \big\|A - QQ^\top A\big\|_2 \le \big(1 + \epsilon^{1/(2q+1)}\big)\sigma_{k+1}$$

Practice — Unit 04

MCQ
$A \in \mathbb{R}^{5000 \times 200}$. What is the shape of the middle factor $\Sigma$ in the full SVD of $A$?
  • A$200 \times 200$
  • B$5000 \times 5000$
  • C$5000 \times 200$
  • D$200 \times 5000$
Answer — C

The full SVD is $A = U\Sigma V^\top$, and $\Sigma$ has the same shape as $A$: $U$ is $5000\times5000$, $\Sigma$ is $5000\times200$, $V^\top$ is $200\times200$. Only the top $200\times200$ block of $\Sigma$ is non-zero; the bottom $4800$ rows are all zeros. Option A is the shape in the thin/economy SVD — a real distinction, so read which one the question asks for.

MSQ
$A \in \mathbb{R}^{m\times n}$ with $m > n$. Which are true?
  • AThe eigenvalues of $A^\top A$ are the squares of the singular values of $A$.
  • B$AA^\top$ and $A^\top A$ have the same non-zero eigenvalues.
  • CThe left singular vectors are the eigenvectors of $A^\top A$.
  • D$\|A\|_2 = \sigma_1$.
Answer — A, B and D

C is false — and it is the classic swap. $A^\top A = V\Sigma^2V^\top$ gives the right singular vectors; $AA^\top = U\Sigma^2U^\top$ gives the left ones. Mnemonic: "$A^\top A$ is $n\times n$, lives in feature space, gives $V$."

B is true: both equal $\{\sigma_i^2 : \sigma_i > 0\}$; they differ only in how many extra zeros they carry ($AA^\top$ has $m-n$ more).

NAT
$A$ has singular values $10, 8, 6, 3, 1$. What is $\min_{\mathrm{rank}(B)=3}\|A - B\|_2$?
Answer — 3

Eckart–Young: the error is $\sigma_{k+1}$ with $k = 3$, so $\sigma_4 = \mathbf{3}$.

Traps: $\sigma_3 = 6$ (off-by-one — the error is the first value you discard, not the last you keep) and $\sqrt{3^2+1^2} = \sqrt{10}$ (that would be the Frobenius-norm error, a different theorem that this course does not state).

NAT
In randomized SVD with $k = 20$ and oversampling $p = 5$, what is the shape of $B = Q^\top A$ when $A \in \mathbb{R}^{10^6 \times 5000}$? Give the number of rows.
Answer — 25

$\ell = k + p = 25$, so $Q$ is $10^6 \times 25$ and $B = Q^\top A$ is $\mathbf{25} \times 5000$. That is the entire point: you run an exact SVD on a $25\times5000$ matrix rather than a $10^6\times5000$ one.

Note $B$ has $\ell$ rows, not $k$. The truncation to $k$ happens later, at the pull-back step.

MCQ
Your matrix has a nearly flat singular-value spectrum ($\sigma_{k+1}/\sigma_k \approx 0.98$). Which change helps most?
  • AIncrease the oversampling parameter $p$
  • BApply $q$ steps of power iteration
  • CDecrease $\ell$
  • DUse a uniform instead of Gaussian $\Omega$
Answer — B

A flat spectrum is precisely the failure mode Davis–Kahan predicts: $\|QQ^\top - U_kU_k^\top\| \lesssim \sigma_{k+1}/\sigma_k \approx 0.98$, i.e. no guarantee at all. Power iteration replaces that ratio with $0.98^{2q+1}$ — with $q = 10$, $0.98^{21} = 0.65$. Oversampling (A) helps the probability of a good sketch but does nothing about an intrinsically indistinguishable spectrum.

MSQ
Which statements about randomized SVD are correct?
  • A$Q$ has orthonormal columns spanning approximately the top-$\ell$ left singular subspace.
  • BThe sketch $Y = A\Omega$ takes random linear combinations of the rows of $A$.
  • CTotal cost is $O(mn\ell)$, better than the naive $O(mn^2)$ since $\ell \ll n$.
  • DSetting $p = 0$ still gives the stated $(1+\epsilon)$ guarantee.
Answer — A and C

B is false: $A\Omega$ combines columns — $A\omega = \sum_i \omega_i a_i$ where $a_i$ are columns. (Row combinations would be $\Omega^\top A$.)

D is false: the error term $\epsilon$ degenerates as $p \to 0$ — with $\ell = k$ exactly there is no slack in the sketch. Oversampling is structurally required, not a tuning nicety.

NAT
With $q = 2$ power iterations, by what power is the gap ratio $\sigma_{k+1}/\sigma_k$ raised in the subspace bound?
Answer — 5

$(AA^\top)^qA = U\Sigma^{2q+1}V^\top$, so the exponent is $2q+1 = 2(2)+1 = \mathbf{5}$.

Common slips: answering $2q = 4$, or $q = 2$. Remember the odd power comes from the trailing single $A$ — $q$ full "squarings" plus one.


Unit 05 · Week 5 L1–L3, Week 6 L1

Spectral clustering

k-means can only carve the plane into straight-edged convex cells. Two interlocking moons defeat it. The fix: rebuild the data as a graph, ask for a cheap cut, and discover that the answer is an eigenvector.

Why k-means fails

Lloyd's algorithm alternates two steps — centroid computation and cluster re-assignment — and the partition it produces is always a Voronoi diagram of the centroids. Every cell is therefore convex: for any two points in a cell, the whole segment between them stays in the cell.

The consequence

A crescent is not convex — draw a segment between its two tips and it exits the shape. So a crescent can never be a k-means cell, no matter the initialisation, no matter how long you run it. Two moons, or a ring around a blob, are structurally out of reach. This is not a convergence problem; it is a representational one.

Note the deeper issue: on the two-moons data, the two facing tips of opposite moons are Euclidean-close while the two ends of the same moon are Euclidean-far. Raw distance is the wrong notion of similarity. What we want is connectedness — and that is a graph question.

Building the graph

Similarity graph $G = (V, E, W)$

One node per data point. Edge weights from the Gaussian (RBF) kernel:

$$w_{ij} = \exp\!\left(-\frac{\|x_i - x_j\|^2}{2\sigma^2}\right)$$

with $\sigma$ a hyperparameter. Weight is inversely related to distance: nearby points get weight near $1$, far points near $0$ — but never exactly $0$, so this graph is fully dense. (The scalable alternative, used in Week 6: a $k$-NN graph.)

Degree matrix $D$ is diagonal with $D_{ii} = \sum_j w_{ij}$.

Cuts

Cut weight

A cut is just a subset $A \subseteq S$ of nodes. Its weight is the total weight of edges crossing to the other side:

$$\mathrm{cut}(A, S\setminus A) = \sum_{i \in A,\; j \in S\setminus A} w_{ij}$$

Clustering becomes: cut the graph into two pieces so that as little weight as possible crosses. Points in different clusters should be far apart, hence joined by low weights, hence cheap to cut.

A = {3, 6} 124 563 crimson edges cross the cut · cut(A, Aᶜ) = 2
The professor's six-node example: $E = \{\{1,2\},\{2,6\},\{2,4\},\{3,6\},\{3,5\},\{4,5\}\}$, all weights $1$. Cutting off $\{3,6\}$ severs exactly the edges $\{2,6\}$ and $\{3,5\}$, so the cut value is $2$.

From cut to quadratic form

Encode the partition as a binary vector: $f_i = 1$ if $i \in A$, else $0$. Then

$$\mathrm{cut}(A, S\setminus A) = \sum_{i,j} f_i(1-f_j)w_{ij}$$
The derivation of $L = D - W$ — know this line by line $$\begin{aligned} \sum_{i,j} f_i(1-f_j)w_{ij} &= \sum_{i,j} f_i w_{ij} \;-\; \sum_{i,j} f_i f_j w_{ij}\\ &= \sum_i f_i\Big(\textstyle\sum_j w_{ij}\Big) \;-\; f^\top W f\\ &= f^\top D f \;-\; f^\top W f \qquad \text{(using } f_i^2 = f_i \text{ for binary } f)\\ &= f^\top (D - W) f \;=\; f^\top L f \end{aligned}$$
The graph Laplacian $$L = D - W, \qquad D_{ii} = \sum_j w_{ij}$$

Off-diagonal $L_{ij} = -w_{ij}$; diagonal $L_{ii} = \sum_j w_{ij}$. Every row sums to zero.

The quadratic-form identity $$f^\top L f = \sum_{(i,j) \in E} w_{ij}\,(f_i - f_j)^2$$

The course notes write this as $f^\top Lf = \sum_{i,j} w_{ij}(f_i-f_j)^2$. Read that sum over edges (each unordered pair once), which is what the lecture slides do explicitly. If you instead run $i$ and $j$ over all ordered pairs, every edge is counted twice and you need a $\tfrac12$ out front. When computing a cut by hand, sum over edges — it is the reading that matches the answer.

Three facts fall straight out of this identity:

  • $L$ is positive semi-definite — the right side is a sum of non-negative terms whenever $w_{ij} > 0$. So all eigenvalues are $\ge 0$.
  • $\lambda_1 = 0$ with eigenvector $\mathbf{1}$ — plug $f = \mathbf 1$: every $(f_i - f_j) = 0$. Equivalently, $L\mathbf 1 = 0$ because each row sums to zero.
  • It measures smoothness — $f^\top Lf$ is small when $f$ takes similar values at heavily connected pairs. The Laplacian penalises disagreement across strong edges.
Worked: build $L$ for the six-node graph

Degrees: $\deg(1)=1$, $\deg(2)=3$, $\deg(3)=2$, $\deg(4)=2$, $\deg(5)=2$, $\deg(6)=2$. So $D = \mathrm{diag}(1,3,2,2,2,2)$ and

$$L = \begin{bmatrix} 1 & -1 & 0 & 0 & 0 & 0\\ -1 & 3 & 0 & -1 & 0 & -1\\ 0 & 0 & 2 & 0 & -1 & -1\\ 0 & -1 & 0 & 2 & -1 & 0\\ 0 & 0 & -1 & -1 & 2 & 0\\ 0 & -1 & -1 & 0 & 0 & 2 \end{bmatrix}$$

Verify the cut for $A = \{1,2,4,5\}$, i.e. $f = (1,1,0,1,1,0)^\top$. Using the identity, only edges with differing endpoints contribute: $\{2,6\}$ gives $(1-0)^2 = 1$, $\{3,5\}$ gives $(0-1)^2 = 1$, all others give $0$. So $f^\top Lf = \mathbf{2}$ — matching the direct edge count. ✓

Now the problem: $A = \{1\}$ gives a cut of just $\mathbf{1}$, the smallest possible non-zero value. Plain mincut wants to peel off the single least-connected vertex. That is a useless clustering.

Killing the degenerate solutions

Written as an optimisation, $\min_{f\in\{0,1\}^n} f^\top Lf$ is broken twice over:

  • $f = \mathbf 0$ and $f = \mathbf 1$ both give $0$ — "everything in one cluster", not a cut at all.
  • Even excluding those, the binary problem is NP-hard.

The route taken is to add two constraints and then relax:

The relaxed problem $$\min_{f} \; f^\top L f \qquad \text{s.t.}\quad f \in \mathbb{R}^n, \quad \|f\|^2 = 1, \quad f^\top \mathbf{1} = 0$$
  • $\|f\|^2 = 1$ rules out the all-zeros solution and fixes the scale.
  • $f^\top\mathbf 1 = 0$ forces $f$ orthogonal to the all-ones vector, ruling out the trivial $\mathbf 1$ direction.
  • $f \in \mathbb{R}^n$ instead of $\{0,1\}^n$ is the relaxation — it turns an NP-hard combinatorial problem into an eigenvalue problem.
The solution

Order the eigenpairs of $L$ by eigenvalue: $(\lambda_1, f_1), (\lambda_2, f_2), \dots$ with $\lambda_1 = 0$ and $f_1 = \tfrac{1}{\sqrt n}\mathbf 1$. Then

$$\min_{\|f\|=1,\, f\perp\mathbf 1} f^\top Lf = \lambda_2, \qquad \arg\min = f_2$$

$f_2$ — the eigenvector of the second-smallest eigenvalue — is the Fiedler vector.

Why "second"

Unconstrained, the minimiser of $f^\top Lf$ over unit vectors is the eigenvector of the smallest eigenvalue — which is $\mathbf 1$ at $\lambda_1 = 0$, the degenerate answer. The constraint $f \perp \mathbf 1$ deletes exactly that direction, so the minimum over what remains is the next eigenpair. The constraint and the "second smallest" are the same fact stated twice.

Recovering a clustering from the real-valued $f^\star$: threshold it (the professor suggests $0.5$), or run 1-D k-means on the values $\{f^\star_1,\dots,f^\star_n\}$.

More than two clusters

Take the first $k$ eigenvectors after the trivial one — $f_2, f_3, \dots, f_{k+1}$ — stack them as columns, and read off row $i$ as the embedding of point $x_i$:

$$x_i \;\longmapsto\; f_{x_i} = \big[f_{2,i}\;\; f_{3,i}\;\;\cdots\;\;f_{k+1,i}\big] \in \mathbb{R}^k, \qquad v_i = \frac{f_{x_i}}{\|f_{x_i}\|}$$
Each eigenvector is a "view"

$f_2$ is the single best way to split the graph in two. $f_3$ is the next-best split orthogonal to it, and so on. Stacking $k$ of them gives each point a $k$-dimensional signature summarising how it falls on each of the $k$ cheapest splits. Points in the same cluster agree across all views, so they land near each other.

Then row-normalise to the unit sphere and run k-means on the embeddings. Which raises the obvious question: why is k-means acceptable now, given we just spent a lecture on how it fails? Because the embedding is exactly the space where k-means' assumption finally holds — the two moons come out as two tight, well-separated, convex blobs. The spectral map does the hard part; k-means only has to finish.

Spectral clustering (unnormalized Laplacian)
  1. Build the similarity graph: $w_{ij} = e^{-\|x_i-x_j\|^2/2\sigma^2}$ (or $k$-NN).
  2. Form $D$ and $L = D - W$.
  3. Compute eigenvectors $f_1, \dots, f_{k+1}$ for the smallest eigenvalues; discard $f_1$.
  4. Stack $f_2,\dots,f_{k+1}$ as columns of an $n \times k$ matrix; each row is a point's embedding.
  5. Normalise each row to unit length.
  6. Run k-means on the $n$ embeddings.

Unit 06 · Week 6, Lectures 2–4

Spectral sparsification

The Gaussian similarity graph is dense — $\binom{n}{2}$ edges, all non-zero. At $n = 10^6$ that is $5\times10^{11}$ edges before you compute a single eigenvector. Throw most of them away, and reweight the survivors so the spectrum survives.

What must be preserved

The clustering came entirely from eigenvectors of $L$, so the thing to protect is the quadratic form. Here is why that is the same as protecting the spectrum: if $f$ is a unit eigenvector with eigenvalue $\lambda$, then

$$f^\top L f = f^\top(\lambda f) = \lambda\|f\|^2 = \lambda$$

Preserve $f^\top Lf$ for all $f$ and you have preserved every eigenvalue — hence the whole spectral structure.

$\epsilon$-spectral sparsifier

$H = (V, F, W')$ with $F \subseteq E$ is an $\epsilon$-spectral sparsifier of $G = (V,E,W)$ if for all $f \in \mathbb{R}^{|V|}$:

$$(1-\epsilon)\,f^\top L_G f \;\le\; f^\top L_H f \;\le\; (1+\epsilon)\,f^\top L_G f$$

Same vertex set, a subset of the edges, and new weights. Note the structural echo of JL: a $(1\pm\epsilon)$ multiplicative sandwich that must hold for everything at once.

Sparsification by downsampling

The scheme
  1. Keep each edge $(u,v) \in E$ independently with probability $p_{uv}$.
  2. If kept, reweight: $\;w'_{uv} = \dfrac{w_{uv}}{p_{uv}}$.
Unbiasedness $$\mathbb{E}\big[f^\top L_H f\big] = \sum_{(i,j)\in E} p_{ij}\,(f_i-f_j)^2\,\frac{w_{ij}}{p_{ij}} = \sum_{(i,j)\in E}(f_i-f_j)^2 w_{ij} = f^\top L_G f$$
The inverse-probability weight is the whole trick

An edge kept with probability $p$ appears a fraction $p$ of the time; scaling its weight by $1/p$ makes its average contribution exactly right. The $p_{ij}$ and the $1/p_{ij}$ cancel identically.

Exam trap: this cancellation happens for any choice of $p_{ij} > 0$. Unbiasedness alone does not tell you how to sample. The clever choice of probabilities is entirely about variance — about making the estimate concentrate, not about making it correct on average. The professor states this explicitly.

Effective resistance — choosing the probabilities

Scope

The Part-1 course notes stop at the unbiasedness result above. Everything from here to the end of the unit comes from the Week 6 lectures — it is in the syllabus, but if you are revising strictly from the typeset notes you will not have seen it.

Two pictures make the right notion obvious:

Edge inside a clique

In a near-complete graph on $n$ nodes, edge $(u,v)$ has $n-2$ alternative two-hop routes. Dropping it barely changes anything — it is redundant. Sample it rarely: $p \propto 1/n$.

A bridge between two cliques

Two cliques of 1000 nodes joined by one edge. Delete it and the graph disconnects — the spectrum changes qualitatively. It is irreplaceable. Sample it with $p \approx 1$.

The quantity that measures "how irreplaceable is this edge" is effective resistance — treat the graph as an electrical network where each edge is a resistor. An edge with many parallel paths has low effective resistance; a bridge has high.

Sampling rule and the edge-count bound $$p_{uv} \;\propto\; R_{\mathrm{eff}}(u,v) = (e_u - e_v)^\top L_G^{\dagger} (e_u - e_v)$$

where $L_G^\dagger$ is the Moore–Penrose pseudo-inverse (needed because $L$ is singular — $\lambda_1 = 0$) and $e_u - e_v$ is the vector with $+1$ at $u$, $-1$ at $v$, zeros elsewhere. With these probabilities, with high probability the result is an $\epsilon$-sparsifier with

$$|F| = O\!\left(\frac{|V|\log|V|}{\epsilon^2}\right) = O(n\log n)\ \text{edges}$$

Down from $O(n^2)$ — a nearly linear-size graph.

Computing $R_{\mathrm{eff}}$ fast — JL comes back

Forming $L^\dagger$ densely is as expensive as the problem you were avoiding. But rewrite, using $L^\dagger L L^\dagger = L^\dagger$ and $L = U\Sigma U^\top$:

$$R_{\mathrm{eff}}(i,j) = e_{ij}^\top L^\dagger L L^\dagger e_{ij} = \big\|\Sigma^{1/2}U^\top L^\dagger e_{ij}\big\|^2 = \big\|\underbrace{\Sigma^{1/2}U^\top L^\dagger e_i}_{y_i} - \underbrace{\Sigma^{1/2}U^\top L^\dagger e_j}_{y_j}\big\|^2$$
The payoff

Effective resistance is a squared Euclidean distance between two vectors $y_i, y_j$. So Johnson–Lindenstrauss applies: project the $y$'s into $O(\log n/\epsilon^2)$ dimensions and every pairwise squared distance — hence every effective resistance — is preserved to within $(1\pm\epsilon)$. You never form $L^\dagger$ densely.

This is the course closing its own loop: the Week 1 lemma is what makes the Week 6 algorithm run.

Spectral clustering at scale — the full pipeline
  1. Build the similarity graph $G = (V,E,W)$ ($k$-NN, or the Gaussian kernel).
  2. Estimate $\hat R_{\mathrm{eff}}(i,j)$ for all edges, using the JL trick.
  3. Sample with $p_{ij} \propto \hat R_{\mathrm{eff}}(i,j)$, reweight $w'_{ij} = w_{ij}/p_{ij}$, giving $H$ with $O(n\log n/\epsilon^2)$ edges.
  4. Compute $L_H = D_H - W_H$.
  5. Use a sparse eigenvector solver for $f_1,\dots,f_k$ (this is why sparsity was worth buying).
  6. Stack, discard $f_1$, row-normalise to get embeddings.
  7. Run k-means.

Steps 1–3 are the scale-enabling preprocessing; steps 4–7 are spectral clustering as before.

Practice — Units 05 & 06

NAT
For the six-node graph above (all weights $1$), what is the cut value when $A = \{1,2\}$?
Answer — 2

Edges leaving $\{1,2\}$: $\{2,6\}$ and $\{2,4\}$. The edge $\{1,2\}$ is internal and does not count. So the cut is $\mathbf{2}$.

Check with the quadratic form, $f = (1,1,0,0,0,0)$: contributions from $\{2,6\}$ and $\{2,4\}$ are $1$ each, everything else $0$. ✓

MSQ
Which are true of the unnormalized graph Laplacian of a connected graph with positive weights?
  • A$L$ is symmetric positive semi-definite.
  • BThe smallest eigenvalue is $0$.
  • C$L$ is invertible.
  • DEvery row of $L$ sums to zero.
Answer — A, B and D

The unnormalized Laplacian is $L = D - W$, with $D_{ii} = \sum_j w_{ij}$ on the diagonal and $-w_{ij}$ off it.

C is false, and it follows from B: a zero eigenvalue means $L$ is singular. This is exactly why the sparsification formula needs the pseudo-inverse $L^\dagger$ rather than $L^{-1}$.

D is the reason for B: $L\mathbf 1 = 0$ directly, since $L_{ii} = \sum_j w_{ij}$ and the off-diagonals are $-w_{ij}$.

MCQ
Why is the constraint $f^\top\mathbf{1} = 0$ imposed in the relaxed mincut problem?
  • ATo make the problem convex
  • BTo exclude the trivial all-ones eigenvector at $\lambda_1 = 0$
  • CTo ensure $L$ is positive semi-definite
  • DTo normalise the embedding
Answer — B

Without it, the minimiser is $f = \tfrac{1}{\sqrt n}\mathbf 1$ with objective $0$ — "put everything in one cluster". Forcing orthogonality to $\mathbf 1$ deletes that direction and promotes the answer to $f_2$. C is a property of $L$ that holds regardless of any constraint.

MCQ
A dataset consists of two concentric rings. Which is the best description of what happens?
  • ABoth k-means and spectral clustering succeed.
  • Bk-means fails; spectral clustering succeeds because the rings are connected components in the similarity graph.
  • CBoth fail because the rings are not linearly separable.
  • Dk-means succeeds if initialised at the common centre.
Answer — B

A ring is not convex, so it can never be a Voronoi cell — k-means will slice both rings along a diameter regardless of initialisation. In the similarity graph, though, each ring is densely connected internally and weakly connected to the other, so the cheapest cut separates them, and the Fiedler vector finds it. Linear separability (C) is irrelevant: after the spectral embedding, the clusters become separable, which is precisely the point.

MSQ
In the edge-sampling sparsifier, edge $(u,v)$ has $w_{uv} = 0.6$ and is retained with $p_{uv} = 0.2$. Which are true?
  • AIts new weight is $3$.
  • BIts new weight is $0.12$.
  • C$\mathbb{E}[f^\top L_H f] = f^\top L_G f$ for this and any other choice of positive probabilities.
  • DEffective-resistance probabilities are needed for unbiasedness.
Answer — A and C

$w' = w/p = 0.6/0.2 = \mathbf{3}$ — you divide by $p$, which makes surviving edges heavier, not lighter. B multiplies instead, and is the natural wrong answer.

D is false, and this is the key conceptual point: unbiasedness holds for any $p_{ij} > 0$, since the $p$ and $1/p$ cancel. Effective resistance is chosen to control variance — so the estimate concentrates and the $(1\pm\epsilon)$ guarantee holds w.h.p., with few enough edges.

MCQ
Which edge should be sampled with the highest probability?
  • AAn edge inside a dense clique of 500 nodes
  • BThe single bridge connecting two large clusters
  • CThe edge with the largest weight
  • DAll edges should be sampled equally to preserve unbiasedness
Answer — B

The bridge has the highest effective resistance — no alternative path exists, so removing it disconnects the graph and destroys the spectrum. It must be kept with probability $\approx 1$. Clique-internal edges are redundant ($p \propto 1/n$). C is a distractor: high weight does not imply high effective resistance — a heavy edge buried in a clique is still replaceable. D is the trap from the previous question.

NAT
A dense similarity graph on $n = 10^6$ points has $\approx 5\times 10^{11}$ edges. Ignoring constants and the $1/\epsilon^2$ factor, roughly how many edges does the effective-resistance sparsifier keep? Give the exponent $t$ in $10^t$.
Answer — 7

$|F| = O(n\log n) = 10^6 \times \log(10^6)$. With natural log, $\ln 10^6 \approx 13.8$, giving $\approx 1.4\times10^7$; with $\log_2$, $\approx 20$, giving $2\times10^7$. Either way the exponent is $t = \mathbf{7}$.

That is a reduction of roughly four orders of magnitude — from $5\times10^{11}$ to $\sim10^7$ — which is the difference between "impossible" and "runs on a laptop".

MCQ
Why is the mincut problem over $f \in \{0,1\}^n$ described as NP-hard rather than merely "expensive"?
  • ABecause $L$ is singular
  • BBecause no polynomial-time algorithm is known for the constrained binary problem
  • CBecause computing eigenvectors is slow
  • DBecause the graph is dense
Answer — B

The professor is deliberate about this distinction. NP-hard = no polynomial algorithm known, a complexity-theoretic barrier — that describes the balanced binary cut problem. Computationally expensive = polynomial but slow, which is what dense eigen-decomposition (C, D) is, and what sparsification addresses. The relaxation attacks the first problem; sparsification attacks the second.


Unit 07 · Week 7, Lectures 1–3

Statistical learning theory: the setup

The course turns here. Prof. Rajkumar opens Week 7 by writing two lines on the board — "Probability → algorithmic tool. Probability → analysis tool." The first six weeks were the top line. Everything from here is the bottom one: the same Hoeffding and union bound, pointed at a different question.

The new question

Weeks 1–6: "this computation is too expensive — can randomness make it cheap and still nearly right?"

Weeks 7–10: "I fitted a classifier to $n$ random samples — can I say anything about how it behaves on data I have never seen?" No new inequality is introduced. Hoeffding does the work again, and the union bound is again the step that makes it hold for everything at once.

The standard assumption

Setup

There is a joint distribution $D$ over features and labels. It is fixed but unknown. Both the training and test points are drawn i.i.d. from it:

$$S = \{(x_1,y_1),\dots,(x_n,y_n)\}, \qquad (x_i,y_i) \overset{\text{i.i.d.}}{\sim} D, \qquad S \sim D^n$$

Classifiers are $h : \mathbb{R}^d \to \{0,1\}$.

Both halves of "fixed but unknown" earn their keep. Fixed is what makes learning possible — if train and test came from different distributions, no amount of data would help. Unknown is what makes it necessary: if you had $D$, you would just write down the optimal classifier and go home.

Two decompositions of the same $D$

$P(x,y) = P(y)\cdot P(x\mid y)$ is the generative story — pick a class, then sample a point from that class. This is the form every exam question hands you: a prior $P(y=1)$ plus two class-conditional densities. The other factorisation $P(x,y) = P(x)\cdot P(y\mid x)$ is the discriminative one, and it is the form the Bayes classifier is defined in. Getting from one to the other is a single application of Bayes' theorem, and it is the entire content of half the past-paper questions in this unit.

Train and test error

Definitions $$\mathrm{er}_D[h] \;=\; P_{(x,y)\sim D}\big(h(x) \ne y\big) \;=\; \mathbb{E}_{(x,y)\sim D}\big[\mathbb 1[h(x)\ne y]\big]$$ $$\mathrm{er}_S[h] \;=\; \frac{1}{n}\sum_{i=1}^n \mathbb 1[h(x_i)\ne y_i]$$

Note the shape of the difference. The test error is an expectation over an unknown distribution — not computable. The train error is an average over data you hold — computable. The whole unit is about the gap between a thing you can compute and things you cannot.

The Bayes classifier and the Bayes error

Theorem — the optimal classifier

Among all classifiers $h:\mathbb{R}^d\to\{0,1\}$, the minimum test error is achieved by

$$h^*(x) = \begin{cases}1, & P(y=1\mid x) \ge 0.5\\ 0, & \text{otherwise}\end{cases} \qquad\qquad \mathrm{er}_D^* = \mathrm{er}_D[h^*] = \min_h \mathrm{er}_D[h]$$

Two things to hold onto. First, the minimum is over every classifier — not over a hypothesis class. Second, $\mathrm{er}_D^*$ need not be zero. If the class-conditional densities overlap, some points genuinely belong to both classes with positive probability and no classifier can win there. The Bayes error is the irreducible noise floor of the problem.

Computing $h^*$ by hand

You are given the generative form, and $P(y=1\mid x)\ge 0.5$ is the same as $P(y=1\mid x)\ge P(y=0\mid x)$. Apply Bayes and cancel the common $P(x)$:

The chain every exam question walks
$$P(y=1\mid x) \ge P(y=0 \mid x) \iff P(y=1)\,f_1(x) \;\ge\; P(y=0)\,f_0(x) \iff f_1(x) \;\ge\; \frac{P(y=0)}{P(y=1)}\,f_0(x)$$

With equal priors the ratio is $1$ and the rule collapses to "pick the class with the higher density at $x$". The decision boundary is wherever the two densities cross, so $h^*$ becomes a threshold rule $h^*(x) = 1$ for $x \le \theta$ (or a union of intervals, if they cross more than once).

Worked — the exponential example (2025 T3 ET, Q19–20)

$P(y=0)=P(y=1)=0.5$, one feature, $x\mid y=0 \sim \mathrm{Exp}(1)$ and $x\mid y=1 \sim \mathrm{Exp}(2)$. So $f_0(x)=e^{-x}$ and $f_1(x)=2e^{-2x}$ on $x\ge 0$.

Equal priors, so threshold where densities cross:

$$2e^{-2x} \ge e^{-x} \iff 2 \ge e^{x} \iff x \le \ln 2$$

so $\theta = \ln 2 \approx \mathbf{0.69}$ and $h^*(x)=1$ for $0\le x\le \ln 2$.

Notice which density wins where: $\mathrm{Exp}(2)$ is taller near zero and dies faster, so class $1$ owns the region near the origin and class $0$ owns the tail. Sketching the two curves takes ten seconds and prevents the sign error.

Computing the Bayes error

Write it as an expectation of an indicator, then split the expectation over the two classes — this is the professor's exact move, and the exam hint says so out loud:

Continuous case
$$\mathrm{er}_D^* = \mathbb{E}_{(x,y)\sim D}\big[\mathbb 1[h^*(x)\ne y]\big] = P(y=0)\!\int_x \!f_0(x)\,\mathbb 1[h^*(x)\ne 0]\,dx \;+\; P(y=1)\!\int_x\! f_1(x)\,\mathbb 1[h^*(x)\ne 1]\,dx$$

In words: the probability of each class, times the mass of that class's density lying on the wrong side of the boundary. Geometrically it is the area of the overlap region, scaled by the priors. If $x\mid y$ is discrete, replace densities with PMFs and integrals with sums — nothing else changes.

Worked — the same exponential example, continued

$h^*$ says $1$ on $[0,\ln2]$ and $0$ beyond. So it errs on class-$1$ points that landed past $\ln 2$, and on class-$0$ points that landed before it:

$$\mathrm{er}_D^* = 0.5\cdot P(x > \ln 2\mid y=1) \;+\; 0.5\cdot P(x \le \ln 2\mid y=0) = 0.5\,e^{-2\ln 2} + 0.5\big(1-e^{-\ln 2}\big)$$ $$= 0.5\cdot\tfrac14 + 0.5\cdot\tfrac12 = 0.125 + 0.25 = \mathbf{0.375}$$

Use the CDF the paper hands you — $F(x)=1-e^{-\lambda x}$ — rather than re-integrating. And keep the two tails straight: class $1$ errs in the upper tail, class $0$ in the lower.

The learning algorithm, and the class we search in

In practice you do not search over all classifiers. You fix a hypothesis class $H$ — linear, quadratic, intervals, rectangles — hand it and $S$ to an algorithm $A$, and get back $h_S \in H$. The best that class can possibly do is

$$\mathrm{er}_D[H] \;=\; \min_{h\in H}\,\mathrm{er}_D[h]$$

Three error levels are now in play, and they nest: $\mathrm{er}_D^* \le \mathrm{er}_D[H] \le \mathrm{er}_D[h_S]$. Only the first inequality is about $H$; only the second is about the algorithm.

The error decomposition

The one quantity you can compute is $\mathrm{er}_S[h_S]$. The one you care about is $\mathrm{er}_D^*$. So study their difference — and insert the two intermediate levels by adding and subtracting:

The decomposition — memorise this exactly $$\mathrm{er}_S[h_S] - \mathrm{er}_D^* \;=\; \underbrace{\Big(\mathrm{er}_S[h_S] - \mathrm{er}_D[h_S]\Big)}_{\textbf{generalisation error}} \;+\; \underbrace{\Big(\mathrm{er}_D[h_S] - \mathrm{er}_D[H]\Big)}_{\textbf{estimation error}} \;+\; \underbrace{\Big(\mathrm{er}_D[H] - \mathrm{er}_D^*\Big)}_{\textbf{approximation error}}$$
er*_Der_D[H] er_D[h_S]er_S[h_S] Bayes best in H what you got computable approximation estimation generalisation choice of H the algorithm finite sample
Four error levels, three gaps. Each gap is blamed on exactly one thing, and each is fixed by a different lever: more data shrinks generalisation and estimation, but never approximation — that one is set the moment you choose $H$.
GapFormulaBlamesSignAttacked by
Generalisation$\mathrm{er}_S[h_S] - \mathrm{er}_D[h_S]$the finite sampleeitherHoeffding + union bound (Unit 08)
Estimation$\mathrm{er}_D[h_S] - \mathrm{er}_D[H]$the algorithm$\ge 0$ERM (Unit 10)
Approximation$\mathrm{er}_D[H] - \mathrm{er}_D^*$the choice of $H$$\ge 0$SRM (Unit 10)
Trap

The two signs are exam gold and they appeared as an MSQ on both May-2025 papers. Estimation $\ge 0$ because $\mathrm{er}_D[H]$ is a minimum over $H$ and $h_S\in H$. Approximation $\ge 0$ because $\mathrm{er}_D^*$ is a minimum over all classifiers, a superset of $H$.

Generalisation can be negative — the train error can sit above the test error by luck of the draw. It is the only one of the three that is not signed, which is exactly why the theorems about it are stated with an absolute value.

The professor's numeric walk-through

Suppose $\mathrm{er}_S[h_S]=0.7$, $\mathrm{er}_D[h_S]=0.75$, $\mathrm{er}_D[H]=0.3$ and $\mathrm{er}_D^*=0.15$. Then

  • generalisation $= 0.7-0.75 = -0.05$ — negative, and that is fine;
  • estimation $= 0.75-0.3 = 0.45$ — the algorithm is doing badly inside a decent class;
  • approximation $= 0.3-0.15 = 0.15$ — the class itself is leaving $15$ points on the table;
  • total $= 0.7 - 0.15 = 0.55 = -0.05+0.45+0.15$. ✓
Label conventions differ between sources — read the question

The typeset notes and every past paper use $y \in \{0,1\}$, with $h^*(x)=1$ when $P(y=1\mid x)\ge 0.5$. The professor's handwritten lecture notes use $y\in\{\pm1\}$ with $h_w(x)=\mathrm{sign}(w^\top x)$. The mathematics is identical; only the symbols move. Since the papers are $\{0,1\}$, that is the convention used throughout this page — but when a question hands you $\{-1,+1\}$ (as the polynomial-sign question on 2025 T3 did), switch without blinking.

Practice — Unit 07

MCQ
Which quantity in the error decomposition can be computed from the data you actually hold?
  • A$\mathrm{er}_D[h_S]$
  • B$\mathrm{er}_S[h_S]$
  • C$\mathrm{er}_D[H]$
  • D$\mathrm{er}_D^*$
Answer — B

Every quantity with a subscript $D$ is an expectation over the unknown distribution, so none of A, C, D is computable. Only the train error is an average over points in your hand.

This is the reason the decomposition is written as $\mathrm{er}_S[h_S] - \mathrm{er}_D^*$ and not the other way round: it starts from the one number you have and walks to the one you want.

MSQ
Which of the following must be true for any $D$, $H$ and algorithm output $h_S \in H$?
  • A$\mathrm{er}_D[H] - \mathrm{er}_D^* \ge 0$
  • B$\mathrm{er}_D[h_S] - \mathrm{er}_D[H] \ge 0$
  • C$\mathrm{er}_S[h_S] - \mathrm{er}_D[h_S] \ge 0$
  • D$\mathrm{er}_D^* \ge 0$
Answer — A, B and D

A and B are the two nesting facts. D holds because the Bayes error is a probability. C is the trap: the generalisation error is the one unsigned term.

The May-2025 papers asked exactly A and B as an MSQ, with $\le 0$ versions as the distractors. They also asked separately whether the Bayes error is "non-negative", "zero" or "positive" — the answer is non-negative: it is zero when the classes do not overlap and positive when they do, so neither of the stronger claims is always true.

NAT
$P(y=1)=0.5$; $x\mid y=1 \sim U[-1,3]$; $x\mid y=0 \sim U[-2,0]$. Compute the Bayes error.
Answer — 0.125

Densities: $f_1 = \tfrac14$ on $[-1,3]$; $f_0 = \tfrac12$ on $[-2,0]$. Priors are equal, so compare densities directly.

  • $x\in[-2,-1)$: $f_1=0 < f_0=\tfrac12$ ⇒ $h^*=0$
  • $x\in[-1,0]$: $f_1=\tfrac14 < f_0=\tfrac12$ ⇒ $h^*=0$
  • $x\in(0,3]$: $f_1=\tfrac14 > f_0=0$ ⇒ $h^*=1$

So $h^*(x)=1$ exactly on $[0,3]$. Errors: class-$1$ points landing in $[-1,0]$, and class-$0$ points landing in $[0,\,0]$ (measure zero).

$$\mathrm{er}_D^* = 0.5\cdot\frac{1}{4}\cdot 1 \;+\; 0.5\cdot 0 = \mathbf{0.125}$$

Trap: the overlap region is $[-1,0]$, and it is tempting to charge both classes for it. You only charge the class that $h^*$ gets wrong there — and $h^*$ says $0$ throughout $[-1,0]$, which is right for class $0$ and wrong for class $1$. This was Q179 on both May-2025 papers.

NAT
Two concentric circles: the green disc is $\|x\|\le 1$ with label $1$; the red annulus is $1<\|x\|\le 2$ with label $0$. A fair coin picks $y$; then $x$ is uniform on the matching region. $H=\{h_r\}$ with $h_r(x)=1$ iff $\|x\|\le r$. Find $|\text{estimation error}|$ for $h_{0.5}$, to three decimals.
Answer — 0.375

First the general test error. For $r\le1$ the circle sits inside the green disc, so it never mislabels a red point, and it misses the green points beyond $r$. Since $x\mid y=1$ is uniform on a unit disc, $P(\|x\|>r\mid y=1) = 1-r^2$:

$$\mathrm{er}_D[h_r] = 0.5\,(1-r^2) \quad (r\le 1), \qquad \mathrm{er}_D[h_r] = 0.5\cdot\frac{r^2-1}{3} \quad (1<r\le2)$$

(For the annulus, area $= 4\pi-\pi = 3\pi$, so the fraction inside radius $r$ is $(r^2-1)/3$.)

At $r=0.5$: $\mathrm{er}_D[h_{0.5}] = 0.5(1-0.25) = 0.375$.

The class minimum is at $r=1$ — the first branch decreases to $0$, the second increases from $0$ — so $\mathrm{er}_D[H] = 0$. Hence

$$\text{estimation error} = 0.375 - 0 = \mathbf{0.375}$$

And the approximation error is $0$: $h_1$ is perfect, so $\mathrm{er}_D[H]=0=\mathrm{er}_D^*$. That was the follow-up question, worth two marks for one line of reasoning — always check whether the class contains a zero-error classifier before grinding through an integral.

MCQ
Why can the Bayes classifier never be computed in a real problem?
  • AIt is NP-hard to optimise
  • BIt requires knowledge of $D$, which is unknown
  • CIt requires infinite data
  • DIt is not in any finite hypothesis class
Answer — B

$h^*$ is defined by a threshold on $P(y=1\mid x)$, which is a property of $D$. The obstruction is informational, not computational — a distinction worth keeping crisp, because the ERM obstruction later in the syllabus is exactly the other way round (you have everything you need, but the optimisation is NP-hard).

A is that later fact, misapplied. C is close but wrong in kind: even infinite data gives you $D$ only in the limit, and the statement is about $D$ being unknown, not about sample size. D is false — $h^*$ lives in the class of all classifiers.


Unit 08 · Week 8, Lectures 1–2

Generalisation error & uniform convergence

Take the first gap on its own: is the train error a trustworthy stand-in for the test error? The answer arrives in three moves — unbiased, then concentrated, then concentrated for every classifier at once. The third move is where the union bound walks back on stage.

Move 1 — the train error is unbiased

Theorem

Fix any classifier $h$ (chosen before seeing $S$). Then

$$\mathbb{E}_{S\sim D^n}\big[\mathrm{er}_S[h]\big] \;=\; \mathrm{er}_D[h]$$

The proof is three lines and worth being able to write:

Linearity, then the indicator identity
$$\mathbb{E}\big[\mathrm{er}_S[h]\big] = \frac1n\sum_{i=1}^n \mathbb{E}\big[\mathbb 1[h(x_i)\ne y_i]\big] = \frac1n\sum_{i=1}^n P\big(h(x_i)\ne y_i\big) = \frac1n\sum_{i=1}^n \mathrm{er}_D[h] = \mathrm{er}_D[h]$$

The load-bearing step is $\mathbb{E}[\mathbb 1[A]] = P(A)$, and the reason each term equals the same $\mathrm{er}_D[h]$ is that the points are identically distributed. Independence is not needed here — it is needed for the next move.

Move 2 — unbiased is not enough

An unbiased estimator with enormous variance is useless: the train error would swing wildly around the test error and tell you nothing about any single run. So ask for concentration. Define the per-point loss

$$z_i = \mathbb 1[h(x_i)\ne y_i] \in \{0,1\}$$

These are i.i.d. and bounded in $[0,1]$, so $b-a = 1$ and Hoeffding applies verbatim:

Hoeffding, for a single fixed $h$ $$P_{S\sim D^n}\Big(\big|\mathrm{er}_S[h] - \mathrm{er}_D[h]\big| \ge \epsilon\Big) \;\le\; 2\,e^{-2n\epsilon^2}$$
The factor of $2$ — know that both versions exist

The typeset course notes carry the $2$ (it is the price of making Hoeffding two-sided). The professor's board drops it and writes $e^{-2n\epsilon^2}$ directly. Downstream this is the only difference between $n \ge \frac{1}{2\epsilon^2}\log\frac{2|H|}{\delta}$ (notes) and $n \ge \frac{1}{2\epsilon^2}\log\frac{|H|}{\delta}$ (board). Both appear in the course material, so on a numeric question use whichever form the question states, and if it states neither, say which you used. The $\log$ makes the numerical difference small; the structure is what is being examined.

Move 3 — but $h_S$ is not fixed

Here is the whole difficulty. Hoeffding needs $h$ chosen before the data. But $h_S$ is chosen from the data, so it is a random object and $\mathrm{er}_D[h_S]$ is random too. The bound above simply does not apply to it.

The professor's fix is an event-inclusion argument. Define

Two events
$$A: \big|\mathrm{er}_S[h_S] - \mathrm{er}_D[h_S]\big| \ge \epsilon \qquad\qquad B: \Big(\max_{h\in H}\big|\mathrm{er}_S[h] - \mathrm{er}_D[h]\big|\Big) \ge \epsilon$$

Since $h_S \in H$, whenever $A$ happens the maximum over $H$ is also at least $\epsilon$ — so $A \Rightarrow B$, i.e. $A\subseteq B$, and therefore

$$P(A) \;\le\; P(B)$$
Why this is the clever step

$A$ mentions a random classifier; $B$ does not. The maximum over $H$ ranges over classifiers that are all fixed in advance. Trading $A$ for $B$ is a genuine loss — $B$ is a bigger event — but it buys you a statement Hoeffding can actually touch. This exact question was Q15 on the 2025 T3 end term: "which is true, $P(A)\le P(B)$, $P(A)\ge P(B)$, or $P(A)=P(B)$?"

Now unfold $B$: a maximum exceeding $\epsilon$ means some $h$ exceeds $\epsilon$, which is a union of events. Union bound, then Hoeffding on each term:

The chain, start to finish
  1. $P\big(|\mathrm{er}_S[h_S]-\mathrm{er}_D[h_S]|\ge\epsilon\big) \;\le\; P\big(\max_{h\in H}|\mathrm{er}_S[h]-\mathrm{er}_D[h]|\ge\epsilon\big)$  (subset bound)
  2. $= P\big(\exists\, h\in H : |\mathrm{er}_S[h]-\mathrm{er}_D[h]|\ge\epsilon\big)$
  3. $\le \sum_{h\in H} P\big(|\mathrm{er}_S[h]-\mathrm{er}_D[h]|\ge\epsilon\big)$  (union bound)
  4. $\le \sum_{h\in H} 2e^{-2n\epsilon^2} = 2|H|\,e^{-2n\epsilon^2}$  (Hoeffding, needs $|H|<\infty$)
  5. Set the right side $\le \delta$ and solve for $n$.

The sample complexity

Solving $2|H|e^{-2n\epsilon^2}\le\delta$:

Rearranged
$$e^{-2n\epsilon^2} \le \frac{\delta}{2|H|} \;\Longrightarrow\; -2n\epsilon^2 \le \log\frac{\delta}{2|H|} \;\Longrightarrow\; n \;\ge\; \frac{1}{2\epsilon^2}\log\frac{2|H|}{\delta}$$
Uniform Convergence Theorem (finite $H$)

Let $H$ be finite. Given $0<\epsilon<1$ and $0<\delta<1$, if

$$n \;\ge\; \frac{1}{2\epsilon^2}\log\frac{2|H|}{\delta}$$

then for every $h_S \in H$,   $P\big(|\mathrm{er}_S[h_S]-\mathrm{er}_D[h_S]|\ge\epsilon\big) \le \delta$.

The professor's numeric example

$\epsilon = 0.1$, $\delta = 0.1$, $|H| = 1000$. Using the board form $n \ge \frac{1}{2\epsilon^2}\log\frac{|H|}{\delta}$:

$$n \ge \frac{1}{2(0.01)}\ln\frac{1000}{0.1} = 50\,\ln\!\big(10^4\big) = 200\,\ln 10 \approx 200 \times 2.303 \approx \mathbf{461}$$

With the notes' factor of $2$ it becomes $50\ln(2\times10^4)\approx 495$. Either way, a few hundred points certify a $\pm0.1$ error bar at $90\%$ confidence over a thousand candidate classifiers — and the answer barely moves when $|H|$ jumps to a million, because $|H|$ sits inside a logarithm.

Reading the formula — what moves $n$

ChangeEffect on required $n$How strongly
$\epsilon$ decreases (want a tighter error bar)increases$1/\epsilon^2$ — the expensive one
$\delta$ decreases (want more confidence)increases$\log(1/\delta)$ — cheap
$\delta$ increasesdecreases$\log(1/\delta)$
$|H|$ increases (richer class)increases$\log|H|$ — cheap
Trap — the direction of $\delta$

This was an MSQ on the 2025 T3 end term with four options, and the two false ones were both about $\delta$ and $|H|$: "if $\delta$ increases, $n_0$ increases" is false ($\delta$ is your tolerance for failure — allowing more failure needs less data), and "$n_0$ is independent of $|H|$" is false ($|H|$ is in there, logarithmically). The two true ones were $\epsilon\!\downarrow\Rightarrow n_0\!\uparrow$ and $|H|\!\uparrow\Rightarrow n_0\!\uparrow$. Read $\delta$ as "probability of the bad event", not "confidence".

What "uniform" means, and what the theorem does not say

Uniform

The guarantee holds for every classifier in $H$ simultaneously, not for one chosen in advance. That is precisely why it can be applied to $h_S$, whichever member the algorithm happened to land on.

Algorithm-agnostic

Nothing in the statement mentions how $h_S$ was produced. Any learning rule that returns an element of $H$ inherits the bound — which is both its power and the reason it says nothing about quality.

It does NOT bound the test error

It says train $\approx$ test. If your class is hopeless, both are $0.45$ and the theorem is perfectly happy. Judging $H$ is the job of the approximation error, not this theorem.

It does NOT say $H$ is good

"Learnable" here means the train error is a reliable proxy. It is a statement about measurement, not performance. Nothing about the magnitude of the error is claimed.

Practice — Unit 08

MCQ
Why can Hoeffding's inequality not be applied directly to $|\mathrm{er}_S[h_S]-\mathrm{er}_D[h_S]|$?
  • ABecause the losses $z_i$ are not bounded
  • BBecause $h_S$ depends on $S$, so $\mathrm{er}_D[h_S]$ is random
  • CBecause the $z_i$ are not independent
  • DBecause $H$ may be infinite
Answer — B

Hoeffding compares a sample average to its mean — a fixed number. When $h$ is chosen from the data, the "mean" $\mathrm{er}_D[h_S]$ moves with the sample too, and the inequality has nothing to say.

A is false ($z_i\in\{0,1\}$). C is false for a fixed $h$ — the points are i.i.d. and so are the losses. D is a real problem but a different one, and it is Unit 09's subject; the failure here bites even when $|H|=2$.

MCQ
With $A$ and $B$ defined as in the lecture, which relation holds?
  • A$P(A)\le P(B)$
  • B$P(A)\ge P(B)$
  • C$P(A)=P(B)$
  • DNo relation holds in general
Answer — A

$h_S\in H$, so $A$ occurring forces the maximum over $H$ to be at least $\epsilon$: $A\subseteq B$, hence $P(A)\le P(B)$. This is the subset bound from Week 1, Lecture 5 — the same two-line utility inequality, reused eight weeks later.

C is wrong because $B$ can occur through some other classifier while $h_S$ itself is fine. The inclusion is genuinely one-directional.

NAT
Using $n \ge \frac{1}{2\epsilon^2}\log\frac{|H|}{\delta}$ with natural log: how many samples for $\epsilon=0.05$, $\delta=0.05$ and $|H|=20$? Round up to the nearest integer.
Answer — 1199 $$n \ge \frac{1}{2(0.0025)}\ln\frac{20}{0.05} = 200\,\ln 400 = 200 \times 5.9915 = 1198.3 \Rightarrow \mathbf{1199}$$

Sanity check the sensitivity, because that is what gets examined: halving $\epsilon$ from $0.1$ to $0.05$ multiplied $n$ by $4$. Halving $\delta$ would have added only $200\ln 2 \approx 139$. Accuracy is quadratically expensive; confidence is logarithmically cheap.

MSQ
Which are consequences of the uniform convergence theorem for a finite $H$?
  • AWith enough data, the train error of any $h\in H$ is close to its test error.
  • BWith enough data, the test error of $h_S$ is close to zero.
  • CThe guarantee holds regardless of which algorithm produced $h_S$.
  • DThe required $n$ grows linearly in $|H|$.
Answer — A and C

B is the headline misreading. The theorem equates two errors; it never claims either is small. A class of two terrible classifiers satisfies it perfectly with both errors at $0.5$.

D is false — $|H|$ enters as $\log|H|$. Going from $10^3$ to $10^6$ classifiers triples the requirement rather than multiplying it by a thousand, which is why "finite but astronomically large" classes are still learnable.

C is the "algorithm-agnostic" property, and it is what makes the theorem usable at all: you prove it for the whole class, so you need not model the algorithm.

MCQ
In the proof that $\mathbb{E}[\mathrm{er}_S[h]] = \mathrm{er}_D[h]$, which assumption on the sample is actually used?
  • AOnly that the points are identically distributed
  • BOnly that the points are independent
  • CBoth independence and identical distribution
  • DNeither — it holds for any sample
Answer — A

Expectation is linear whether or not the terms are independent, so the unbiasedness computation only needs each $(x_i,y_i)$ to have the same law, giving each term the same value $\mathrm{er}_D[h]$.

Independence is needed one step later, for Hoeffding. That is the clean way to remember the split: i.d. buys you unbiasedness, independence buys you concentration. This is the same division of labour as in the JL proof, where unbiasedness of $\|Mu\|^2$ came free and only the tail bound needed the coordinates to be independent.


Unit 09 · Week 9, Lectures 1–5

Infinite classes & VC dimension

Every class you would actually use — linear, quadratic, intervals, rectangles — is infinite, and the Unit 08 bound reads $\infty \cdot e^{-2n\epsilon^2}$. The repair is to notice that $|H|$ was never the right quantity. What matters is how many different labelings $H$ can produce on your $n$ points, and that is finite even when $H$ is not.

Where the argument breaks

Step 4 of the Unit 08 chain summed $2e^{-2n\epsilon^2}$ once per classifier. With $|H| = \infty$ the sum diverges and the bound is vacuous — not wrong, just useless.

The key insight

Two classifiers that assign the same labels to all $n$ training points have the same train error. For the purposes of this bound they are indistinguishable. So the class is effectively partitioned into equivalence groups, one per achievable labeling, and the union bound only ever needed one term per group:

$$\text{effective size of } H \;=\; \#\{\text{distinct labelings of } S \text{ realisable by } H\}$$

$|H|$ may be infinite; this count is at most $2^n$.

Honesty about the gap

Same labeling ⇒ same train error, but not the same test error. Turning this intuition into a theorem needs an extra device (the symmetrisation trick), which the professor explicitly defers to a full learning-theory course. For this course the take-away is the shape of the result, not the proof: whatever controls the number of effective classifiers is what appears in the bound.

Case 1 — learning from all classifiers is hopeless

If $H$ is the set of all functions $\mathbb{R}^d\to\{0,1\}$, every one of the $2^n$ labelings is realisable, so

$$P\Big(\big|\mathrm{er}_S[h_S]-\mathrm{er}_D[h_S]\big|\ge\epsilon\Big) \;\le\; 2^{n}\,e^{-2n\epsilon^2}$$

and now both factors move with $n$. The growth $2^n = e^{n\ln 2}$ is exponential, the decay $e^{-2n\epsilon^2}$ is exponential, and for small $\epsilon$ the growth wins — the product does not go to zero. No uniform convergence.

What that means concretely

With all classifiers available, there is always one that reproduces every training label exactly, so you can always drive the train error to $0$ — by memorising. The train error then tells you nothing about the test error. The mathematics is saying, in the language of tail bounds, exactly what "overfitting" means: if you impose no structure at all, measurement becomes meaningless.

Case 2 — restrict the class and the count collapses

The interval class $$H_{\mathrm{int}} = \{h_{ab} : a < b,\ a,b\in\mathbb{R}\}, \qquad h_{ab}(x) = \begin{cases}1, & x\in[a,b]\\ 0,&\text{otherwise}\end{cases}$$

$|H_{\mathrm{int}}| = \infty$ — every real pair $a<b$ gives a classifier, and $h_{3,\,7.5}$ differs from $h_{3.001,\,7.499}$.

But on a fixed set of $n$ points the interval only ever selects a contiguous run of them. Slide the endpoint anywhere inside a gap and the labeling does not change — that is why infinitely many classifiers collapse to finitely many labelings.

x₁x₂x₃x₄ 1 1 1 1 1 1 0 0 0 1 1 0 0 1 0 0 any endpoint inside the same gap gives the same labeling
Infinitely many intervals, finitely many labelings. Only contiguous runs are achievable — which is why $1\,0\,1\,0$ is out of reach and the count is $O(n^2)$ rather than $2^n$.
Exact count for $H_{\mathrm{int}}$

Choose a contiguous run by choosing its first and last point ($\binom n2$ pairs plus $n$ singletons), or choose nothing:

$$\#\text{labelings} \;=\; \binom{n}{2} + n + 1 \;=\; \frac{n(n+1)}{2} + 1 \;\in\; O(n^2)$$
Two counts, one for each purpose

On the board the professor counts $(n+1) + n + (n-1) + \cdots + 1$ by sweeping the left endpoint through each gap. That is a clean upper bound of the right order — it re-counts the all-zeros labeling once per left endpoint — and it is all his argument needs, since only "$O(n^2)$" matters there. When a question asks for the exact number of distinct labelings, use $\frac{n(n+1)}{2}+1$. For $n=5$ that is $15+1=\mathbf{16}$, which is exactly what the 2025 T3 end term wanted.

With a polynomial count the bound is saved:

$$P\Big(\big|\mathrm{er}_S[h_S]-\mathrm{er}_D[h_S]\big|\ge\epsilon\Big) \;\le\; \underbrace{n^{2}}_{\text{polynomial growth}}\cdot\underbrace{e^{-2n\epsilon^2}}_{\text{exponential decay}} \;\xrightarrow[n\to\infty]{}\; 0$$

Polynomial growth always loses to exponential decay. That single sentence is the entire reason VC dimension is the right complexity measure — the exponent of the polynomial is what we need to name.

VC dimension — the two-player game

The professor introduces it as a game, which is by far the fastest way to compute one under exam pressure.

The game (round $m$, starting at $m=1$)
  1. Player 1 picks $m$ points $x_1,\dots,x_m$ — chosen as favourably as possible.
  2. Player 2 sees them and picks a labeling $y_1,\dots,y_m$ — chosen as awkwardly as possible.
  3. If Player 1 can produce some $h\in H$ with $h(x_i)=y_i$ for all $i$, the round is won and play moves to $m+1$. Otherwise the game stops.

The VC dimension is the largest $m$ Player 1 can win. Player 1 wants many rounds; Player 2 wants to end it.

Formal definition — both halves are required

$\mathrm{VCdim}(H) = k$ iff

  1. Existence. There exist $x_1,\dots,x_k$ such that for every labeling $y_1,\dots,y_k$ there is an $h\in H$ with $h(x_i)=y_i$ for all $i$. (Such a set is shattered.)
  2. Impossibility. For every set of $m > k$ points there exists a labeling that no $h\in H$ realises.
Trap — the quantifiers are asymmetric, and mixing them up is the classic error

Condition 1 is ∃ points, ∀ labelings. You get to choose the most convenient $k$ points; you must then handle all $2^k$ labelings. It is not "every set of $k$ points can be shattered" — three collinear points cannot be shattered by a line through the origin, yet $\mathrm{VCdim}(H_{\mathrm{lin}})$ in $\mathbb{R}^3$ is still $3$.

Condition 2 flips them: ∀ point sets, ∃ a bad labeling. Exhibiting one awkward set of $k+1$ points proves nothing; you must argue that no set of $k+1$ points works.

The standard VC dimensions

ClassDefinitionVC dim
$H_{\mathrm{int}}$ — intervals in $\mathbb{R}$$h_{ab}(x)=1$ iff $x\in[a,b]$$2$
$H_{\mathrm{apr}}$ — axis-parallel rectangles in $\mathbb{R}^2$$1$ iff $x_1\in[a,b]$ and $x_2\in[c,d]$$4$
Axis-parallel boxes in $\mathbb{R}^d$ (cuboids at $d=3$)one interval per coordinate$2d$  (so $6$ in $\mathbb{R}^3$)
$H_{\mathrm{lin}}$ — linear through the origin in $\mathbb{R}^d$$h_w(x)=1$ iff $w^\top x\ge0$$d$
Linear with bias in $\mathbb{R}^d$$h_{w,b}(x)=1$ iff $w^\top x + b\ge0$$d+1$
Union of $m$ intervals in $\mathbb{R}$$2m$ free endpoints$2m$
Circles centred at the origin$h_r(x)=1$ iff $\|x\|\le r$$1$
$\mathrm{sign}(p(x))$, $\deg p \le m$, one feature$m$ real roots ⇒ $m$ sign flips$m+1$
Triangles in $\mathbb{R}^2$$1$ inside the triangle$7$
Any finite class$|H| < \infty$$\le \lfloor\log_2|H|\rfloor$
All classifiersevery function$\infty$
The pattern worth internalising

For most geometric families the VC dimension equals the number of free real parameters: an interval has $2$, a rectangle has $4$, a $d$-dimensional box has $2d$, a union of $m$ intervals has $2m$, a homogeneous hyperplane has $d$, a triangle has $6$ (three vertices in $\mathbb{R}^2$) — though the triangle case is the reminder that the rule is a heuristic, not a theorem: its VC dimension is $7$, one more than its parameter count. Use the count to form a guess, then verify by playing the game.

Worked — $\mathrm{VCdim}(H_{\mathrm{int}}) = 2$

$\ge 2$: Player 1 picks $x_1 = 3.3$, $x_2 = 7$. All four labelings are reachable: $[+,+]$ with an interval spanning both, $[+,-]$ with one covering only $3.3$, $[-,+]$ with one covering only $7$, $[-,-]$ with an interval elsewhere. Round won.

$< 3$: For any three points $x_1<x_2<x_3$, Player 2 answers $[+,-,+]$. An interval containing both $x_1$ and $x_3$ must contain $x_2$ — intervals are connected. Game over.

Worked — $\mathrm{VCdim}(H_{\mathrm{lin}}) = d$ (both directions)

Part 1: $\ge d$ — the standard basis wins

Player 1 picks $x_i = e_i$, the standard basis vectors. For any labeling $y\in\{0,1\}^d$, take

$$w = \big(2y_1-1,\; 2y_2-1,\;\dots,\; 2y_d-1\big)$$

Then $w^\top e_i = w_i = 2y_i-1$, which is $+1$ when $y_i=1$ and $-1$ when $y_i=0$ — so $h_w(e_i)=y_i$ for every $i$, and all $2^d$ labelings are realised.

Part 2: $< d+1$ — linear dependence kills it

Take any $d+1$ points in $\mathbb{R}^d$. They are linearly dependent, so write

$$x_{d+1} = \sum_{i=1}^{d}\alpha_i x_i, \qquad \alpha_i \in \mathbb{R}$$

Player 2 chooses:  $y_{d+1}=0$, and $y_i = 1$ if $\alpha_i \ge 0$, else $y_i=0$.

Suppose some $w$ realised it. Then $w^\top x_i \ge 0$ exactly when $\alpha_i\ge0$, so every product $\alpha_i(w^\top x_i)$ is a product of two same-signed numbers, hence $\ge 0$. Therefore

$$w^\top x_{d+1} = \sum_{i=1}^{d}\alpha_i\,(w^\top x_i) \;\ge\; 0 \;\Longrightarrow\; h_w(x_{d+1}) = 1 \ne 0 = y_{d+1}$$

Contradiction. No set of $d+1$ points is shattered, so $\mathrm{VCdim} = d$. Adding a bias term lifts each $x$ to $(x,1)$ in $\mathbb{R}^{d+1}$, giving $d+1$.

Why this proof is worth knowing

It is the only VC proof in the course that runs on algebra rather than pictures, and it shows the two halves of the definition being discharged in completely different styles: Part 1 constructs one lucky point set; Part 2 argues about every point set via a structural property (dependence) they all share. When you are asked for an unfamiliar VC dimension, ask which structural property forces a contradiction — connectedness for intervals, dependence for hyperplanes, "at most $m$ roots" for polynomials.

The key result, and uniform convergence restored

Growth is polynomial in $n$ with exponent the VC dimension

If $\mathrm{VCdim}(H) = d < \infty$, then for any set of $n$ points the number of labelings realisable by $H$ is at most $n^{d}$. Hence

$$P\Big(\big|\mathrm{er}_S[h_S]-\mathrm{er}_D[h_S]\big|\ge\epsilon\Big) \;\le\; n^{d}\,e^{-2n\epsilon^2} \;\xrightarrow[n\to\infty]{}\; 0$$
Uniform Convergence Theorem (infinite $H$, finite VC dimension)

With $\mathrm{VCdim}(H) = d$, there is a constant $C$ such that the guarantee $P(\cdot\ge\epsilon)\le\delta$ holds whenever

$$n \;\ge\; C\left(\frac{d}{\epsilon^2} + \log\frac1\delta\right) \qquad\text{equivalently}\qquad n \;=\; O\!\left(\frac{d\log(1/\epsilon) + \log(1/\delta)}{\epsilon^2}\right)$$

Crudely: $\log|H|$ has been replaced by $d$. That substitution is the one-line summary of the whole unit.

Practice — Unit 09

NAT
Given $5$ distinct points in $\mathbb{R}$, what is the maximum number of labelings realisable by $H_{\mathrm{int}}$?
Answer — 16

Only contiguous runs are achievable. Count them: $\binom52 = 10$ runs of length $\ge2$, plus $5$ singletons, plus the empty (all-zeros) labeling:

$$\frac{5\cdot6}{2} + 1 = 15 + 1 = \mathbf{16}$$

Traps: $2^5 = 32$ is the count for all classifiers. $15$ forgets the all-zeros labeling. And the board's $(n+1)+n+\cdots+1 = 21$ is a valid upper bound of the right order but over-counts — do not use it when the question says "maximum number of labelings".

Sanity check against the VC dimension: at $n=2$ the formula gives $3+1=4=2^2$ (shattered ✓); at $n=3$ it gives $6+1=7<8$ (not shattered ✓). Consistent with $\mathrm{VCdim}=2$.

NAT
$H$ is the set of all axis-parallel cuboids in $\mathbb{R}^3$ (predicting $1$ inside). Find $\mathrm{VCdim}(H)$.
Answer — 6

A cuboid is one interval per coordinate: $[a_1,b_1]\times[a_2,b_2]\times[a_3,b_3]$, so $2\times3 = \mathbf{6}$ free parameters, and the VC dimension matches.

$\ge6$: put the six points at $\pm e_1, \pm e_2, \pm e_3$ — the six face centres. Any subset can be captured, because each of the six box faces can be pushed independently to include or exclude its own point.

$<7$: given any $7$ points, take the six achieving the extreme coordinate in each of the six directions (a point may serve twice; that only helps). Label those $1$ and some remaining point $0$. The tightest box containing all six extremes contains every other point, so the $0$ cannot be excluded.

Generalises immediately: axis-parallel boxes in $\mathbb{R}^d$ have VC dimension $2d$, and the $\mathbb{R}^2$ case $\mathrm{VCdim}(H_{\mathrm{apr}}) = 4$ is the professor's worked example.

NAT
$\mathcal P_4$ is the set of polynomials of degree at most $4$. With one feature in $\mathbb{R}$ and labels in $\{1,-1\}$, let $H = \{\mathrm{sign}(p(x)) : p\in\mathcal P_4\}$, with $\mathrm{sign}(0)=1$. Find $\mathrm{VCdim}(H)$.
Answer — 5

The right object to count is sign changes. A non-zero polynomial of degree $\le4$ has at most $4$ real roots, so its sign can flip at most $4$ times along the line — carving $\mathbb{R}$ into at most $5$ constant-sign blocks.

$\ge5$: take any $5$ points. Any labeling of them needs at most $4$ sign changes; drop a root into each gap where the label flips and take $p(x) = \pm\prod(x-r_j)$ (pad with extra roots outside the data, or a positive constant factor, to fix the leading sign). Degree stays $\le4$. ✓

$<6$: for any $6$ points, ask for the fully alternating labeling $+,-,+,-,+,-$. That is $5$ sign changes, so it needs $5$ roots — impossible at degree $4$. ✓

So $\mathrm{VCdim} = 4+1 = \mathbf 5$, and the general rule is $\deg \le m \Rightarrow \mathrm{VCdim} = m+1$. Check it at $m=1$: $\mathrm{sign}(ax+b)$ is a threshold rule, VC dimension $2$ — which matches linear-with-bias in $\mathbb{R}^1$. ✓

Trap: $\mathcal P_4$ has $5$ coefficients and the answer is also $5$, so the parameter-count heuristic gets the right number here — but the reason is the root count, and that is the argument to write down.

NAT
$H = \{h_{a_1\dots a_6}\}$ with $a_1<\dots<a_6$ and $h(x)=1$ iff $x\in[a_1,a_2]\cup[a_3,a_4]\cup[a_5,a_6]$. Find $\mathrm{VCdim}(H)$.
Answer — 6

A union of three intervals can produce at most three positive runs.

$\ge6$: take $6$ points. The worst labeling has positives at alternating positions — at most $3$ separate runs of $1$s among $6$ points — and three intervals can cover exactly that. Every labeling of $6$ points needs at most $3$ positive runs, so all $2^6$ are reachable. ✓

$<7$: for any $7$ points ask for $+,-,+,-,+,-,+$ — four positive runs, more than three intervals can produce. ✓

So $\mathbf 6$, matching the $6$ free endpoints. General rule: a union of $m$ intervals has VC dimension $2m$. (Q172 on both May-2025 papers.)

NAT
$H = \{h_r : r\in\mathbb{R}\}$ on $\mathbb{R}^2$, with $h_r(x)=1$ iff $\|x\|^2\le r^2$ — circles centred at the origin. Find $\mathrm{VCdim}(H)$.
Answer — 1

The classifier only ever sees $\|x\|$, so it is a threshold rule on a single non-negative number — and thresholds are monotone: if the nearer point is labelled $1$, so is everything nearer still.

$\ge1$: one point $x$ with $\|x\|=1$; take $r=2$ for label $1$, $r=0$ for label $0$. ✓

$<2$: for any two points, say $\|x_1\| \le \|x_2\|$, ask for $h(x_1)=0$, $h(x_2)=1$. Any circle containing $x_2$ contains $x_1$. ✓ (If the norms are equal, ask for different labels — impossible for the same reason.)

Trap: "circle in the plane" invites the answer $3$ (VC dimension of arbitrary discs) or $2$ (a parameter count of centre-plus-radius). Centring at the origin removes both centre parameters and leaves a one-dimensional monotone family. Always read what is being held fixed. (Q174 on both May-2025 papers.)

NAT
$H = \{h_1,\dots,h_{100}\}$ is a set of binary classifiers. What is the tightest upper bound on $\mathrm{VCdim}(H)$?
Answer — 6

Shattering $k$ points requires $2^k$ distinct labelings, and each labeling needs at least one classifier, so $2^k \le |H|$:

$$2^k \le 100 \;\Longrightarrow\; k \le \log_2 100 = 6.64 \;\Longrightarrow\; k \le \mathbf 6$$

Traps: $7$ would need $128 > 100$ classifiers. $100$ and $50$ ignore the exponential. And note the direction: this is an upper bound — the actual VC dimension of a specific $100$-element class could be anything from $0$ to $6$.

This is also the sanity check on the whole unit: $\mathrm{VCdim} \le \log_2|H|$ is exactly why "$\log|H| \to d$" is the right substitution in the sample-complexity formula. (Q183 on both May-2025 papers.)

NAT
A sample of $5$ data-points for a classification problem with $3$ classes. At most $k$ labelings are possible. Tightest upper bound on $k$?
Answer — 243

Each of the $5$ points independently takes one of $3$ labels: $3^5 = \mathbf{243}$.

The binary case $2^n$ generalises to $c^n$ for $c$ classes — a one-line question testing whether you know why $2^n$ appears in the bound, rather than having memorised the symbol. Trap: $5^3 = 125$ inverts base and exponent; $2^5=32$ forgets there are three classes. (Q171 on both May-2025 papers.)

MCQ
Why does the bound $2^n e^{-2n\epsilon^2}$ fail to give uniform convergence, while $n^d e^{-2n\epsilon^2}$ succeeds?
  • ABecause $2^n > n^d$ for all $n$
  • BBecause exponential growth can cancel exponential decay, while polynomial growth cannot
  • CBecause $n^d$ is independent of $n$
  • DBecause Hoeffding does not apply to infinite classes
Answer — B

Write both in exponential form: $2^ne^{-2n\epsilon^2} = e^{n(\ln 2 - 2\epsilon^2)}$, which grows whenever $\epsilon^2 < \tfrac{\ln 2}{2}$ — i.e. for every $\epsilon$ you would actually care about. Meanwhile $n^de^{-2n\epsilon^2} = e^{d\ln n - 2n\epsilon^2}$, and $d\ln n$ is beaten by $2n\epsilon^2$ for every fixed $d$ and $\epsilon$.

A is false for small $n$ and is anyway not the point — the issue is asymptotic rate, not pointwise size. C is plainly false. D confuses the mechanism: Hoeffding is applied per labeling, and the labeling count is exactly what was fixed.

MSQ
Which statements about the definition of VC dimension are correct?
  • ASome set of $k$ points must be shatterable.
  • BEvery set of $k$ points must be shatterable.
  • CNo set of $k+1$ points may be shatterable.
  • DSome set of $k+1$ points must fail to be shatterable.
Answer — A and C

The definition is ∃ a shatterable set of size $k$ and ∀ larger sets, not shatterable.

B is too strong and is the most common misreading: in $\mathbb{R}^2$, three collinear points cannot be shattered by lines through the origin, yet the VC dimension is still $2$. Degenerate configurations are allowed to fail; you only need one good configuration.

D is too weak. "Some set of $k+1$ points fails" is compatible with a different set of $k+1$ points succeeding, which would push the dimension up. You need all of them to fail.


Unit 10 · Week 10, Lectures 1–4

ERM, SRM & sample compression

Two gaps remain. The estimation error needs us to finally name an algorithm; the approximation error needs us to reconsider the class itself. Then the unit closes with a completely different lens on complexity — how few points you need to keep in order to rebuild the labels.

Estimation error needs an algorithm

Recall the gap: $\mathrm{er}_D[h_S] - \mathrm{er}_D[H]$ — how much worse the classifier you got is than the best one your class contains. Two observations from the lecture:

  • Uniform convergence cannot be applied directly here — both terms are test errors, and the theorem is about the train-versus-test gap.
  • The gap depends on the algorithm, so we cannot stay algorithm-agnostic any longer.

The only quantity we can compute is the train error. So minimise it.

Empirical Risk Minimiser $$h_S^{\mathrm{ERM}} \;=\; \arg\min_{h\in H}\; \mathrm{er}_S[h]$$
Trap — what ERM optimises, exactly

$\mathrm{er}_S$ is the $0$–$1$ loss: the fraction of misclassified points. Minimising it is the same as maximising accuracy — nothing else. Not F1, not precision, not log loss. The 2025 T3 end term opened with exactly this as a two-mark MCQ ("which metric is the ERM primarily designed to maximize by design?"), and the three wrong options are all metrics you optimise by choosing a different objective. Log loss in particular is a surrogate for the $0$–$1$ loss, not the thing ERM minimises.

Bounding the estimation error

The derivation is an add-and-subtract exercise. Let $h^*_H \in H$ achieve $\mathrm{er}_D[H]$ (the best classifier in the class), and write $\hat h = h_S^{\mathrm{ERM}}$:

Insert the train errors of both classifiers
$$\mathrm{er}_D[\hat h] - \mathrm{er}_D[H] \;=\; \underbrace{\big(\mathrm{er}_D[\hat h]-\mathrm{er}_S[\hat h]\big)}_{\text{gap at } \hat h} \;+\; \underbrace{\big(\mathrm{er}_S[\hat h]-\mathrm{er}_S[h^*_H]\big)}_{\le\, 0 \text{ — by definition of ERM}} \;+\; \underbrace{\big(\mathrm{er}_S[h^*_H]-\mathrm{er}_D[h^*_H]\big)}_{\text{gap at } h^*_H}$$

The middle term is $\le0$ because $\hat h$ minimises the train error, so $\mathrm{er}_S[\hat h] \le \mathrm{er}_S[h^*_H]$. Drop it and bound each remaining term by the worst case over $H$:

$$\big|\mathrm{er}_D[\hat h] - \mathrm{er}_D[H]\big| \;\le\; 2\max_{h\in H}\big|\mathrm{er}_S[h]-\mathrm{er}_D[h]\big|$$
The bound — note where the $\epsilon/2$ comes from $$P\Big(\big|\mathrm{er}_D[h_S^{\mathrm{ERM}}]-\mathrm{er}_D[H]\big| \ge \epsilon\Big) \;\le\; P\Big(\max_{h\in H}\big|\mathrm{er}_S[h]-\mathrm{er}_D[h]\big| \ge \tfrac{\epsilon}{2}\Big) \;\xrightarrow[n\to\infty]{}\; 0$$
Why the factor of two matters

The right-hand side is exactly the quantity uniform convergence controls — so the estimation error is bounded by the same machinery, just at half the tolerance. Since sample complexity scales as $1/\epsilon^2$, asking for $\epsilon/2$ costs a factor of four in $n$. The two errors are not independently attacked: generalisation and estimation are the same theorem, applied twice.

What ERM buys, in one sentence each
  • Statistically, ERM is good. As $n\to\infty$, both $|\text{train error of ERM} - \text{test error of ERM}|$ and $|\text{test error of ERM} - \text{best test error in } H|$ go to $0$. Transitively, the ERM's train error is a reliable proxy for the best achievable test error in $H$ — which is what you actually wanted from a number you can compute.
  • Computationally, ERM is hard. For $H_{\mathrm{lin}}$, solving $\min_{w}\sum_i \mathbb 1[\mathrm{sign}(w^\top x_i)\ne y_i]$ is NP-hard. The $0$–$1$ loss is non-convex and piecewise constant, so gradients carry no information.
Surrogate losses — the practical escape
SurrogateConvex loss on the marginGives
Logistic$\log\!\big(1+e^{-y\,w^\top x}\big)$logistic regression
Hinge$\max(0,\,1-y\,w^\top x)$SVM
Exponential$e^{-y\,w^\top x}$boosting

Whether minimising a surrogate really minimises the $0$–$1$ risk is the theory of loss calibration, which the professor names and explicitly places outside this course.

Approximation error — and why $H$ cannot be everything

The last gap, $\mathrm{er}_D[H] - \mathrm{er}_D^*$, is different in kind: no amount of extra data shrinks it. It is fixed the instant you choose $H$.

The tension, stated plainly

Why restrict $H$ at all? Because with $H$ = all classifiers, $\mathrm{VCdim}(H)=\infty$ and both earlier bounds evaporate — no generalisation guarantee, no estimation guarantee.

But shrink $H$ too far and the Bayes classifier sits far outside it, so the approximation error is large. Large $H$: small approximation, bad generalisation. Small $H$: good generalisation, large approximation. This is the bias–variance trade-off in learning-theoretic clothing.

Structural Risk Minimisation (Vapnik)

Instead of one class, take a nested family — say linear $\subseteq$ quadratic $\subseteq$ cubic $\subseteq\cdots$ — with increasing VC dimensions:

$$H_1 \subseteq H_2 \subseteq H_3 \subseteq \cdots \subseteq H, \qquad d_1 \le d_2 \le d_3 \le \cdots$$
  1. Run ERM separately inside each $H_i$, obtaining $h_i^{\mathrm{ERM}}$.
  2. Score each one by its train error plus a complexity penalty:
$$\mathrm{er}_S\big[h_i^{\mathrm{ERM}}\big] \;+\; \sqrt{\frac{d_i\log(n/d_i) + \log(1/\delta)}{n}}, \qquad d_i = \mathrm{VCdim}(H_i)$$

Return the $h_i^{\mathrm{ERM}}$ with the smallest score. Vapnik proved this drives the approximation error down as $n$ grows.

Why the VC dimension climbs as you nest: in the two-player game, a bigger bag of classifiers means more chances for Player 1 to answer Player 2's labeling, so the game survives more rounds.

SRM in practice is regularisation

Running many ERMs is doubly impractical — ERM is already NP-hard. So the spirit of SRM is folded straight into the optimisation:

$$\min_{w\in\mathbb{R}^d}\; \sum_{i=1}^n \ell\big(w^\top x_i,\, y_i\big) \;+\; \lambda\|w\|^2$$

"Train error $+$ complexity penalty" becomes "surrogate loss $+$ regulariser". If you map $x$ into a high-dimensional feature space (a degree-$k$ polynomial kernel, say), you are nominally learning in a class of huge VC dimension — but the regulariser confines you to a smaller effective region, and $\lambda$ is the dial that says how small. Cross-validation picks $\lambda$; that is model selection doing SRM's job by other means.

Sample compression — complexity from a different angle

Same question — how complex is $H$? — asked in a completely different way. Assume the labels were generated by some $h\in H$, i.e. $y_i = h(x_i)$ for all $i$, and $\mathrm{VCdim}(H) = d < \infty$.

Compression / decompression pair
  • Compress: take $S$, return a subset $T \subseteq S$ with $|T| = k$.
  • Decompress: take $T$ alone, return some $h'\in H$ with $h'(x_i) = y_i$ for all $i = 1,\dots,n$ — every point of $S$, not just those in $T$.
Sample compression scheme

$H$ has a sample compression scheme of size $k$ if such a pair exists with $|T| \le k$ for every dataset $S$ realisable by some $h\in H$.

The point: $k$ points suffice to reconstruct all $n$ labels. The smaller $k$, the simpler the class.

h′ = interval(x₄ , x₆) x₁x₂x₃ x₄x₅x₆ x₇x₈x₉ label 0 label 1 label 0 |S| = 9 →→→ |T| = 2 keep the two extreme positives; x₅ is recovered for free
$H_{\mathrm{int}}$ compresses to size $2$: retain the leftmost and rightmost positive points, and the interval they span relabels the whole dataset correctly. The interior positive $x_5$ and all six negatives are reconstructed, never stored.
The two worked schemes

$H_{\mathrm{int}}$ — size $2$. Compress: keep the two positive points with maximum separation, $T = \{(x_i,1),(x_j,1)\}$. Decompress: return $h' = h_{x_i x_j}$. Every positive lies between them (the labels came from an interval), every negative lies outside.

$H_{\mathrm{apr}}$ — size $4$. Compress: keep four positive points — the extremes in each of the two axis directions. Decompress: return $h_{abcd}$ where $a<b$ are the $x_1$-coordinates of the horizontally extreme pair and $c<d$ the $x_2$-coordinates of the vertically extreme pair.

The professor's own caveat: these algorithms are sketches, not complete specifications. Both fail if every point of $S$ is negative — there is no positive to keep. Full versions handle the corner cases; the exam only asks for the sizes.

Compression and VC dimension

Known: if $H$ has a sample compression scheme of size $k$, then $\mathrm{VCdim}(H) = O(k)$ — and hence $H$ is learnable.

Open: does $\mathrm{VCdim}(H) = d$ imply a compression scheme of size $d$? Unresolved for over thirty years — the sample compression conjecture.

Why the numbers coinciding is suggestive, not a theorem

$\mathrm{VCdim}(H_{\mathrm{int}}) = 2$ and its compression size is $2$. $\mathrm{VCdim}(H_{\mathrm{apr}}) = 4$ and its compression size is $4$. The professor flags this as "interesting" precisely because the general claim is the open conjecture — the two examples are evidence, not proof. Exam-wise this is a gift: the compression size of these two classes equals their VC dimension, and both directions have been asked.

Practice — Unit 10

MCQ
Which metric is the ERM primarily designed to maximise, by design?
  • AAccuracy
  • BF1 score
  • CPrecision
  • DLog loss
Answer — A

ERM minimises $\mathrm{er}_S[h] = \frac1n\sum\mathbb 1[h(x_i)\ne y_i]$, the misclassification rate — so it maximises $1 - \mathrm{er}_S = $ accuracy, and nothing else.

F1 and precision weight the two error types asymmetrically and require a different objective (and are exactly why ERM behaves badly on imbalanced data). Log loss is a surrogate — a convex stand-in you minimise because the $0$–$1$ loss is NP-hard — so it is a means, not the target. This opened the 2025 T3 end term.

NAT
$S$ has four points in $\mathbb{R}^2$ with labels in $\{0,1\}$: $(-1,1)\to1$, $(1,-1)\to1$, $(-1,-1)\to0$, $(1,1)\to0$. With $H_{\mathrm{lin}}$ = linear classifiers through the origin ($h_w(x)=1$ iff $w^\top x\ge0$), find $\mathrm{er}_S(h_S^{\mathrm{ERM}})$ to two decimals.
Answer — 0.25

Write out what each point demands of $w = (w_1,w_2)$:

Point$y$Requirement
$(-1,1)$$1$$-w_1+w_2 \ge 0$
$(1,-1)$$1$$w_1-w_2 \ge 0$
$(-1,-1)$$0$$-w_1-w_2 < 0$, i.e. $w_1+w_2 > 0$
$(1,1)$$0$$w_1+w_2 < 0$

Rows 3 and 4 are directly contradictory, so at least one error is unavoidable — the lower bound is $1/4$. Rows 1 and 2 force $w_2\ge w_1$ and $w_1\ge w_2$, hence $w_1 = w_2 = t$.

Take $t > 0$, e.g. $w = (1,1)$: the first two points give $w^\top x = 0 \ge 0$ ⇒ predict $1$ ✓✓; $(-1,-1)$ gives $-2 < 0$ ⇒ predict $0$ ✓; $(1,1)$ gives $2\ge0$ ⇒ predict $1$ ✗. Exactly one mistake:

$$\mathrm{er}_S\big(h_S^{\mathrm{ERM}}\big) = \frac14 = \mathbf{0.25}$$

Traps: $0$ assumes a linear classifier can always fit four points — this is XOR-shaped and it cannot. $0.5$ is what you get if you miss that $w=(1,1)$ salvages the first three. And the tie-break matters: the convention $w^\top x \ge 0 \Rightarrow 1$ is what makes the two boundary points come out right. (Q9 on the 2025 T3 end term.)

NAT
The hypothesis class of axis-parallel rectangles has a sample compression scheme of size $k$. What is $k$?
Answer — 4

Keep four positive points: the leftmost, rightmost, lowest and highest. Decompression rebuilds the bounding rectangle from their coordinates, and because the true labels came from some rectangle, that bounding box contains every positive and excludes every negative.

Same number as $\mathrm{VCdim}(H_{\mathrm{apr}}) = 4$ — and the intervals case matches too ($2$ and $2$). Whether that coincidence is a theorem is the open sample compression conjecture. (Q10 on the 2025 T3 end term; asked as an MSQ about $H_{\mathrm{int}}$ on both May-2025 papers.)

MSQ
Which are true about the approximation error $\mathrm{er}_D[H]-\mathrm{er}_D^*$?
  • AIt shrinks as $n$ grows.
  • BIt is zero if $h^* \in H$.
  • CEnlarging $H$ can only decrease it.
  • DIt is what SRM is designed to attack.
Answer — B, C and D

A is false, and it is the central point of the unit. The approximation error involves no sample at all — both terms are population quantities. Collecting a billion more points changes it by exactly zero. This is the one gap data cannot buy your way out of.

B: if the Bayes classifier is itself in $H$ then $\mathrm{er}_D[H] = \mathrm{er}_D^*$. C: a minimum over a superset can only fall. D: SRM searches a nested family precisely to let the approximation error fall while keeping the complexity penalty honest.

MCQ
ERM for $H_{\mathrm{lin}}$ is described as computationally hard. Which statement is accurate?
  • AMinimising the $0$–$1$ training loss over $w$ is NP-hard, so convex surrogates are used instead.
  • BERM is statistically inconsistent for linear classes.
  • CERM is hard because $H_{\mathrm{lin}}$ is infinite.
  • DERM is hard because the VC dimension of $H_{\mathrm{lin}}$ is infinite.
Answer — A

The $0$–$1$ loss is non-convex and piecewise constant — gradients are zero almost everywhere and uninformative elsewhere. Hinge, logistic and exponential losses are convex upper bounds that restore tractability.

B is the opposite of the truth: ERM is statistically excellent here (that is the estimation-error bound). C is a non-sequitur — least-squares regression also searches an infinite set and is solved in closed form. D is factually wrong: $\mathrm{VCdim}(H_{\mathrm{lin}}) = d$, finite, which is exactly why the statistical side works.

Keep the two obstructions apart: the Bayes classifier fails on information; ERM fails on computation.

MCQ
In the estimation-error bound, why does $\epsilon/2$ appear on the right-hand side?
  • ABecause Hoeffding is two-sided
  • BBecause the derivation bounds the gap by twice the worst-case train/test deviation
  • CBecause the union bound doubles the count
  • DBecause there are two classifiers involved, $\hat h$ and $h^*_H$
Answer — B

The chain ends at $|\mathrm{er}_D[\hat h]-\mathrm{er}_D[H]| \le 2\max_h|\mathrm{er}_S[h]-\mathrm{er}_D[h]|$. So the event "estimation error $\ge\epsilon$" implies "$2\max \ge \epsilon$", i.e. "$\max \ge \epsilon/2$" — the $2$ is divided across.

D is the tempting near-miss: two classifiers do appear, and that is why the factor is $2$ — but the question asks why $\epsilon$ is halved, which is the algebraic consequence of the bound, not the count of classifiers. Practical upshot: since $n$ scales as $1/\epsilon^2$, the halving costs a factor of four in sample size.

MSQ
Which statements about sample compression are correct?
  • ADecompression must correctly label every point of $S$, not just those in $T$.
  • B$T$ must be a subset of $S$.
  • CA scheme of size $k$ implies $\mathrm{VCdim}(H) = O(k)$.
  • D$\mathrm{VCdim}(H)=k$ is known to imply a scheme of size $k$.
Answer — A, B and C

A is the whole content of the definition — otherwise you could keep nothing and declare victory. B is what makes it compression rather than model fitting: you select points, you do not manufacture them.

C is the known direction. D is the open conjecture — unresolved for thirty-plus years — and any option asserting it as known is wrong.


Unit 11 · Weeks 11–12

Privacy

Randomness gets a third job. In Weeks 1–6 it made computation cheap; in Weeks 7–10 it was the thing we reasoned about. Here it becomes a shield: noise injected deliberately, in a calibrated amount, so that the output reveals the population without revealing you.

The threat model

Data → algorithm → model → world. Say the data are healthcare records and the model predicts whether someone has a disease. As a data provider, you need a guarantee that an adversary holding the released model cannot reverse-engineer your record — otherwise you rationally refuse to contribute.

And the adversary is assumed to be maximally powerful: they may already know everybody else's record. The guarantee must still hold.

Two approaches the course rejects

Cryptographic

Release the model encrypted and evaluate it in encrypted space. Two problems: it is not always possible (evaluating an arbitrary function without revealing it depends on how complex the function is), and it is expensive. Not wrong — just not this course.

Anonymisation

Strip names, addresses, PIN codes. Believed adequate for years, and broken: the Netflix Prize ratings matrix was released anonymised in the mid-2000s, and researchers re-identified users by correlating it with public IMDb activity. Side-information attacks defeat any ad-hoc scrubbing.

What survives is a statistical notion of privacy — inject randomness so that the output distribution barely moves when any one person's record changes. That is the whole idea, and everything below is a way to implement or refine it.

The survey example, and the two useless extremes

$n$ people; $x_i\in\{0,1\}$ records whether person $i$ voted. The surveyor wants $\bar x = \frac1n\sum x_i$, the turnout fraction. Nobody wants to admit not voting.

StrategyPrivacyUtility
Everyone flips a fair coin and reports thatperfect — the report is independent of the truthzero — the surveyor receives $n$ random bits
Everyone reports the truthzero — every individual bit is exposedperfect — the exact $\bar x$

Both are unusable. We want to sit between them, on a dial.

Randomized response

The mechanism

Person $i$ reports $y_i$ instead of $x_i$, where

$$y_i = \begin{cases} x_i & \text{with probability } \dfrac{e^{\epsilon}}{1+e^{\epsilon}} \quad\text{(the truth)}\\[8pt] 1-x_i & \text{with probability } \dfrac{1}{1+e^{\epsilon}} \quad\text{(a lie)}\end{cases}$$

The strange-looking form is just a convenient parameterisation. At $\epsilon=0$ it gives $\tfrac12/\tfrac12$ — the useless coin toss. As $\epsilon$ grows the truth probability rises past $\tfrac12$ towards $1$. It is always a valid distribution and $\epsilon$ is the single dial.

$\epsilon$$e^\epsilon$$P(\text{truth})$Reading
$0$$1$$0.500$pure noise — maximum privacy, no utility
$0.1$$1.105$$0.525$the value used on every past paper
$\ln 3 \approx 1.099$$3$$0.750$the clean "$3:1$" case
$2$$7.389$$0.881$useful, weakly private
$\to\infty$$\to\infty$$\to 1$truthful reporting — no privacy

The privacy proof

Fix two neighbouring datasets — identical except in one entry:

$$x = (x_1,\dots,x_n), \quad x' = (x'_1,\dots,x'_n), \qquad x_i = x'_i \ \ \forall i \in \{1,\dots,n-1\}$$

Write $RR(x) = y$ for the reported vector. The adversary observes a bit pattern $b = (b_1,\dots,b_n)$ and wants to know which dataset produced it. Because everyone flips independently, the probability factorises — and the first $n-1$ factors are identical for $x$ and $x'$:

Independence, then cancellation
$$P\big(RR(x)=b\big) = \prod_{i=1}^{n}P(y_i=b_i) = \left[\prod_{i=1}^{n-1}P(y_i=b_i)\right]\cdot P(y_n=b_n) \tag{1}$$ $$P\big(RR(x')=b\big) = \left[\prod_{i=1}^{n-1}P(y_i=b_i)\right]\cdot P(y'_n=b'_n) \tag{2}$$

So the entire ratio reduces to the $n$-th person's term. That term has exactly two cases:

Case analysis on the one differing bit
$$\frac{P(y_n = b_n)}{P(y'_n = b_n)} = \begin{cases} \dfrac{e^{\epsilon}/(1+e^{\epsilon})}{1/(1+e^{\epsilon})} = e^{\epsilon}, & b_n = x_n \ \ (\text{truth for } x,\ \text{lie for } x')\\[10pt] \dfrac{1/(1+e^{\epsilon})}{e^{\epsilon}/(1+e^{\epsilon})} = e^{-\epsilon}, & b_n \ne x_n \end{cases} \tag{3}$$

Since $e^{-\epsilon} \le e^{\epsilon}$, both cases give the same bound. Combining $(1)$, $(2)$ and $(3)$:

Randomized response is $\epsilon$-private $$\frac{P\big(RR(x)=b\big)}{P\big(RR(x')=b\big)} \;\le\; e^{\epsilon} \qquad \textbf{for every bit pattern } b \in \{0,1\}^n$$

and by swapping the roles of $x$ and $x'$, the two-sided statement

$$e^{-\epsilon}\,P\big(RR(x')=b\big) \;\le\; P\big(RR(x)=b\big) \;\le\; e^{\epsilon}\,P\big(RR(x')=b\big)$$
What this actually promises you

Suppose an adversary knows $x_1,\dots,x_{n-1}$ — everyone but you. They see the released bit pattern $b$. The two hypotheses "your bit is $0$" and "your bit is $1$" are exactly the two neighbouring datasets $x$ and $x'$, and the theorem says $b$ is nearly as likely under one as the other. For small $\epsilon$ the adversary stays confused, so you are willing to participate. The guarantee holds for every $b$ — no matter what gets observed, not merely on average.

Utility: debiasing, then a concentration bound

The surveyor cannot just average the $y_i$, because $y_i$ is a biased estimator of $x_i$:

Expectation of a reported bit
$$\mathbb{E}[y_i] = \frac{e^{\epsilon}}{1+e^{\epsilon}}\,x_i + \frac{1}{1+e^{\epsilon}}\,(1-x_i) \;=\; x_i\left(\frac{e^{\epsilon}-1}{e^{\epsilon}+1}\right) + \frac{1}{1+e^{\epsilon}}$$

A scale and a shift — both known, since $\epsilon$ is public. So invert them:

Debiasing $$z_i \;=\; \left(y_i - \frac{1}{1+e^{\epsilon}}\right)\left(\frac{e^{\epsilon}+1}{e^{\epsilon}-1}\right) \qquad\Longrightarrow\qquad \mathbb{E}[z_i] = x_i, \qquad \mathbb{E}[\bar z] = \bar x$$

Subtract the shift, multiply by the reciprocal of the scale. The pipeline is $x_i \to y_i \to z_i$, and $\bar z = \frac1n\sum z_i$ is the surveyor's estimate. It is random — but unbiased, and it concentrates:

Utility of randomized response $$\big|\bar x - \bar z\big| \;\le\; O\!\left(\frac{1}{\epsilon\sqrt n}\right) \qquad\text{with high probability}$$
$\epsilon$ is the privacy–utility dial; $n$ only buys utility

$\epsilon$ appears in both guarantees, pushing in opposite directions. Small $\epsilon$ ⇒ strong privacy ($e^\epsilon$ near $1$) but a large error bar ($1/\epsilon$ blows up). Large $\epsilon$ ⇒ accurate but exposed.

$n$ appears only in the utility bound. That asymmetry is the practical recipe: fix $\epsilon$ from your privacy requirement, then choose $n$ large enough to hit your accuracy target. Surveying more people never costs you privacy.

The trusted curator model

Now change the setting. Suppose you do trust the curator with your raw value — but the curator publishes a statistic to an untrusted world.

Why a trusted curator is still a privacy problem

The curator releases the exact average. An adversary knowing $n-1$ records subtracts them off and recovers the missing one exactly. One arithmetic step, total breach. Trusting the collector does not make the release safe.

You could still run randomized response and ignore the trust. The question is whether trust buys anything. It does — and the answer is differential privacy.

Differential privacy

Definition (Dwork) — $\epsilon$-differential privacy

A mechanism $M : \mathcal X^n \to \mathcal Y$ is $\epsilon$-differentially private if for all neighbouring $x, x' \in \mathcal X^n$ and all measurable $S \subseteq \mathcal Y$:

$$\frac{P\big(M(x)\in S\big)}{P\big(M(x')\in S\big)} \;\le\; e^{\epsilon}$$
Why sets $S$ and not single outputs

In the randomized-response setting the output space was discrete ($\{0,1\}^n$), so a per-output statement was enough — and it implies the set version, since for disjoint outcomes both numerator and denominator are sums and a bound on every ratio bounds the ratio of sums.

But a mechanism that adds continuous noise has $P(M(x) = \text{exact value}) = 0$ for every value, so the per-output statement is vacuous. Quantifying over measurable sets is what makes the definition work for continuous outputs. Neighbouring also generalises: swap one point of $\mathcal X^n$ for any other point of $\mathcal X$ — it need not be a bit flip.

Sensitivity and the Laplace mechanism

Sensitivity

For $f : \mathcal X^n \to \mathbb{R}$,

$$\Delta \;=\; \max_{x,\,x' \text{ neighbouring}} \big|f(x)-f(x')\big|$$

How much can the released number move if one person changes their record?

Worked — sensitivity of the average of $n$ bits $$\left|\frac1n\sum_{i=1}^n x_i - \frac1n\sum_{i=1}^n x'_i\right| = \frac1n\big|x_n - x'_n\big| = \frac1n \qquad\Longrightarrow\qquad \boxed{\;\Delta = \tfrac1n\;}$$

The first $n-1$ terms cancel; the last differs by exactly $1$ because the entries are bits. Note the direction: more people means lower sensitivity — each individual is diluted — hence less noise needed. This is the single most useful sensitivity computation in the syllabus.

Laplace distribution $$f_{\mathrm{Lap}}(x) = \frac{1}{2b}\,e^{-|x-\mu|/b}$$

A double-sided exponential: like a Gaussian but with a sharp peak at $\mu$ and heavier tails — $b$ is the spread parameter, playing the role $\sigma$ plays for a Gaussian.

The Laplace mechanism $$M(x) = f(x) + \eta, \qquad \eta \sim \mathrm{Lap}\!\left(0,\ \frac{\Delta}{\epsilon}\right)$$

This is $\epsilon$-differentially private. For the average of $n$ bits, $\Delta = 1/n$, so

$$M(x) = \bar x + \eta, \qquad \eta \sim \mathrm{Lap}\!\left(0,\ \frac{1}{n\epsilon}\right)$$

Zero-mean noise, so the release is an unbiased estimate of the truth. The spread is set by two things, and it is worth understanding why each:

$\Delta$ in the numerator

A more sensitive function separates $f(x)$ from $f(x')$ further, so the two noise densities must be wider to still overlap everywhere. More sensitivity → more noise.

$\epsilon$ in the denominator

A stricter privacy requirement means smaller $\epsilon$, means the two densities must be even harder to tell apart, means wider noise. Stricter privacy → more noise.

f(x) f(x′) observed narrow noise densities differ a lot → NOT private f(x) f(x′) observed wide noise densities nearly equal → private privacy = the two densities must stay within a factor e^ε of each other EVERYWHERE the gap f(x) − f(x′) is at most Δ · so the required width is Δ/ε
The mechanism's job is to make the two output densities indistinguishable. Their centres are up to $\Delta$ apart, and the tolerance is $e^\epsilon$ — which is exactly why the spread must be $\Delta/\epsilon$. Too little noise and the observed value betrays which dataset produced it.

Laplace beats randomized response — quadratically

Utility comparison

With high probability, the deviation of the released value from the truth is

MechanismTrust modelDeviationPrivacy
Randomized responsecurator not trusted$O\!\left(\dfrac{1}{\epsilon\sqrt n}\right)$$\epsilon$-DP
Laplace mechanismcurator trusted$O\!\left(\dfrac{1}{\epsilon n}\right)$$\epsilon$-DP
Where the win comes from

Both are $\epsilon$-DP — the privacy is identical. The difference is $\sqrt n$ versus $n$, so for the same $(\epsilon, \text{accuracy})$ target the Laplace mechanism needs quadratically fewer people.

The reason is structural: under randomized response every one of the $n$ people injects noise and the curator must average it all away. Under the Laplace mechanism nobody injects noise — the curator computes the exact average and adds a single perturbation at the end. One noise injection is cheaper than $n$. At $n=100$: $\frac{1}{100\epsilon}$ versus $\frac{1}{10\epsilon}$ — a tenfold better estimate for the same privacy.

Vector-valued releases

If the curator releases $d$ statistics at once — mean, median, quantiles — then $f(x)\in\mathbb{R}^d$ and the sensitivity becomes an $\ell_1$ quantity:

High-dimensional Laplace mechanism
$$\Delta_1 = \max_{x,x' \text{ nbr}} \big\|f(x)-f(x')\big\|_1 = \max\sum_{i=1}^{d}\big|f(x)_i - f(x')_i\big|$$ $$\text{add } \mathrm{Lap}\!\left(0, \frac{\Delta_1}{\epsilon}\right) \text{ to each component, independently} \quad\Longrightarrow\quad \epsilon\text{-DP}$$

If each of the $d$ components is $\tfrac1n$-sensitive, then $\Delta_1 = \tfrac dn$ and the per-component noise scale is $\tfrac{d}{n\epsilon}$ — linear in $d$. Releasing more numbers costs proportionally more noise. That is the cost the next relaxation is designed to reduce.

Approximate differential privacy

Definition — $(\epsilon,\delta)$-DP

$M$ is $(\epsilon,\delta)$-approximately differentially private if for all neighbouring $x,x'$ and all $S\subseteq\mathcal Y$:

$$P\big(M(x)\in S\big) \;\le\; e^{\epsilon}\,P\big(M(x')\in S\big) \;+\; \delta$$

Setting $\delta = 0$ recovers exact $\epsilon$-DP. The $\delta$ is leeway: it permits a set of low-probability outputs on which the $e^\epsilon$ guarantee may fail. For rare events privacy is not certified; for everything else it is.

The Gaussian mechanism

Add Gaussian instead of Laplace noise:

$$M(x) = f(x) + \eta, \qquad \eta \sim \mathcal N\!\left(0,\ \ln\!\left(\frac1\delta\right)\frac{\Delta_2^2}{\epsilon^2}\right)$$

where the sensitivity is now measured in the $\ell_2$ norm:

$$\Delta_2 = \max_{x,x' \text{ nbr}}\big\|f(x)-f(x')\big\|_2 = \max\sqrt{\sum_{i=1}^{d}\big(f(x)_i-f(x')_i\big)^2}$$

This achieves $(\epsilon,\delta)$-DP.

What the relaxation buys — a $\sqrt d$ instead of $d$
NoiseSensitivity usedSpread (each of $d$ components $\tfrac1n$-sensitive)Guarantee
Laplace$\ell_1$$\dfrac{d}{n\epsilon}$$(\epsilon, 0)$
Gaussian$\ell_2$$\dfrac{\sqrt{d\,\ln(1/\delta)}}{n\epsilon}$$(\epsilon, \delta)$

The $n\epsilon$ denominators match, so compare numerators: $d$ against $\sqrt{d\ln(1/\delta)}$. That is quadratically less noise in the output dimension, at the price of an extra $\sqrt{\ln(1/\delta)}$ — and since it sits inside a logarithm, even a tiny $\delta$ costs little. Less noise means higher utility. The mechanism is $\ell_1$ versus $\ell_2$: summing $d$ deviations versus root-summing their squares.

Two properties that make DP usable

Post-processing

If $M$ is $(\epsilon,\delta)$-DP then $F\circ M$ is $(\epsilon,\delta)$-DP for any function $F$. You cannot squeeze extra information out of a private release by transforming it — the guarantee covers every function of the output, not just the output itself.

Composition

If $M_1,\dots,M_k$ are each $(\epsilon,\delta)$-DP and an adversary sees all $k$ outputs:

  • Basic: the combination is $\big(k\epsilon,\; k\delta\big)$-DP. Easy to prove; the natural guess ($k$ leaks of size $\epsilon$, plus a union bound over $k$ failure sets of size $\delta$).
  • Advanced (Gaussian mechanism only, harder to prove): $\left(\epsilon\sqrt{k\log(1/\delta')} + k\epsilon\big(e^{\epsilon}-1\big),\;\; k\delta + \delta'\right)$-DP for any $\delta' > 0$.
Why $\sqrt k$ instead of $k$ is the whole point

The headline is the leading term: advanced composition degrades like $\epsilon\sqrt k$, not $k\epsilon$. That is the difference between running a private algorithm for $10$ iterations and for $1000$.

The application is private gradient descent. Each step releases a noisy gradient, leaking a little; over $k$ steps basic composition spends $k\epsilon$ and you run out of budget fast. With Gaussian noise and advanced composition you spend only $\approx\epsilon\sqrt k$, so you can afford quadratically more iterations — and more iterations means a better model. Advanced composition holds for the Gaussian mechanism, not for Laplace; only the basic version is available there. That is the real reason practitioners accept $(\epsilon,\delta)$-DP.

The exponential mechanism

A different shape of problem: what if the thing you release is not a number, but a choice?

The buyer–seller setup

A digital good with $n$ buyers holding private valuations $v_1,\dots,v_n$. The seller picks a public price $p$. Everyone whose valuation is at least $p$ buys, so the revenue is

$$S(x, p) \;=\; p\sum_{i=1}^{n}\mathbb 1\big(v_i \ge p\big) \;=\; p \times \#\{\text{buyers with } v_i \ge p\}$$

The valuations must stay private; the price is published.

The professor's example: valuations $10, 10, 500$

Trace the revenue curve. For $p \le 10$ all three buy, so revenue $= 3p$, climbing to $30$ at $p=10$. Just past $10$ the two cheap buyers drop out and revenue collapses to $\approx 10$, then climbs as $1\cdot p$ until $p = 500$ (revenue $500$), and past $500$ it is $0$.

The optimum is $p^\star = 500$, with $OPT = 500$. The curve is ragged — sawtoothed, discontinuous, non-monotone. That raggedness is what breaks the Laplace approach.

1030500 price 30 500 revenue OPT = 500 p = 10 and p = 30 both yield revenue 30 schematic — vertical axis is not to scale
Prices $10$ and $30$ earn the seller identical revenue, so no sane mechanism should prefer one over the other. Laplace noise added to $p^\star = 500$ prefers whichever is nearer $500$ — and noise in the wrong direction pushes past $500$, where revenue is exactly zero.
Why you cannot just add noise to the price
  • Equal-revenue prices get unequal probability. $p=10$ and $p=30$ both earn $30$, so the seller is indifferent — yet Laplace noise centred at $500$ makes $30$ far likelier than $10$. The mechanism has invented a preference the objective does not have.
  • Noise in the wrong direction is catastrophic. Push above $500$ and the revenue is not "slightly less", it is zero. Adding noise to the argument of a ragged function is unsafe in a way adding noise to a smooth value is not.
The exponential mechanism (Talwar et al., 2012)

Given valuations $x\in\mathcal X^n$, a finite set of candidate prices $H$, and a scoring function $S : \mathcal X^n\times H \to \mathbb{R}$, define

$$\Delta \;=\; \max_{h\in H}\ \max_{x,x' \text{ neighbouring}}\ \big|S(x,h)-S(x',h)\big|$$

Then select $h\in H$ with probability proportional to

$$\exp\!\left(\frac{\epsilon}{2\Delta}\,S(x,h)\right)$$

The exponential mechanism is $\epsilon$-differentially private for the valuations.

The fix, in one line

You are no longer perturbing the price — you are sampling the price from a distribution built out of its score. Two prices with the same revenue get exactly the same probability, and prices with terrible revenue are exponentially suppressed rather than being one noise draw away. Note the two maxima in $\Delta$: over candidates and over neighbouring datasets. The general recipe needs only a private input, a candidate set, and a score linking them — the buyer–seller market is just the canonical instance.

Utility of the exponential mechanism $$P\!\left(S\big(x, EM(x)\big) \;\le\; OPT(x) - \left(\frac{2\Delta}{\epsilon}\ln|H| + t\right)\right) \;\le\; e^{-t}$$

where $OPT(x)$ is the best achievable score. Read it as: the chance of landing more than $\frac{2\Delta}{\epsilon}\ln|H| + t$ below optimal decays exponentially in $t$. You do not get $OPT$ — you added randomness — but you land close to it with high probability. Note $\ln|H|$: a bigger candidate set costs you, but only logarithmically.

The whole privacy arc, on one line

MechanismTrustNoise / ruleGuaranteeUtility
Randomized responsenoneflip each bit w.p. $\frac{1}{1+e^\epsilon}$$\epsilon$-DP$O\!\left(\frac{1}{\epsilon\sqrt n}\right)$
Laplacecurator$+\,\mathrm{Lap}(0,\Delta_1/\epsilon)$$\epsilon$-DP$O\!\left(\frac{1}{\epsilon n}\right)$
Gaussiancurator$+\,\mathcal N\!\big(0,\ln(1/\delta)\Delta_2^2/\epsilon^2\big)$$(\epsilon,\delta)$-DP$\sqrt d$ not $d$
Exponentialcuratorsample $h$ w.p. $\propto e^{\frac{\epsilon}{2\Delta}S(x,h)}$$\epsilon$-DP$OPT - \frac{2\Delta}{\epsilon}\ln|H|$

Practice — Unit 11

NAT
Randomized response is applied to the true data $X = (1,1,0,1)$ with $\epsilon = 0.1$. Let $Y$ be the intermediate random vector. Compute $P\big(Y = (1,1,1,0)\big)$ to three decimals.
Answer — 0.062

Write $p = \frac{e^{0.1}}{1+e^{0.1}} = \frac{1.10517}{2.10517} = 0.52498$ (truth) and $q = \frac{1}{1+e^{0.1}} = 0.47502$ (flip). Now match each coordinate:

$i$$x_i$$y_i$NeededFactor
111truth$p$
211truth$p$
301flip$q$
410flip$q$

Independence across people, so multiply:

$$P = p^2q^2 = (0.52498)^2(0.47502)^2 = 0.275604 \times 0.225644 = \mathbf{0.062}$$

Method: compare $X$ and $Y$ coordinate by coordinate, count agreements $a$ and disagreements $f$, then answer $p^{a}q^{f}$. That is all these questions ever are. Traps: mixing up which of $p,q$ is bigger ($p > \tfrac12$ always, for $\epsilon > 0$), and forgetting that $Y$ is the intermediate vector — no debiasing is involved. (Q11 on the 2025 T3 end term.)

NAT
Same mechanism, $\epsilon = 0.1$, true data $X = (1,0,1,1,0)$. Compute $P\big(Y = (1,1,1,1,1)\big)$ to three decimals.
Answer — 0.033

Agreements at positions $1, 3, 4$ (three truths); disagreements at $2$ and $5$ (two flips):

$$P = p^3q^2 = (0.52498)^3(0.47502)^2 = 0.144687\times 0.225644 = 0.03265 \approx \mathbf{0.033}$$

The accepted range on the paper was $0.030$ to $0.035$. Worth a sanity check: the all-ones pattern from a data vector with three ones needs $3$ truths and $2$ lies, and since $p\approx q\approx\tfrac12$ at this tiny $\epsilon$, the answer must be near $2^{-5} = 0.031$. ✓ (Q190 / Q273 on the May-2025 papers.)

NAT
A trusted curator holds $n = 200$ bits and releases their average under the Laplace mechanism with $\epsilon = 0.5$. What is the spread parameter of the noise? Give the answer as $1/k$ and enter $k$.
Answer — 100

Sensitivity of the average of $n$ bits is $\Delta = 1/n = 1/200$. The Laplace spread is

$$b = \frac{\Delta}{\epsilon} = \frac{1}{n\epsilon} = \frac{1}{200 \times 0.5} = \frac{1}{100} \;\Longrightarrow\; k = \mathbf{100}$$

Traps: $\Delta = 1$ (that is the sensitivity of the sum, not the average — the $1/n$ is the entire point); and multiplying by $\epsilon$ instead of dividing. Remember the two directions: more people → less noise; stricter privacy (smaller $\epsilon$) → more noise.

MSQ
Which are true of $\epsilon$ in the randomized response mechanism?
  • AIncreasing $\epsilon$ improves utility.
  • BIncreasing $\epsilon$ improves privacy.
  • CAt $\epsilon = 0$ the mechanism reveals nothing about the data.
  • DIncreasing $n$ improves privacy.
Answer — A and C

A: the deviation is $O(1/(\epsilon\sqrt n))$, so larger $\epsilon$ ⇒ smaller error. B is backwards — privacy is $e^\epsilon$, and a larger ratio means the adversary distinguishes $x$ from $x'$ more easily. C: at $\epsilon=0$ the flip probability is exactly $\tfrac12$, so $y_i$ is a fair coin independent of $x_i$ — perfect privacy, zero utility.

D is the trap, and it is a good one. $n$ appears only in the utility bound; the privacy proof cancels the other $n-1$ factors and never mentions $n$ at all. Surveying more people does not make any individual more private — it makes the estimate better. That asymmetry is what lets you set $\epsilon$ and $n$ independently.

MCQ
Why does the definition of $\epsilon$-DP quantify over sets $S\subseteq\mathcal Y$ rather than individual outputs?
  • ATo make the guarantee stronger than a per-output statement
  • BBecause for continuous output spaces every single output has probability zero
  • CBecause the union bound requires it
  • DBecause neighbouring datasets differ in one entry
Answer — B

Randomized response has a discrete output space, so a per-pattern statement is meaningful there. The Laplace mechanism outputs a real number, and $P(M(x) = c) = 0$ for every $c$ — so a per-output ratio is $0/0$ and says nothing. Quantifying over measurable sets is the fix.

A is the near-miss: in the discrete case the two formulations are equivalent, because for disjoint outcomes bounding every ratio bounds the ratio of the sums. So the set version is not stronger — it is the version that still means something when the output is continuous.

NAT
Five mechanisms, each $(0.2, 10^{-6})$-DP, are run on the same dataset and all five outputs are published. Under basic composition, what is the resulting $\epsilon$?
Answer — 1.0

Basic composition: $k$ mechanisms each $(\epsilon,\delta)$-DP compose to $(k\epsilon, k\delta)$-DP. So $\epsilon_{\text{total}} = 5\times0.2 = \mathbf{1.0}$, and $\delta_{\text{total}} = 5\times10^{-6}$.

Contrast with advanced composition, whose leading term is $\epsilon\sqrt{k\log(1/\delta')}$ — the $k$ becomes $\sqrt k$. That is the entire reason DP-SGD uses Gaussian noise: releasing a noisy gradient at every step is composition with $k$ = number of iterations, and $k\epsilon$ exhausts the budget in a handful of steps while $\epsilon\sqrt k$ survives thousands.

Trap: advanced composition is available for the Gaussian mechanism, not for Laplace — for Laplace only the basic bound holds.

MCQ
A curator releases $d = 100$ statistics, each $\tfrac1n$-sensitive. Roughly how do the noise scales of the Laplace and Gaussian mechanisms compare?
  • ALaplace $\propto 100$, Gaussian $\propto 10\sqrt{\ln(1/\delta)}$
  • BLaplace $\propto 10$, Gaussian $\propto 100$
  • CThey are equal; only the tail shape differs
  • DLaplace $\propto \sqrt{100}$, Gaussian $\propto 100$
Answer — A

Laplace uses $\ell_1$ sensitivity: $\Delta_1 = \sum_{i=1}^{100}\tfrac1n = \tfrac{100}{n}$, so the spread is $\tfrac{100}{n\epsilon}$ — linear in $d$.

Gaussian uses $\ell_2$: $\Delta_2 = \sqrt{100\cdot\tfrac1{n^2}} = \tfrac{10}{n}$, and the standard deviation carries $\sqrt{\ln(1/\delta)}$, giving $\tfrac{10\sqrt{\ln(1/\delta)}}{n\epsilon}$ — $\sqrt d$.

Tenfold less noise at $d=100$, for the price of a $\delta$ and a logarithmic factor. C is the misconception that the two mechanisms differ only cosmetically; the norm they measure sensitivity in is exactly what differs, and it is what produces the $d$ versus $\sqrt d$ gap.

MCQ
Valuations are $10, 10, 500$. Under the exponential mechanism with revenue as the score, how do the probabilities of selecting $p = 10$ and $p = 30$ compare?
  • A$p=30$ is more likely, being closer to the optimum
  • BThey are equally likely
  • C$p=10$ is more likely, being nearer the majority valuation
  • DIt depends on $\epsilon$
Answer — B

Revenue at $p=10$: all three buy, $10\times3 = 30$. Revenue at $p=30$: only the $500$-buyer, $30\times1 = 30$. Identical scores, and the mechanism's probability depends on the score alone:

$$P(h) \propto \exp\!\left(\frac{\epsilon}{2\Delta}S(x,h)\right) \;\Longrightarrow\; P(10) = P(30)$$

A is what the Laplace approach would do — noise around $p^\star=500$ makes $30$ far likelier — and that mismatch is precisely the defect the exponential mechanism was built to remove. D is wrong because $\epsilon$ scales both exponents identically, so the ratio is $1$ for every $\epsilon$.

MSQ
Which are true of the trusted curator model?
  • AProviders hand over their raw values.
  • BReleasing the exact average is safe, since the curator is trusted.
  • CNoise is added once, after the statistic is computed.
  • DIt achieves better utility than randomized response at the same $\epsilon$.
Answer — A, C and D

B is exactly the trap, and it is the reason the model exists. Trust concerns the curator, not the world. An adversary who knows $n-1$ records and sees the exact average subtracts and recovers the last one — total breach in one arithmetic step. What is trusted is who holds the data; what is dangerous is what gets published.

C is the structural difference: one perturbation instead of $n$. D is its consequence: $O\!\left(\frac{1}{\epsilon n}\right)$ against $O\!\left(\frac{1}{\epsilon\sqrt n}\right)$ — quadratically better, so quadratically fewer people are needed for the same accuracy.

MCQ
Why is anonymisation rejected as a privacy mechanism?
  • AIt is computationally expensive
  • BIt is vulnerable to side-information attacks using auxiliary databases
  • CIt destroys too much utility
  • DIt cannot be applied to numeric data
Answer — B

The canonical case is the Netflix Prize: an anonymised user × movie ratings matrix was released, and researchers de-anonymised users by correlating it with public IMDb reviews. Removing identifiers does not remove the pattern, and a pattern plus a second database is an identity.

A and C describe the cryptographic objection and the too-much-noise objection respectively. The point about anonymisation is sharper: it offers no guarantee at all — it is heuristic rather than provable, which is why the course replaces it with a definition you can prove theorems about.


Reference

Formula cheat sheet

Everything examinable, on one screen. If you can reconstruct this page from memory, you are ready.

Concentration

NameStatementRequires
Markov$P(X \ge a) \le \dfrac{\mathbb{E}[X]}{a}$$X \ge 0$, $a > 0$
Chebyshev$P(|X-\mathbb{E}X| \ge k\sigma) \le \dfrac{1}{k^2}$finite mean and variance
Hoeffding$P(\bar X - \mathbb{E}\bar X \ge t) \le e^{-2nt^2/(b-a)^2}$independent, $X_i \in [a,b]$
Union bound$P(\cup_i A_i) \le \sum_i P(A_i)$nothing
Subset$A \subseteq B \Rightarrow P(A) \le P(B)$nothing

Johnson–Lindenstrauss

The lemma
$$(1-\epsilon)\|x_i-x_j\|^2 \le \|f(x_i)-f(x_j)\|^2 \le (1+\epsilon)\|x_i-x_j\|^2, \qquad k \in O\!\left(\frac{\log n}{\epsilon^2}\right)$$
Construction and unbiasedness
$$M = \frac{R}{\sqrt k},\quad R_{ij}\sim\mathcal N(0,1) \qquad\Longrightarrow\qquad \mathbb{E}\big[\|Mu\|^2\big] = \|u\|^2$$ $$r_i^\top u \sim \mathcal N\big(0,\|u\|^2\big), \qquad x = \tfrac{\sqrt k\,V}{\|u\|} \sim \mathcal N(\vec0, I_k), \qquad \mathbb{E}\big[\|x\|^2\big] = k$$
Tail, union bound, and the final result
$$P\big(\|Mu\|^2 \ge (1+\epsilon)\|u\|^2\big) \le e^{-c\,k\epsilon^2} \quad (c > 0 \text{ a constant})$$ $$E = \exists\,(x_i,x_j) \text{ distorted} \quad\Longrightarrow\quad P(E) \le n^2 e^{-c\,k\epsilon^2} \quad\Longrightarrow\quad k \in O\!\left(\frac{\log n}{\epsilon^2}\right)$$
  • Cost to apply the map to a dataset: $O(ndk)$. Cost to project one query: $O(dk)$.
  • $k$ is independent of $d$. Composing with any orthogonal $Q$ preserves the guarantee and the same $\epsilon$.
  • Distance version: $\|f(x)-f(y)\| \le \sqrt{1+\epsilon}\,\|x-y\|$ — the lemma is on squared norms.

LSH

Sensitive family and the Datar hash
$$\|x-y\|\le r \Rightarrow \Pr(h(x)=h(y)) \ge p_1, \qquad \|x-y\|\ge cr \Rightarrow \Pr(h(x)=h(y)) \le p_2$$ $$h_{ab}(x) = \left\lfloor\frac{a^\top x + b}{w}\right\rfloor, \quad a \sim \mathcal N(0,I_d),\ b \sim \mathrm{Unif}[0,w]$$ $$\Pr\big(h(x)=h(y)\,\big|\,a\big) = \max\!\left(0, 1 - \frac{|\Delta|}{w}\right), \qquad \Delta = a^\top(x-y) \sim \mathcal N\big(0,\|x-y\|^2\big)$$
Amplification
$$\text{AND of }k:\quad \mathrm{TPR}=p_1^k,\qquad \mathrm{FPR}=p_2^k$$ $$\text{OR of }L:\quad \mathrm{TPR}=1-\big(1-p_1^k\big)^L,\qquad \mathrm{FPR}=1-\big(1-p_2^k\big)^L$$
The tuned regime
$$k = \frac{\log n}{\log(1/p_2)} \;\;(\Rightarrow np_2^k=1), \qquad \rho = \frac{\log(1/p_1)}{\log(1/p_2)} \;\;(\Rightarrow p_1^k = n^{-\rho}), \qquad L = \theta n^\rho$$ $$\mathrm{TPR} \approx 1 - e^{-\theta}, \qquad \mathrm{FPR} \approx \theta n^{\rho-1}, \qquad \#\text{false positives} \approx \theta n^{\rho}$$

Always $\rho < 1$. $\theta = 1,2,3 \Rightarrow$ TPR $= 0.63, 0.86, 0.96$.

SVD & randomized SVD

Watch the letter swap

The course notes reuse letters between units. In JL and LSH, $n$ = number of points and $d$ = ambient dimension. In SVD, $A$ is $m\times n$: $m$ = number of points (rows), $n$ = number of features (columns). So $n$ means opposite things in the two halves of the syllabus — always read it off the matrix shape given in the question.

Decomposition and identities ($A$ is $m\times n$, $m > n$)
$$A = U\Sigma V^\top, \qquad A = \sum_{i=1}^n \sigma_i u_iv_i^\top, \qquad \|A\|_2 = \sigma_1$$ $$A^\top A = V\Sigma^2V^\top \;(n\times n,\ \text{gives } V), \qquad AA^\top = U\Sigma^2U^\top \;(m\times m,\ \text{gives } U)$$
Eckart–Young
$$\min_{\mathrm{rank}(B)=k}\|A-B\|_2 = \|A - A_k\|_2 = \sigma_{k+1}, \qquad A_k = U_k\Sigma_kV_k^\top = (U_kU_k^\top)A$$
Randomized SVD, $\ell = k+p$
$$\Omega_{n\times\ell} \to Y = A\Omega_{\,m\times\ell} \to Q = \mathrm{orth}(Y)_{\,m\times\ell} \to B = Q^\top A_{\,\ell\times n} \to \mathrm{SVD}(B) \to \hat U = Q\tilde U_k$$ $$\text{Total } O(mn\ell) \ \text{ vs naive } O(mn^2)$$
Guarantees
$$\big\|A - QQ^\top A\big\|_2 = (1+\epsilon)\,\sigma_{k+1} \ \text{ w.p. } \ge 1-\delta, \qquad \epsilon = \epsilon(\delta, k, p) \ \text{ — shrinks as } p \text{ grows}$$ $$\big\|QQ^\top - U_kU_k^\top\big\|_2 \lesssim \frac{\sigma_{k+1}}{\sigma_k} \quad\xrightarrow{\ q \text{ power steps}\ }\quad \left(\frac{\sigma_{k+1}}{\sigma_k}\right)^{2q+1}, \qquad (AA^\top)^qA = U\Sigma^{2q+1}V^\top$$

Spectral clustering & sparsification

Graph and Laplacian
$$w_{ij} = e^{-\|x_i-x_j\|^2/2\sigma^2}, \qquad D_{ii} = \sum_j w_{ij}, \qquad L = D - W$$ $$f^\top L f = \sum_{(i,j)\in E} w_{ij}(f_i-f_j)^2 \;=\; \tfrac12\sum_{i,j} w_{ij}(f_i-f_j)^2$$
The relaxation
$$\min_{f\in\mathbb{R}^n,\;\|f\|^2=1,\;f^\top\mathbf1=0} f^\top Lf \;=\; \lambda_2, \qquad \arg\min = f_2 \ \text{(Fiedler vector)}$$ $$\lambda_1 = 0, \quad f_1 = \tfrac{1}{\sqrt n}\mathbf 1, \quad L \succeq 0, \quad L\mathbf1 = 0$$
Sparsifier
$$(1-\epsilon)f^\top L_Gf \le f^\top L_Hf \le (1+\epsilon)f^\top L_Gf \quad \forall f$$ $$\text{keep }(u,v)\text{ w.p. } p_{uv},\ \ w'_{uv} = \frac{w_{uv}}{p_{uv}} \;\Longrightarrow\; \mathbb{E}\big[f^\top L_Hf\big] = f^\top L_Gf \ \ \textbf{(any } p\textbf{)}$$ $$p_{uv} \propto R_{\mathrm{eff}}(u,v) = (e_u-e_v)^\top L^\dagger (e_u-e_v) \;\Longrightarrow\; |F| = O\!\left(\frac{n\log n}{\epsilon^2}\right)$$

Statistical learning theory

Errors and the optimum
$$\mathrm{er}_D[h] = P_{(x,y)\sim D}\big(h(x)\ne y\big), \qquad \mathrm{er}_S[h] = \frac1n\sum_{i=1}^n \mathbb 1[h(x_i)\ne y_i]$$ $$h^*(x) = \mathbb 1\big[P(y=1\mid x)\ge 0.5\big], \qquad \mathrm{er}_D^* = \mathrm{er}_D[h^*] = \min_{\text{all } h}\mathrm{er}_D[h], \qquad \mathrm{er}_D[H] = \min_{h\in H}\mathrm{er}_D[h]$$
Finding $h^*$ from the generative form, and its error
$$P(y{=}1\mid x)\ge P(y{=}0\mid x) \iff P(y{=}1)f_1(x) \ge P(y{=}0)f_0(x) \ \ \underset{\text{equal priors}}{\iff}\ \ f_1(x)\ge f_0(x)$$ $$\mathrm{er}_D^* = P(y{=}0)\!\int_x\! f_0\,\mathbb 1[h^*\!\ne\!0]\,dx \;+\; P(y{=}1)\!\int_x\! f_1\,\mathbb 1[h^*\!\ne\!1]\,dx \quad \text{(sums \& PMFs if discrete)}$$
The decomposition
$$\mathrm{er}_S[h_S] - \mathrm{er}_D^* = \underbrace{\big(\mathrm{er}_S[h_S]-\mathrm{er}_D[h_S]\big)}_{\text{generalisation, either sign}} + \underbrace{\big(\mathrm{er}_D[h_S]-\mathrm{er}_D[H]\big)}_{\text{estimation} \,\ge\, 0} + \underbrace{\big(\mathrm{er}_D[H]-\mathrm{er}_D^*\big)}_{\text{approximation} \,\ge\, 0}$$
Generalisation: unbiased, then concentrated, then uniform
$$\mathbb{E}_S\big[\mathrm{er}_S[h]\big] = \mathrm{er}_D[h] \quad\text{(i.d. only)} \qquad\qquad P\big(\big|\mathrm{er}_S[h]-\mathrm{er}_D[h]\big|\ge\epsilon\big) \le 2e^{-2n\epsilon^2} \quad\text{(Hoeffding, } b-a=1)$$ $$A \subseteq B \Rightarrow P(A)\le P(B), \qquad A: \big|\mathrm{er}_S[h_S]-\mathrm{er}_D[h_S]\big|\ge\epsilon, \qquad B: \max_{h\in H}\big|\mathrm{er}_S[h]-\mathrm{er}_D[h]\big|\ge\epsilon$$ $$P(A) \;\le\; 2|H|\,e^{-2n\epsilon^2} \;\le\; \delta \qquad\Longrightarrow\qquad n \;\ge\; \frac{1}{2\epsilon^2}\log\frac{2|H|}{\delta}$$

Board variant: the professor drops the factor $2$, giving $|H|e^{-2n\epsilon^2}$ and $n\ge\frac{1}{2\epsilon^2}\log\frac{|H|}{\delta}$. Use whichever the question states. Monotonicity: $\epsilon\!\downarrow$, $\delta\!\downarrow$, $|H|\!\uparrow$ all push $n$ up — $\epsilon$ quadratically, the other two logarithmically.

Infinite classes
$$\#\text{labelings} \le 2^n \ \text{(all classifiers — bound fails)}, \qquad \le n^{d} \ \text{ if } \mathrm{VCdim}(H)=d \ \text{(bound works)}$$ $$P(A) \le n^{d}e^{-2n\epsilon^2} \to 0, \qquad n = O\!\left(\frac{d\log(1/\epsilon)+\log(1/\delta)}{\epsilon^2}\right) \quad\text{or}\quad n \ge C\left(\frac{d}{\epsilon^2}+\log\frac1\delta\right)$$ $$\#\text{labelings of } n \text{ points by } H_{\mathrm{int}} \;=\; \frac{n(n+1)}{2}+1, \qquad \text{by } c\text{-class arbitrary classifiers} \;=\; c^{\,n}$$
ClassVC dimCompression size
Intervals $H_{\mathrm{int}}$ in $\mathbb{R}$$2$$2$
Axis-parallel rectangles $H_{\mathrm{apr}}$ in $\mathbb{R}^2$$4$$4$
Axis-parallel boxes in $\mathbb{R}^d$$2d$$2d$
Union of $m$ intervals in $\mathbb{R}$$2m$—
Linear through origin in $\mathbb{R}^d$  /  with bias$d$  /  $d+1$—
Origin-centred circles in $\mathbb{R}^2$$1$—
$\mathrm{sign}(p(x))$, $\deg p\le m$, one feature$m+1$—
Triangles in $\mathbb{R}^2$$7$—
Finite class$\le\lfloor\log_2|H|\rfloor$—
All classifiers$\infty$—
ERM, estimation error, SRM
$$h_S^{\mathrm{ERM}} = \arg\min_{h\in H}\mathrm{er}_S[h] \quad \text{(maximises \textbf{accuracy}; NP-hard for } H_{\mathrm{lin}})$$ $$\big|\mathrm{er}_D[h_S^{\mathrm{ERM}}]-\mathrm{er}_D[H]\big| \le 2\max_{h\in H}\big|\mathrm{er}_S[h]-\mathrm{er}_D[h]\big| \;\Longrightarrow\; P(\cdot\ge\epsilon) \le P\big(\max \ge \tfrac{\epsilon}{2}\big)$$ $$\text{SRM: } \min_i \ \mathrm{er}_S\big[h_i^{\mathrm{ERM}}\big] + \sqrt{\frac{d_i\log(n/d_i)+\log(1/\delta)}{n}}, \qquad H_1\subseteq H_2\subseteq\cdots, \quad d_i = \mathrm{VCdim}(H_i)$$

Surrogates: logistic loss → logistic regression; hinge → SVM; exponential → boosting. Compression size $k$ ⇒ $\mathrm{VCdim} = O(k)$; the converse is the open sample compression conjecture.

Privacy

Randomized response (curator not trusted)
$$y_i = x_i \ \text{ w.p. } \frac{e^\epsilon}{1+e^\epsilon}, \qquad y_i = 1-x_i \ \text{ w.p. } \frac{1}{1+e^\epsilon}$$ $$\frac{P\big(RR(x)=b\big)}{P\big(RR(x')=b\big)} \le e^{\epsilon} \quad \forall b, \quad x,x' \text{ neighbouring} \qquad\qquad P\big(Y=b\mid X\big) = p^{\,\#\text{agree}}\,q^{\,\#\text{flip}}$$ $$\mathbb{E}[y_i] = x_i\frac{e^\epsilon-1}{e^\epsilon+1} + \frac{1}{1+e^\epsilon}, \qquad z_i = \left(y_i - \frac{1}{1+e^\epsilon}\right)\!\left(\frac{e^\epsilon+1}{e^\epsilon-1}\right), \qquad \mathbb{E}[\bar z]=\bar x$$
Differential privacy (curator trusted)
$$\epsilon\text{-DP}: \ \frac{P\big(M(x)\in S\big)}{P\big(M(x')\in S\big)} \le e^{\epsilon} \qquad (\epsilon,\delta)\text{-DP}: \ P\big(M(x)\in S\big) \le e^{\epsilon}P\big(M(x')\in S\big) + \delta$$ $$\Delta_1 = \max_{x,x' \text{nbr}}\big\|f(x)-f(x')\big\|_1, \qquad \Delta_2 = \max_{x,x' \text{nbr}}\big\|f(x)-f(x')\big\|_2, \qquad \Delta(\text{average of } n \text{ bits}) = \tfrac1n$$ $$\text{Laplace: } f(x) + \mathrm{Lap}\!\left(0,\tfrac{\Delta_1}{\epsilon}\right) \ \text{ is } \epsilon\text{-DP}, \qquad f_{\mathrm{Lap}}(x) = \tfrac{1}{2b}e^{-|x-\mu|/b}$$ $$\text{Gaussian: } f(x) + \mathcal N\!\left(0,\ \ln\!\tfrac1\delta \cdot \tfrac{\Delta_2^2}{\epsilon^2}\right) \ \text{ is } (\epsilon,\delta)\text{-DP}$$
Properties and the exponential mechanism
$$\text{Post-processing: } F\circ M \text{ is } (\epsilon,\delta)\text{-DP.} \qquad \text{Composition, basic: } (k\epsilon,\ k\delta)$$ $$\text{Composition, advanced (Gaussian only): } \left(\epsilon\sqrt{k\log(1/\delta')} + k\epsilon\big(e^\epsilon-1\big),\ \ k\delta+\delta'\right)$$ $$\text{EM: select } h\in H \text{ w.p. } \propto \exp\!\left(\frac{\epsilon}{2\Delta}S(x,h)\right), \quad \Delta = \max_{h\in H}\max_{x,x'\text{nbr}}\big|S(x,h)-S(x',h)\big|$$ $$P\!\left(S\big(x,EM(x)\big) \le OPT(x) - \Big(\tfrac{2\Delta}{\epsilon}\ln|H| + t\Big)\right) \le e^{-t}, \qquad S(x,p) = p\sum_i \mathbb 1(v_i \ge p)$$
MechanismTrustGuaranteeUtility / noise
Randomized responsenone$\epsilon$-DP$O\!\left(\frac{1}{\epsilon\sqrt n}\right)$
Laplacecurator$\epsilon$-DP$O\!\left(\frac{1}{\epsilon n}\right)$  ·  spread $\frac{d}{n\epsilon}$ for $d$ outputs
Gaussiancurator$(\epsilon,\delta)$-DPspread $\frac{\sqrt{d\ln(1/\delta)}}{n\epsilon}$ — $\sqrt d$ not $d$
Exponentialcurator$\epsilon$-DPwithin $\frac{2\Delta}{\epsilon}\ln|H|$ of $OPT$ w.h.p.

$\epsilon$ is the only privacy–utility dial; $n$ affects utility only. Small $\epsilon$ = private and noisy; large $\epsilon$ = accurate and exposed.

Complexity, all in one place

TaskNaiveFast / randomized
Apply JL map to $n$ points—$O(ndk)$
Nearest-neighbour query$O(nd)$JL: $O(dk+nk)$  ·  LSH: $O(n^\rho)$
SVD of $A_{m\times n}$$O(mn^2)$$O(mn\ell)$, $\ell = k+p$
Randomized SVD + $q$ power steps—$O(mn\ell q)$
Fast SVD given $Q$ (small SVD)—$O(nk^2)$
Similarity-graph edges$O(n^2)$$O(n\log n/\epsilon^2)$ after sparsification

Reference

Traps & confusions

Compiled from the professor's own "students get this wrong" remarks and from the wrong options that actually appeared on past papers — quiz 2 and end term. Every entry below is a mark someone lost. Entries 17–33 cover Weeks 7–12, which is where two-thirds of the end-term marks live.

01 · Markov gives a tail — read what is being asked

Markov bounds $P(X \ge a)$. If the question asks for $P(X \le a)$, you must take the complement, which flips the inequality direction: $P(X \le a) \ge 1 - \mathbb{E}[X]/a$. Both past papers had a Markov question and both required this step.

02 · Chebyshev is measured in $\sigma$-units

$P(|X-\mu| \ge k\sigma) \le 1/k^2$. Given an absolute threshold $t$, set $k = t/\sigma$ first. The bound is $\sigma^2/t^2$, never $1/t^2$.

03 · $A^\top A$ vs $AA^\top$

$A^\top A$ is $n\times n$ and gives the right singular vectors $V$ (this is the PCA covariance). $AA^\top$ is $m\times m$ and gives the left singular vectors $U$ (this is the covariance of the sketch $A\omega$). Both have the same non-zero eigenvalues $\sigma_i^2$, so a wrong answer looks symmetric and plausible — check the diagonal, not the off-diagonal.

04 · Eigenvalue vs singular value

$\lambda_i(A^\top A) = \sigma_i^2$, so $\sigma_i = \sqrt{\lambda_i}$. A past paper handed over the eigenvalue $12$ as a decoy option when the singular value was $\sqrt{12}$. Take the square root.

05 · Eckart–Young off-by-one

$\|A - A_k\|_2 = \sigma_{k+1}$ — the first singular value you discard, not the last you keep. And $\|\cdot\|_2$ means spectral norm: only one value, not a root-sum-of-squares of the discarded tail (that would be Frobenius, which this course does not state).

06 · JL is a statement about squared distances

$(1\pm\epsilon)$ multiplies $\|x-y\|^2$. If you want a bound on the distance itself, take a square root: $\|f(x)-f(y)\| \le \sqrt{1+\epsilon}\,\|x-y\|$. A past paper chose $\epsilon = 0.0201$ precisely so that $\sqrt{1+\epsilon} = 1.01$ exactly — a deliberate signal.

07 · $k$ does not depend on $d$

Stated three different ways across the two past papers. Any option where $k$ scales with the ambient dimension is wrong. Corollary: the ambient dimension is frequently a red herring in numeric questions — e.g. computing $\mathbb{E}\|Au\|^2$ for $R$ of shape $25\times10^4$ never uses the $10^4$.

08 · LSH: which knob moves which rate

$k$ (AND, hashes per table): pushes BOTH rates DOWN. Fixes FPR, damages TPR.
$L$ (OR, number of tables): pushes BOTH rates UP. Fixes TPR, damages FPR.

A past paper asked exactly this about $L$ and the correct answer was "TPR increases and FPR increases". Students who had memorised "more hashing = better filtering" chose the wrong pair.

09 · LSH bucket shapes

Euclidean (Datar) buckets are parallel slabs — infinite stripes, convex, arbitrary random orientation. Cosine buckets are angular wedges through the origin. Concentric circles/squares are always wrong: they hash by norm, so antipodal points on the same ring collide. And a single linear hash can never produce a bounded closed region.

Buckets being convex means the whole segment between two colliding points also collides — but only $\beta \in [0,1]$. Extending to the full line ($\beta \in \mathbb{R}$) leaves the slab. A past paper turned exactly on that one word.

10 · Sparsifier reweighting divides

$w' = w/p$, so surviving edges get heavier. Multiplying ($w \cdot p$) is the natural wrong move.

11 · Unbiasedness ≠ the spectral guarantee

$\mathbb{E}[f^\top L_H f] = f^\top L_G f$ holds for any positive sampling probabilities — the $p$ and $1/p$ cancel identically. Effective resistance is chosen for variance / concentration, so the $(1\pm\epsilon)$ bound holds w.h.p. with few edges. Zero expected error does not mean zero error.

12 · Laplacian sanity checks

$L = D - W$: diagonal is the weighted degree (sum of incident weights, not the count of neighbours); off-diagonal is $-w_{ij}$. Every row must sum to zero — use this to eliminate options instantly. A past paper offered $-W$ (zero diagonal) as a distractor; the row-sum test kills it in two seconds.

Careful with signs when a question asks for a difference of entries: $L_{11} - L_{42} = 15 - (-2) = 17$, not $13$.

13 · Cuts count crossing edges only

$\mathrm{cut}(A, A^c)$ sums edges with one endpoint on each side. Internal edges do not count. For a singleton $A = \{v\}$, the cut is the weighted degree of $v$. And watch for constraints in the question ("among cuts with $|A| = 1$…") — a disconnected graph has a global mincut of $0$ that the constraint may forbid.

14 · Mincut minimises crossing weight — so heavy edges stay together

A weight-$10$ edge tempts you to "cut the expensive one". Backwards: the cheapest cut avoids crossing heavy edges, so its endpoints end up on the same side.

15 · Power iteration cannot create what the sketch missed

$(AA^\top)^q$ rescales directions already present in the sketch's span by positive scalars — which does not change the span. It improves accuracy (sharpens the spectrum, reduces the tail), never coverage. A zero-mark bonus question on a past paper turned entirely on this.

16 · NP-hard vs computationally expensive

The professor separates these deliberately. The binary constrained mincut is NP-hard → fixed by relaxation to $f\in\mathbb{R}^n$. Dense eigendecomposition is merely expensive (polynomial) → fixed by sparsification. Different problems, different fixes.

17 · The three gaps — signs and tells

Estimation $\ge0$ ($\mathrm{er}_D[H]$ is a min over $H$ and $h_S\in H$). Approximation $\ge0$ ($\mathrm{er}_D^*$ is a min over all classifiers). Generalisation is unsigned — the train error can exceed the test error. Options asserting $\mathrm{er}_S[h_S]-\mathrm{er}_D[h_S]\ge0$ are wrong, and options asserting the other two $\le0$ are wrong.

Identifying them fast: the generalisation term is the only one containing $\mathrm{er}_S$; the approximation term is the only one containing $\mathrm{er}_D^*$. Find those two and the third is forced.

18 · $\delta$ is the failure probability, not the confidence

In $n \ge \frac{1}{2\epsilon^2}\log\frac{2|H|}{\delta}$, a larger $\delta$ means you tolerate more failure, so you need less data. "If $\delta$ increases then $n_0$ increases" is false and was a wrong option on the 2025 T3 end term.

Also on that MSQ: "$n_0$ is independent of $|H|$" is false — $|H|$ appears logarithmically, and a logarithm is not an absence. The two true options were $\epsilon\!\downarrow\Rightarrow n_0\!\uparrow$ and $|H|\!\uparrow\Rightarrow n_0\!\uparrow$.

19 · Uniform convergence does not bound the test error

It says train $\approx$ test. It says nothing about either being small. A class of two useless classifiers satisfies it with both errors at $0.5$. "Learnable" means the train error is a trustworthy measurement, not the classifier is good — judging $H$ is the approximation error's job.

Related: a zero train error does not imply zero generalisation error. On the May-2025 papers the ERM had $\mathrm{er}_S = 0$ and generalisation error $0.125$.

20 · VC dimension: the quantifiers are asymmetric

Condition 1 is ∃ a set of $k$ points, ∀ labelings — you pick the most convenient points. It is not "every set of $k$ points is shatterable"; degenerate configurations are allowed to fail.

Condition 2 flips it: ∀ sets of $k+1$ points, ∃ a bad labeling. Exhibiting one awkward set of $k+1$ points proves nothing. On an MSQ, "every set of $k$ points must be shatterable" and "some set of $k+1$ points fails" are both wrong.

21 · Read what a hypothesis class holds fixed

Both May-2025 papers asked for the VC dimension of $h_r(x)=\mathbb 1[\|x\|^2\le r^2]$ in $\mathbb{R}^2$. The answer is $1$, not $3$ — because the circles are centred at the origin, which removes both centre parameters and leaves a monotone threshold on $\|x\|$. Arbitrary discs would give $3$.

The parameter-count heuristic (interval $2$, rectangle $4$, box in $\mathbb{R}^d$ $2d$, union of $m$ intervals $2m$, homogeneous hyperplane $d$) is a good first guess, then verify with the game. It fails for triangles in $\mathbb{R}^2$: $6$ parameters, VC dimension $\mathbf 7$.

22 · Interval labelings: exact count vs the board's bound

The exact number of distinct labelings of $n$ points by $H_{\mathrm{int}}$ is $\frac{n(n+1)}{2}+1$ — contiguous runs, plus the empty one. At $n=5$ that is $\mathbf{16}$.

The professor's board count $(n+1)+n+\cdots+1$ over-counts (it recounts all-zeros once per left endpoint) and is only meant as an $O(n^2)$ upper bound for the convergence argument. If the question says "maximum number of labelings", use the exact formula; $21$ was the trap answer at $n=5$.

23 · Bayes error: charge the losing density, never both

In the overlap region, $h^*$ picks the class with the higher density and errs only on the other one. Charging both classes for the overlap is the standard mistake and it roughly triples the answer.

Corollary trap (Q178, both May-2025 papers): $h^*$ is not $1$ throughout the support of $x\mid y=1$. On $[-1,0]$ both classes were possible and class $0$ was twice as dense, so $h^*=0$ there. Overlap is resolved by which density is larger, not by which is non-zero.

24 · ERM maximises accuracy — nothing else

$\mathrm{er}_S$ is the $0$–$1$ loss, so minimising it maximises accuracy. Not F1, not precision, not log loss. Log loss is a surrogate you minimise because the $0$–$1$ objective is NP-hard — a means, not the target.

Keep the two obstructions of this half of the course apart: the Bayes classifier is blocked by information ($D$ unknown); ERM is blocked by computation (NP-hard even with all the data in hand).

25 · More data cannot fix approximation error

Both terms of $\mathrm{er}_D[H]-\mathrm{er}_D^*$ are population quantities — no sample appears. Collecting a billion more points changes it by exactly zero. It is fixed the moment you choose $H$, and only SRM (or a better class) touches it.

Generalisation and estimation do shrink with $n$ — and via the same theorem: estimation is bounded by twice the worst-case train/test gap, hence uniform convergence at $\epsilon/2$, which costs a factor of four in $n$.

26 · Sample compression: what is known, what is open

Known: a compression scheme of size $k$ implies $\mathrm{VCdim}(H) = O(k)$. Open for 30+ years: whether $\mathrm{VCdim}(H)=k$ implies a scheme of size $k$. Any option stating the second direction as established is wrong.

And keep the two examples straight: $H_{\mathrm{int}}$ has size $2$, $H_{\mathrm{apr}}$ has size $4$. An MSQ on both May-2025 papers offered "$H_{\mathrm{int}}$ has a scheme of size $4$" as a distractor.

27 · Randomized response: $p > \tfrac12$, and $Y$ is not $Z$

The truth probability is $p = \frac{e^\epsilon}{1+e^\epsilon} > \tfrac12$ for every $\epsilon > 0$; the flip probability is $q = \frac{1}{1+e^\epsilon} < \tfrac12$. Swapping them is the commonest error, and at $\epsilon=0.1$ they are so close ($0.525$ vs $0.475$) that the answer looks plausible either way.

Every past-paper question asks for $P(Y=b\mid X)$ where $Y$ is the intermediate vector — the reported bits, before debiasing. Answer $p^{\#\text{agree}}q^{\#\text{flip}}$. The debiased $Z$ never appears in a numeric question.

28 · $\epsilon$ trades privacy for utility; $n$ only buys utility

Larger $\epsilon$ = better utility, worse privacy. "Increasing $\epsilon$ improves privacy" is backwards — privacy is the ratio bound $e^\epsilon$, and a larger ratio is easier for the adversary to exploit.

$n$ appears only in the utility bound. The privacy proof cancels the other $n-1$ factors and never mentions $n$. Surveying more people does not make an individual more private — that asymmetry is what lets you fix $\epsilon$ from the privacy requirement and then choose $n$ for accuracy.

29 · Sensitivity of the average is $1/n$, not $1$

$\Delta = \max|f(x)-f(x')|$ over neighbours. For the average of $n$ bits the first $n-1$ terms cancel and the last differs by $1$, so $\Delta = \tfrac1n$ — and Laplace noise has spread $\tfrac{\Delta}{\epsilon} = \tfrac{1}{n\epsilon}$.

$\Delta = 1$ is the sensitivity of the sum. Two directions to keep straight: more people → lower sensitivity → less noise; smaller $\epsilon$ (stricter privacy) → more noise. And it is $\Delta/\epsilon$, never $\Delta\epsilon$.

30 · A trusted curator does not make the release safe

Trust concerns who holds the data; the danger is what gets published. Release the exact average and an adversary who knows $n-1$ records recovers the last one by subtraction. "Releasing the exact average is safe because the curator is trusted" is false.

What trust does buy: one noise injection instead of $n$, hence $O\!\left(\frac{1}{\epsilon n}\right)$ instead of $O\!\left(\frac{1}{\epsilon\sqrt n}\right)$ — quadratically better utility at identical $\epsilon$.

31 · Laplace uses $\ell_1$; Gaussian uses $\ell_2$

For a $d$-dimensional release with each component $\tfrac1n$-sensitive: $\Delta_1 = \tfrac dn$ gives Laplace spread $\tfrac{d}{n\epsilon}$ (linear in $d$), while $\Delta_2 = \tfrac{\sqrt d}{n}$ gives Gaussian spread $\tfrac{\sqrt{d\ln(1/\delta)}}{n\epsilon}$ ($\sqrt d$).

That is the whole reason to accept $(\epsilon,\delta)$-DP. The other reason: advanced composition ($\epsilon\sqrt k$ instead of $k\epsilon$) holds for the Gaussian mechanism and not for Laplace — which is why private gradient descent uses Gaussian noise.

32 · Exponential mechanism: probability from the score, not the candidate

$P(h) \propto \exp\!\left(\frac{\epsilon}{2\Delta}S(x,h)\right)$. Two candidates with equal scores get equal probability, whatever their numeric values. In the $10,10,500$ example, prices $10$ and $30$ both earn revenue $30$ and are therefore equally likely.

This is exactly what perturbing the price gets wrong: Laplace noise around $p^\star=500$ favours $30$ over $10$ for no reason the objective recognises, and noise pushing past $500$ drops the revenue to zero, not to "slightly less". Never add noise to the argument of a ragged function.

33 · JL guarantees the dataset's pairs, not all of $\mathbb{R}^d$

The distortion bound holds for $x,y \in D$ — the union bound was taken over the $\binom n2$ dataset pairs, which is where $\log n$ comes from. Extending it to all $x,y\in\mathbb{R}^d$ is false: with $k<d$ the map has a kernel, so some distinct pair collapses to a single point.

That was a wrong option on the 2025 T3 end term, and ticking it contradicts Step 1 of the JL unit — no exact isometry exists. Linearity ($f(0)=0$, additivity), by contrast, is free once the question says "linear map".


Past papers · End term

End-term papers, solved

Both available end-term papers, every question, with the answer key, the derivation, and the trap each wrong option was built to catch.

What the papers look like

May 2025 — 50 marks. The two PDFs in circulation (ET 1 and ET 2) are the same paper with different question IDs and a different shuffle: Q170–191 in one, Q252–274 in the other. If you have "done both", you have done one.

2025 T3 — 40 marks over 19 scored questions plus a zero-mark bonus. Numeric-heavy: 12 of the 19 are short-answer numbers.

No negative marking on either. Both papers lean on comprehension blocks — a shared setup followed by two or three sub-questions — so one modelling error costs you the whole block. Read the block header twice before answering any part of it.

Where the marks actually are

Half of the syllabusMay 20252025 T3CombinedShare
Weeks 7–10 — statistical learning theory32275966%
Weeks 1–6 — randomised algorithms13102326%
Weeks 11–12 — privacy5389%
Total504090100%
Read that table carefully — it is the single most useful fact on this page

The end term is roughly two-thirds statistical learning theory. Weeks 1–6, which were the entire Quiz 2 syllabus, contribute about a quarter — and when they do appear it is only ever the statements: the JL guarantee, the two LSH inequalities, $L=D-W$, Eckart–Young. No JL derivation, no randomized-SVD algorithm trace, no effective resistance.

Inside the learning-theory two-thirds, the concentration is heavier still. VC dimension and the error decomposition together are about half of it, and both papers ask for a VC dimension of a class you have never seen before — cuboids, polynomial signs, unions of intervals, origin-centred circles. Being fluent at deriving a VC dimension from the two-player game matters more than having memorised the four in the notes.

TopicMarksWhat actually gets asked
VC dimension17Unfamiliar classes: cuboids in $\mathbb{R}^3$, $\mathrm{sign}(p(x))$ for $\deg p\le4$, union of $3$ intervals, origin-centred circles, $\le\log_2|H|$ for a finite class
Error decomposition16Name the three gaps; their signs; compute estimation and approximation from a stated $D$
Bayes classifier & error14Cross two class-conditional densities, find $\theta$, integrate the overlap. Uniform, exponential, discrete PMFs
ERM & generalisation numerics13Find $\theta^\star$ or the best $w$ on a 4-point dataset; then train error, then $|$generalisation error$|$
Privacy8Only randomized response, only $P(Y=b\mid X)$, always $\epsilon=0.1$
Uniform convergence6$P(A)\le P(B)$; monotonicity of $n_0$ in $\epsilon,\delta,|H|$
JL / random projections7Linearity + the guarantee holds on $D$, not all of $\mathbb{R}^d$; mean and variance of $a^\top r$
LSH6The two sensitivity conditions; TPR/FPR after AND–OR; can TPR $=$ FPR
SVD5Eckart–Young; read $\sigma_{k+1}$ off a list; best rank-1 from a given SVD
Labeling counts4$c^n$ for $c$ classes; exact interval count $\tfrac{n(n+1)}{2}+1$
Sample compression4Size for $H_{\mathrm{int}}$ ($2$) and $H_{\mathrm{apr}}$ ($4$)
Spectral clustering / sparsification5$L=D-W$, $0$ is an eigenvalue, PSD-not-PD; the $(1\pm\epsilon)$ quadratic form
ERM definition2Which metric it maximises

Notice what is absent despite being examinable: Markov / Chebyshev / Hoeffding numerics, the randomized-SVD six-step trace, effective resistance, the Datar hash construction, SRM, and every privacy mechanism after randomized response — no Laplace numeric, no Gaussian, no exponential mechanism. Two papers is a small sample and the syllabus is the syllabus, so this is a guide to ordering your revision, not to skipping any of it.

May 2025

Q170 · MCQ · 2Sparsification
$G=(V,E,W)$ is undirected and weighted; $H=(V,F,W')$ with $F\subset E$ is its sparsification, $|V|=n$. Under what condition is $H$ an $\epsilon$-spectral approximation of $G$?
  • A$(1-\epsilon)\theta^\top L_H\theta \le \theta^\top L_G\theta \le (1+\epsilon)\theta^\top L_H\theta$ for all $\theta\in\mathbb{R}^n$
  • B$(1-\epsilon)\theta^\top L_G\theta \le \theta^\top L_H\theta \le (1+\epsilon)\theta^\top L_G\theta$ for all $\theta\in\mathbb{R}^n$
  • C$(1-\epsilon)\theta^\top L_G\theta \le \theta^\top L_H\theta \le (1+\epsilon)\theta^\top L_H\theta$ for all $\theta\in\mathbb{R}^n$
  • D$(1-\epsilon)\theta^\top L_G\theta \le \theta^\top L_G\theta \le (1+\epsilon)\theta^\top L_H\theta$ for all $\theta\in\mathbb{R}^n$
Answer — B

The approximated object goes on the outside; the approximation is sandwiched. $H$ approximates $G$, so $\theta^\top L_H\theta$ sits in the middle with $(1\pm\epsilon)\theta^\top L_G\theta$ as the bounds.

Traps: A has the roles reversed (a statement about $G$ approximating $H$, which is not what "$H$ is a sparsification of $G$" means). C and D each mix $G$ and $H$ across the two bounds, so they are not even a sandwich — they compare a quantity to itself scaled two different ways. Sanity check any candidate by setting $\epsilon=0$: the correct form must collapse to $\theta^\top L_H\theta = \theta^\top L_G\theta$. Only B does.

Q171 · NAT · 2Labelings
A sample of $5$ data-points for a classification problem with $3$ classes. We can have at most $k$ different labelings. Tightest upper bound for $k$?
Answer — 243

Each point takes one of $3$ labels, independently: $3^5 = \mathbf{243}$.

This tests whether you understand where the $2^n$ in the uniform-convergence argument comes from. Traps: $5^3=125$ (base and exponent swapped); $2^5=32$ (forgot three classes); $15 = 5\times3$ (added instead of exponentiated).

Q172 · NAT · 3VC dimension
Single feature in $\mathbb{R}$, labels in $\{0,1\}$, $H = \{h_{a_1\dots a_6} : a_1<a_2<\dots<a_6\}$ where $h(x)=1$ iff $x\in[a_1,a_2]\cup[a_3,a_4]\cup[a_5,a_6]$. Find $\mathrm{VCdim}(H)$.
Answer — 6

Three intervals produce at most three positive runs on a sorted set of points.

$\ge6$: take any $6$ points. Whatever the labeling, its $1$s form at most $3$ maximal runs (you cannot fit $4$ separated runs into $6$ positions), and each run is covered by one interval. All $2^6$ labelings are reachable. ✓

$<7$: for any $7$ points ask for $+,-,+,-,+,-,+$ — four positive runs, one more than three intervals can supply. ✓

So $\mathrm{VCdim} = \mathbf 6$, matching the $6$ free endpoints. Trap: "three intervals, each of VC dimension $2$" invites $2$ or $3$; the parameter count $2m$ is the right instinct.

Q173 · NAT · 3SVD
$A\in\mathbb{R}^{3\times3}$ has SVD with $U = \begin{bmatrix}1&0&0\\0&\tfrac1{\sqrt2}&\tfrac1{\sqrt2}\\0&\tfrac1{\sqrt2}&-\tfrac1{\sqrt2}\end{bmatrix}$, $\Sigma = \mathrm{diag}(3,2,1)$, $V = I$. The best rank-1 approximation $B$ is diagonal. Find the sum of the diagonal entries of $B$.
Answer — 3

The best rank-1 approximation keeps only the top singular triplet:

$$B = \sigma_1 u_1 v_1^\top = 3\begin{bmatrix}1\\0\\0\end{bmatrix}\begin{bmatrix}1&0&0\end{bmatrix} = \begin{bmatrix}3&0&0\\0&0&0\\0&0&0\end{bmatrix}$$

Trace $= 3+0+0 = \mathbf 3$.

Two shortcuts to notice. First, the messy $\tfrac1{\sqrt2}$ block is in $u_2,u_3$ — completely irrelevant to a rank-1 approximation. Second, the question already tells you $B$ is diagonal, which confirms you only need $u_1v_1^\top$. Traps: $6 = 3+2+1$ (the trace of $A$ itself, i.e. keeping everything); $2$ or $1$ (wrong singular value — $\sigma_1$ is the largest).

Q174 · NAT · 3VC dimension
Features in $\mathbb{R}^2$, labels in $\{0,1\}$, $H=\{h_r : r\in\mathbb{R}\}$ with $h_r(x)=1$ iff $\|x\|^2\le r^2$ — decision boundary a circle centred at the origin. Find $\mathrm{VCdim}(H)$.
Answer — 1

The classifier reads only $\|x\|$, so it is a monotone threshold on one number: if a point is labelled $1$, every point nearer the origin is too.

$\ge1$: a single point at $\|x\|=1$ takes label $1$ with $r=2$ and label $0$ with $r=0$. ✓

$<2$: for any two points with $\|x_1\|\le\|x_2\|$, the labeling $h(x_1)=0$, $h(x_2)=1$ is impossible — a circle containing the farther point contains the nearer one. ✓

Traps: $3$ is the VC dimension of arbitrary discs in $\mathbb{R}^2$; $2$ is a parameter count that wrongly includes a centre. Centring at the origin is doing all the work — it removes two parameters and leaves a one-dimensional monotone family. Read what is held fixed.

Q175 · MCQ · 2Decomposition
Consider (1) $\mathrm{er}_D(H)-\mathrm{er}_D^*$, (2) $\mathrm{er}_S(h_S)-\mathrm{er}_D(h_S)$, (3) $\mathrm{er}_D(h_S)-\mathrm{er}_D(H)$. Choose the most appropriate matching.
  • A(1) approximation, (2) generalisation, (3) estimation
  • B(1) generalisation, (2) approximation, (3) estimation
  • C(1) estimation, (2) approximation, (3) generalisation
  • D(1) approximation, (2) estimation, (3) generalisation
Answer — A

Identify each by which two levels it compares, and the names follow:

  • (1) best-in-$H$ vs Bayes → how well $H$ can approximate the optimum → approximation
  • (2) train vs test for the same classifier → does it generalise beyond the sample → generalisation
  • (3) what you got vs best-in-$H$ → how well the algorithm estimated the best member → estimation

The reliable tell: the generalisation term is the only one containing $\mathrm{er}_S$, and the approximation term is the only one containing $\mathrm{er}_D^*$. Spot those two and the third is forced — you never need to recall all three names at once.

Q176 · MSQ · 2Decomposition
Select all true statements.
  • A$\mathrm{er}_D(H)-\mathrm{er}_D^* \ge 0$
  • B$\mathrm{er}_D(h_S)-\mathrm{er}_D(H) \ge 0$
  • C$\mathrm{er}_D(H)-\mathrm{er}_D^* \le 0$
  • D$\mathrm{er}_D(h_S)-\mathrm{er}_D(H) \le 0$
Answer — A and B

Both are "a minimum over a smaller set cannot beat a minimum over a bigger one":

  • $\mathrm{er}_D^* = \min$ over all classifiers $\le \min$ over $H$ $= \mathrm{er}_D(H)$ ⇒ A.
  • $\mathrm{er}_D(H) = \min_{h\in H}\mathrm{er}_D(h) \le \mathrm{er}_D(h_S)$ since $h_S\in H$ ⇒ B.

C and D are the negations. Both quantities can be zero (if $h^*\in H$, or if the algorithm happens to return the best member), which is consistent with $\ge0$ — a common source of doubt on this MSQ. Note that the generalisation term is deliberately absent from all four options, because it is the one with no guaranteed sign.

Q177 · MCQ · 2Bayes error
Which of the following is true? Select the most appropriate answer.
  • AThe Bayes error is non-negative.
  • BThe Bayes error is zero.
  • CThe Bayes error is positive.
  • DThe Bayes error is negative.
Answer — A

$\mathrm{er}_D^*$ is a probability, so $\ge0$ always. The phrase "most appropriate" is doing real work here: B and C are each true only sometimes.

Zero when the class-conditional densities have disjoint support (the concentric-circles example on the T3 paper — $\mathrm{er}_D^*=0$). Positive when they overlap (the exponential example — $\mathrm{er}_D^*=0.375$). Only "non-negative" holds for every $D$, and D is impossible.

The wider lesson for MCQs on this paper: when several options are ordered by strength, the answer is the weakest claim that is always true, not the most impressive-sounding one.

Q178 · MCQ · 3Bayes classifier
One feature in $\mathbb{R}$, labels $\{0,1\}$. $P(y=1)=0.5$, $x\mid y=1\sim U[-1,3]$, $x\mid y=0\sim U[-2,0]$. Which is $h^*$?
  • A$h^*(x)=1$ for $0\le x\le3$; $0$ for $-2\le x<0$
  • B$h^*(x)=1$ for $-1\le x\le3$; $0$ for $-2\le x<-1$
  • C$h^*(x)=1$ for all $-2\le x\le3$
  • D$h^*(x)=0$ for all $-2\le x\le3$
Answer — A

Priors are equal, so compare densities. $f_1 = \tfrac{1}{3-(-1)} = \tfrac14$ on $[-1,3]$; $f_0 = \tfrac{1}{0-(-2)} = \tfrac12$ on $[-2,0]$.

Region$f_1$$f_0$$h^*$
$[-2,-1)$$0$$\tfrac12$$0$
$[-1,0]$$\tfrac14$$\tfrac12$$0$
$(0,3]$$\tfrac14$$0$$1$

B is the trap, and it is the good one. It says $h^*=1$ throughout the support of $x\mid y=1$ — i.e. "predict $1$ wherever class $1$ is possible". But on $[-1,0]$ both classes are possible and class $0$ is twice as dense, so $h^*$ must say $0$ there. Overlap is resolved by which density is larger, not by which is non-zero.

The narrower uniform has the higher density — $U[-2,0]$ packs the same mass into half the width — which is exactly why it wins the contested region. Worth sketching: two rectangles of heights $\tfrac14$ and $\tfrac12$.

Q179 · NAT · 3Bayes error
Same setup. Find the Bayes error.
Answer — 0.125

$h^*$ says $1$ exactly on $[0,3]$. Charge each class only where $h^*$ gets that class wrong:

$$\mathrm{er}_D^* = \underbrace{P(y=1)\,P\big(x<0\mid y=1\big)}_{\text{class 1 predicted }0} + \underbrace{P(y=0)\,P\big(x\ge0\mid y=0\big)}_{\text{class 0 predicted }1}$$

Class $1$: $x\sim U[-1,3]$, so $P(x<0) = \tfrac{1}{4}$ (length $1$ out of $4$). Class $0$: $x\sim U[-2,0]$, so $P(x\ge0)=0$ (a single point, measure zero).

$$\mathrm{er}_D^* = 0.5\times\tfrac14 + 0.5\times0 = \mathbf{0.125}$$

Trap: charging both classes for the overlap region $[-1,0]$ gives $0.5\cdot\tfrac14 + 0.5\cdot\tfrac12 = 0.375$ — wrong, because $h^*$ is correct for class $0$ throughout that region. The Bayes error counts the mass of the losing density in each region, never both.

Cross-check the geometry: on $[-1,0]$ the two density heights are $\tfrac14$ and $\tfrac12$; the Bayes error is the area under the lower curve, $\tfrac14\times1 = 0.25$, times the prior $0.5$, giving $0.125$. ✓

Q180–182 · NAT · 2+2+3ERM · comprehension
Labels $\{0,1\}$, two binary features $x=(x_1,x_2)$. $P(y=1)=0.5$; $P((0,0)\mid y=1)=0.25$ and $P((0,0)\mid y=0)=1$. $H=\{h_\theta : \theta\in\mathbb Z\}$ with $h_\theta(x)=1$ iff $x_1+x_2\ge\theta$. Dataset $S$: $(0,0)\to0$ and $(1,0),(0,1),(1,1)\to1$.
(180) Find $\theta^\star$ for the ERM. (181) Find $\mathrm{er}_S(h_S^{\mathrm{ERM}})$. (182) Find $|$generalisation error of $h_S^{\mathrm{ERM}}|$.
Answers — 1, then 0, then 0.125

(180) The feature $x_1+x_2$ takes value $0$ at $(0,0)$ and $1$ or $2$ at the other three points. So the threshold $\theta=1$ separates them perfectly:

$x$$x_1+x_2$$y$$h_1(x)$
$(0,0)$$0$$0$$0$ ✓
$(1,0)$$1$$1$$1$ ✓
$(0,1)$$1$$1$$1$ ✓
$(1,1)$$2$$1$$1$ ✓

$\theta^\star = \mathbf 1$. (Check the neighbours: $\theta=0$ predicts $1$ everywhere — one error; $\theta=2$ misses $(1,0)$ and $(0,1)$ — two errors.)

(181) Zero errors out of four, so $\mathrm{er}_S = \mathbf 0$.

(182) Generalisation error $= \mathrm{er}_S[h_1] - \mathrm{er}_D[h_1] = 0 - \mathrm{er}_D[h_1]$, so compute the test error. $h_1$ predicts $0$ only at $(0,0)$, so:

$$\mathrm{er}_D[h_1] = \underbrace{P(y{=}1)\,P\big((0,0)\mid y{=}1\big)}_{\text{class 1 landing on }(0,0)} + \underbrace{P(y{=}0)\,P\big(x\ne(0,0)\mid y{=}0\big)}_{\text{class 0 landing elsewhere}}$$ $$= 0.5\times0.25 \;+\; 0.5\times(1-1) \;=\; 0.125 + 0 \;=\; 0.125$$

So $|$generalisation error$| = |0-0.125| = \mathbf{0.125}$.

What the two given PMF entries are for: $P((0,0)\mid y=0)=1$ means class $0$ always lands on $(0,0)$, so $h_1$ never errs on class $0$ — that whole term vanishes. $P((0,0)\mid y=1)=0.25$ is the only other number needed. The remaining three probabilities under $y=1$ sum to $0.75$ but are never used individually. The paper hands you exactly two entries and no more; if you find yourself wanting a third, you have taken a wrong turn.

Trap: a zero train error tempts you to answer $0$ for the generalisation error too. Train and test errors are different objects — a perfect fit on four points says nothing about a distribution where $25\%$ of class-$1$ mass sits on the one point you label $0$.

Q183 · NAT · 2VC dimension
$H=\{h_1,h_2,\dots,h_{100}\}$ is a set of binary classifiers. Find the tightest upper bound for $\mathrm{VCdim}(H)$.
Answer — 6

Shattering $k$ points means realising all $2^k$ labelings, and each labeling needs at least one distinct classifier:

$$2^k \le |H| = 100 \;\Longrightarrow\; k \le \log_2 100 \approx 6.64 \;\Longrightarrow\; k \le \mathbf 6$$

Check: $2^6 = 64 \le 100$ ✓, $2^7 = 128 > 100$ ✗.

This is the general fact $\mathrm{VCdim}(H)\le\lfloor\log_2|H|\rfloor$ — and it is exactly why "$\log|H| \to d$" is the right substitution when moving from the finite to the infinite uniform-convergence theorem. Traps: $100$ and $50$ ignore the exponential; $7$ forgets to floor.

Q184 · MSQ · 3VC · compression
Select all true statements regarding $H_{\mathrm{int}}$, the hypothesis class of interval classifiers.
  • AThe VC dimension of $H_{\mathrm{int}}$ is $2$.
  • BThe VC dimension of $H_{\mathrm{int}}$ is $4$.
  • C$H_{\mathrm{int}}$ has a sample compression scheme of size $2$.
  • D$H_{\mathrm{int}}$ has a sample compression scheme of size $4$.
Answer — A and C

VC dimension $2$: two points are shattered (interval over both, over each singly, over neither); three points $x_1<x_2<x_3$ defeat it with $+,-,+$, since an interval containing $x_1$ and $x_3$ must contain $x_2$.

Compression size $2$: keep the two extreme positive points; the interval they span reproduces every label.

B and D are $H_{\mathrm{apr}}$'s numbers (axis-parallel rectangles) — the paper is checking that you have not merged the two classes. The safest way to keep them apart: count free endpoints. An interval has $2$ ($a,b$); a rectangle has $4$ ($a,b,c,d$). Both the VC dimension and the compression size follow that count for these two classes.

Q185–186 · NAT · 2+2JL
$r$ is a random vector whose entries are standard normal, and $a = (1,-1,1,1)\in\mathbb{R}^4$. (185) Find the mean of $a^\top r$. (186) Find the variance of $a^\top r$.
Answers — 0, then 4

$a^\top r = \sum_i a_ir_i$ is a linear combination of independent $\mathcal N(0,1)$ variables, so it is Gaussian with

$$\mathbb{E}[a^\top r] = \sum_i a_i\,\mathbb{E}[r_i] = 0 \qquad\qquad \mathrm{Var}(a^\top r) = \sum_i a_i^2\,\mathrm{Var}(r_i) = \|a\|^2$$ $$\|a\|^2 = 1^2+(-1)^2+1^2+1^2 = \mathbf 4$$

So $a^\top r \sim \mathcal N(0, \|a\|^2)$ — the single fact the entire JL proof rests on, and the same one that makes $\Delta = a^\top(x-y)\sim\mathcal N(0,\|x-y\|^2)$ in the LSH collision analysis.

Traps: $2$ for the variance is $\|a\|$ rather than $\|a\|^2$. And the $-1$ must be squared — anyone who computes $\sum a_i = 2$ and reports that has confused the mean with a sum of coefficients. Note the mean is $0$ regardless of $a$; only the variance sees the vector.

Q187–189 · MCQ · 1+1+2LSH · comprehension
An $(r,c,p_1,p_2)$-sensitive family $H$. $L$ tables, each of length $k$, where each of the $k$ entries is a hash sampled from $H$. A collision happens if there is an exact match in at least one of the $L$ tables.
(187) Which is the TPR? (188) Which is the FPR? (189) Given $p_1>p_2$, can TPR $=$ FPR?
  • A$1-(1-p_1^k)^L$
  • B$1-(1-p_2^k)^L$
  • C$(1-p_1^k)^L$
  • D$(1-p_2^k)^L$
Answers — A, then B, then No

The construction, read off the wording. "Exact match" within a table means all $k$ hashes agree — an AND, giving $p^k$. "At least one of $L$ tables" is an OR, so take the complement of "all $L$ fail": $1-(1-p^k)^L$.

TPR uses near pairs, which collide with probability $\ge p_1$: $1-(1-p_1^k)^L$. FPR uses far pairs, probability $\le p_2$: $1-(1-p_2^k)^L$. C and D are the miss probabilities — the complements — and are the standard distractor pair.

(189) No. Since $p_1>p_2>0$ we get $p_1^k > p_2^k$, hence $1-p_1^k < 1-p_2^k$, hence $(1-p_1^k)^L < (1-p_2^k)^L$, hence TPR $>$ FPR — strictly, for every $k$ and $L$. The paper says "avoid all approximations and use the formulae", which is a direct instruction to run this monotonicity chain rather than reason from the $\rho$ approximations.

Why the answer is reassuring: if TPR could equal FPR the scheme would be worthless — the whole point of amplification is that AND and OR move both rates but never let the far curve catch the near one. Every step of $t\mapsto t^k$ and $t\mapsto 1-(1-t)^L$ is strictly increasing.

Q190 · NAT · 3Privacy
Randomized response applied to true data $X=(1,0,1,1,0)$ with $\epsilon=0.1$. $Y$ is the intermediate random vector. Compute $P\big(Y=(1,1,1,1,1)\mid X=(1,0,1,1,0)\big)$.
Answer — 0.033

Truth probability $p = \frac{e^{0.1}}{1+e^{0.1}} = 0.52498$; flip probability $q = \frac{1}{1+e^{0.1}} = 0.47502$. Compare coordinatewise:

$$X = (1,0,1,1,0), \quad Y = (1,1,1,1,1) \;\Longrightarrow\; \text{agree at } 1,3,4;\ \text{flip at } 2,5$$ $$P = p^3q^2 = (0.52498)^3(0.47502)^2 = 0.144687 \times 0.225644 = \mathbf{0.0326}$$

Accepted range on the paper: $0.030$–$0.035$.

The recipe, once and for all: count agreements $a$ and disagreements $f$ between $X$ and the requested $Y$, then answer $p^aq^f$ with $a+f=n$. Independence across people is what lets you multiply.

Traps: swapping $p$ and $q$ (remember $p>\tfrac12$ whenever $\epsilon>0$); and reading $Y$ as the debiased vector $Z$ — the question says "intermediate", which is the reported bits before any debiasing. Sanity check: at $\epsilon=0.1$ both $p,q\approx\tfrac12$, so any five-bit pattern must have probability near $2^{-5}=0.031$. ✓

Q191

Both source PDFs are truncated: Q191 (the second sub-question of the randomized-response block, worth the remaining $2$ marks) is absent from ET 1, and ET 2's Q274 is present as an MSQ header with its options cut off. Given the block defines both the intermediate vector $Y$ and the output vector $Z$, the missing part almost certainly concerns the debiasing step — $\mathbb{E}[z_i]=x_i$, $\mathbb{E}[\bar z]=\bar x$, and the utility bound $O(1/(\epsilon\sqrt n))$. Make sure you can state all three.

2025 T3

Q2 · MCQ · 2ERM
Which of the following metrics is the ERM primarily designed to maximize by design?
  • AAccuracy
  • BF1 score
  • CPrecision
  • DLog loss
Answer — A

$h_S^{\mathrm{ERM}} = \arg\min_{h\in H}\mathrm{er}_S[h]$ and $\mathrm{er}_S$ is the fraction misclassified, so ERM maximises $1-\mathrm{er}_S = $ accuracy.

F1 and precision weight false positives and false negatives differently and would require a different objective — which is precisely why plain ERM behaves poorly on imbalanced data. Log loss is the subtlest distractor: it is a surrogate, a convex stand-in minimised because the $0$–$1$ loss is NP-hard. Minimising it is a means to the end, not the end ERM is defined by. And note the wording "by design" — the question is about the definition, not about downstream behaviour.

Q3 · MSQ · 3JL
A dataset $D$ of $n$ points in $\mathbb{R}^d$. Given $0<\epsilon<1$, let $f$ be a linear map $\mathbb{R}^d\to\mathbb{R}^k$, an approximate isometry as guaranteed by the JL lemma. Which are true?
  • A$f(0)=0$
  • B$f(x+y)=f(x)+f(y)$ for all $x,y\in\mathbb{R}^d$
  • C$(1-\epsilon)\|x-y\|^2 \le \|f(x)-f(y)\|^2 \le (1+\epsilon)\|x-y\|^2$ for all $x,y\in D$
  • D$(1-\epsilon)\|x-y\|^2 \le \|f(x)-f(y)\|^2 \le (1+\epsilon)\|x-y\|^2$ for all $x,y\in\mathbb{R}^d$
Answer — A, B and C

A and B are free: the question tells you $f$ is linear, and $f(x)=Mx$ satisfies both by definition of matrix multiplication. Do not overthink them.

The whole question is C versus D, and this is the single most important distinction in the JL unit. The lemma guarantees distortion bounds on the $\binom n2$ pairs of the dataset — that is what the union bound was taken over, and where the $\log n$ in $k\in O(\log n/\epsilon^2)$ comes from. Extending to all of $\mathbb{R}^d$ would be a union bound over uncountably many pairs, and it is false: since $k<d$, the map has a non-trivial kernel, so there exist $x\ne y$ with $f(x)=f(y)$ and a distortion of $-100\%$.

That is Step 1 of the unit — no exact isometry exists — reappearing as a wrong option. If you ticked D you also contradicted the very first lemma of the JL derivation.

Q4 · MSQ · 2LSH
A family $H$ is $(r,c,p_1,p_2)$-sensitive for some $r>0$, $c>1$, $0\le p_2<p_1\le1$ if exactly two conditions hold for any pair $x,y\in\mathbb{R}^d$. What are these two conditions?
  • A$\|x-y\|\le r \Rightarrow P_{h\sim H}(h(x)=h(y)) \ge p_1$
  • B$\|x-y\|\ge cr \Rightarrow P_{h\sim H}(h(x)=h(y)) \le p_2$
  • C$\|x-y\|\le r \Rightarrow P_{h\sim H}(h(x)=h(y)) \le p_2$
  • D$\|x-y\|\ge cr \Rightarrow P_{h\sim H}(h(x)=h(y)) \ge p_1$
Answer — A and B

Near pairs collide often; far pairs collide rarely. Close ($\le r$) ⇒ probability at least $p_1$ (the big one). Far ($\ge cr$) ⇒ probability at most $p_2$ (the small one).

C and D are the same two implications with the conclusions swapped — a family satisfying them would hash distant points together and nearby points apart, which is worse than useless.

Two things to carry into the exam. First, memorise the pairing, not the symbols: small distance goes with the large probability. Second, note what the definition says about the annulus $r < \|x-y\| < cr$: nothing at all. Every LSH regime question turns on computing $cr$ and checking which of the three zones the distance lands in.

Q5 · MSQ · 3Laplacian
$G=(V,E,W)$ undirected and weighted with non-negative weights; $W$ is the weight matrix, $D$ diagonal with $D_{ii}=\sum_{j=1}^n W_{ij}$, and $L$ is the Laplacian. Which are true?
  • A$L = D-W$
  • B$L = W-D$
  • C$0$ is an eigenvalue of $L$
  • D$L$ is a positive definite matrix
Answer — A and C

A is the definition. C follows because every row of $L$ sums to zero, so $L\mathbf1 = 0$ — the all-ones vector is an eigenvector with eigenvalue $0$.

D is the mark-loser: $L$ is positive semi-definite, never positive definite. The two facts are directly linked — a zero eigenvalue means $L$ is singular, so it cannot be PD. C and D are logically incompatible, and spotting that is faster than recalling either fact separately.

B fails the row-sum test instantly (its diagonal would be $-D_{ii}$ and its off-diagonals $+w_{ij}$, giving $L=-L_{\text{true}}$, which has non-positive eigenvalues). And note the practical consequence of C: the sparsification formula needs the pseudo-inverse $L^\dagger$, because $L^{-1}$ does not exist.

Q6 · NAT · 2SVD
$A$ has non-zero singular values $1000, 100, 10, 1$ and $0.1$. If $B$ is the best rank-3 approximation of $A$, compute $\|A-B\|_2$.
Answer — 1

Eckart–Young: $\|A-A_k\|_2 = \sigma_{k+1}$. With $k=3$, that is $\sigma_4 = \mathbf 1$.

The off-by-one is the entire question. $\sigma_{k+1}$ is the first singular value you discard, not the last you keep. Sorted descending: $\sigma_1=1000$, $\sigma_2=100$, $\sigma_3=10$ (kept), $\sigma_4=1$, $\sigma_5=0.1$ (discarded).

Traps: $10$ is $\sigma_3$, the last kept. $0.1$ is $\sigma_5$, the smallest. $\sqrt{1^2+0.1^2}\approx1.005$ is the Frobenius error, and the question says $\|\cdot\|_2$ — spectral norm, which is a single singular value. The values are spaced by factors of ten precisely so that every wrong answer is unmistakably distinguishable.

Q7 · NAT · 2Labelings
Binary classification with a single feature in $\mathbb{R}$. Given $5$ distinct points in $\mathbb{R}$, what is the maximum number of labelings possible using classifiers from $H_{\mathrm{int}}$?
Answer — 16

An interval labels a contiguous run of the sorted points as $1$. Count the achievable runs:

$$\underbrace{\binom52}_{\text{runs of length}\ \ge2} + \underbrace{5}_{\text{singletons}} + \underbrace{1}_{\text{empty}} = 10+5+1 = \mathbf{16}$$

equivalently $\frac{n(n+1)}{2}+1$ at $n=5$.

Traps. $32=2^5$ is the count for all classifiers, and is what you get if you forget the class is restricted. $15$ drops the all-zeros labeling — easy to miss, since it comes from intervals that avoid every point. And $21 = 6+5+4+3+2+1$ is the professor's board count $(n+1)+n+\cdots+1$, which is a legitimate $O(n^2)$ upper bound for the uniform-convergence argument but over-counts here, because it recounts the all-zeros labeling once per left-endpoint position. When a question asks for the maximum number of labelings, it wants the exact figure.

Cross-check against $\mathrm{VCdim}(H_{\mathrm{int}})=2$: at $n=2$ the formula gives $3+1=4=2^2$ (shattered ✓); at $n=3$, $6+1=7<8$ (not shattered ✓).

Q8 · NAT · 3VC dimension
$H$ is the set of all axis-parallel cuboids in $\mathbb{R}^3$, a generalisation of axis-parallel rectangles in $\mathbb{R}^2$ to three dimensions. Find $\mathrm{VCdim}(H)$.
Answer — 6

A cuboid is $[a_1,b_1]\times[a_2,b_2]\times[a_3,b_3]$: one interval per axis, $2\times3 = \mathbf 6$ free parameters.

$\ge6$: place the points at the six face centres $\pm e_1,\pm e_2,\pm e_3$. Each of the six faces of the box can be slid independently, so each point can be included or excluded on its own — all $2^6$ labelings. ✓

$<7$: for any $7$ points, select the six that achieve the extreme coordinate in each of the six directions (one point may hold two extremes; that only makes it easier). Label those six $1$ and any remaining point $0$. The smallest cuboid containing all six extremes contains everything, so the $0$ cannot be excluded. ✓

The hint is in the question: the professor derived $\mathrm{VCdim}(H_{\mathrm{apr}})=4$ in $\mathbb{R}^2$, and $4 = 2\times2$. The general rule is $2d$. Traps: $3$ (dimension of the space); $4$ (the $\mathbb{R}^2$ answer, not generalised); $8$ (vertices of a cube).

Q9 · NAT · 2ERM
Dataset $S$ with features in $\mathbb{R}^2$, labels in $\{0,1\}$, $|S|=4$: $(-1,1)\to1$; $(1,-1)\to1$; $(-1,-1)\to0$; $(1,1)\to0$. $H_{\mathrm{lin}}$ is the set of all linear classifiers through the origin. Find $\mathrm{er}_S(h_S^{\mathrm{ERM}})$, to two decimals.
Answer — 0.25

Turn each labelled point into a constraint on $w=(w_1,w_2)$, using $h_w(x)=1$ iff $w^\top x\ge0$:

Point$y$$w^\top x$Requirement
$(-1,1)$$1$$-w_1+w_2$$w_2 \ge w_1$
$(1,-1)$$1$$w_1-w_2$$w_1 \ge w_2$
$(-1,-1)$$0$$-w_1-w_2$$w_1+w_2 > 0$
$(1,1)$$0$$w_1+w_2$$w_1+w_2 < 0$

Rows 3 and 4 demand $w_1+w_2$ be both positive and negative — at least one error is forced, so $\mathrm{er}_S \ge \tfrac14$. Rows 1 and 2 force $w_1=w_2=t$.

Take $t>0$, say $w=(1,1)$: the two positives give $w^\top x = 0 \ge 0$ ⇒ predict $1$ ✓✓; $(-1,-1)$ gives $-2<0$ ⇒ predict $0$ ✓; $(1,1)$ gives $2\ge0$ ⇒ predict $1$ ✗. Exactly one error:

$$\mathrm{er}_S\big(h_S^{\mathrm{ERM}}\big) = \tfrac14 = \mathbf{0.25}$$

Traps. $0$ assumes a homogeneous linear classifier can always fit four points — the labels here are XOR-shaped and it cannot. $0.5$ is what you get by giving up after seeing rows 3 and 4 conflict, without checking that $w=(1,1)$ rescues the other three. And the tie-break convention matters: the two positive points sit exactly on the boundary $w^\top x = 0$, and the rule $\ge 0 \Rightarrow 1$ is what makes them correct. Flip that convention and the answer becomes $0.75$.

Q10 · NAT · 1Compression
The hypothesis class of axis-parallel rectangles has a sample compression scheme of size $k$. What is $k$?
Answer — 4

Keep four positive points: leftmost, rightmost, lowest, highest. Decompression rebuilds the bounding rectangle from their coordinates; because the labels came from some rectangle, that box contains every positive and excludes every negative.

Equals $\mathrm{VCdim}(H_{\mathrm{apr}}) = 4$ — as does the intervals pair ($2$ and $2$). Whether that coincidence is a theorem is the open sample compression conjecture: compression size $k$ implies VC dimension $O(k)$, but the converse has been unresolved for over thirty years. A one-mark question if you know the number, and unanswerable if you do not.

Q11 · NAT · 3Privacy
Randomized response applied to true data $X=(1,1,0,1)$ with $\epsilon=0.1$. $Y$ is the intermediate random vector. Compute $P\big(Y=(1,1,1,0)\big)$ to three decimal places.
Answer — 0.062

$p = \frac{e^{0.1}}{1+e^{0.1}} = \frac{1.10517}{2.10517} = 0.52498$ (report truth); $q = \frac{1}{1+e^{0.1}} = 0.47502$ (flip). Compare coordinatewise:

$$X = (1,1,0,1),\quad Y = (1,1,1,0) \;\Longrightarrow\; \text{agree at } 1,2;\ \text{flip at } 3,4$$ $$P = p^2q^2 = 0.275604\times0.225644 = \mathbf{0.062}$$

Accepted range: $0.03$–$0.09$ — generous, because the graders expected sign confusion between $p$ and $q$. (Note $q^2p^2$ is the same number here, so the two-and-two split is self-correcting; a three-and-one split would not be.)

Traps: using $e^\epsilon = e^{0.1}$ as a probability rather than forming the ratio; and treating $Y$ as the debiased $Z$. Sanity check: with $\epsilon$ this small the mechanism is nearly a fair coin, so any four-bit pattern must have probability near $2^{-4}=0.0625$. ✓

Q12 · NAT · 3VC dimension
$\mathcal P_4$ is the set of all polynomials of degree at most $4$. For binary classification with a single feature in $\mathbb{R}$ and labels in $\{1,-1\}$, let $H=\{\mathrm{sign}(p(x)) : p\in\mathcal P_4\}$, with $\mathrm{sign}(0)=1$. An example: $\mathrm{sign}(3x^4+x^2-1)\in H$. Find $\mathrm{VCdim}(H)$.
Answer — 5

The quantity to count is sign changes. A non-zero polynomial of degree $\le4$ has at most $4$ real roots, and its sign can only flip at a root — so along the real line it has at most $4$ flips, i.e. at most $5$ constant-sign blocks.

$\ge5$: take any $5$ points $x_1<\cdots<x_5$ and any labeling. Reading left to right, the label changes at most $4$ times. Put a simple root in each gap where it changes, take $p(x)=\pm\prod_j(x-r_j)$, and pad with extra roots outside the data range (or an overall sign) to fix the leftmost sign. Degree stays $\le4$. ✓

$<6$: for any $6$ points ask for the fully alternating labeling $+,-,+,-,+,-$. That is $5$ sign changes, requiring $5$ roots — impossible at degree $4$. ✓

So $\mathrm{VCdim} = 4+1 = \mathbf 5$, and the general rule is $\deg\le m \Rightarrow \mathrm{VCdim} = m+1$. Check the base case: $\mathrm{sign}(ax+b)$ is a one-dimensional threshold rule with VC dimension $2$, matching linear-with-bias in $\mathbb{R}^1$. ✓

Traps. $4$ is the degree, and it is the answer to a subtly different question. $9$ counts the dimension of a degree-$4$ feature map in two variables. The $5$-coefficient parameter count happens to agree here, which makes it a dangerous crutch — the argument to write down is the root count, because that is what generalises.

Q13 · NAT · 0 · BONUSVC dimension
Find the VC dimension of the set of all triangle classifiers in $\mathbb{R}^2$, where a triangle classifier predicts $1$ for all points inside the triangle and $0$ for points outside it.
Answer — 7

$\ge7$: place $7$ points on a circle. For any labeling, the positives form at most $3$ contiguous arcs (with $7$ points you cannot get $4$ separated arcs), and a triangle can be chosen so that each of its three sides cuts off one negative arc, keeping all positive arcs inside. ✓

$<8$: with $8$ points on a circle, label them alternately $+,-,+,-,+,-,+,-$. That is $4$ separated positive arcs, and a triangle's boundary is only $3$ lines — each line can exclude at most one arc of negatives, so $4$ separated positive groups cannot all be captured. ✓

Why this is a good zero-mark question. A triangle has $6$ parameters (three vertices in $\mathbb{R}^2$), so the parameter-count heuristic predicts $6$ — and it is wrong. The extra unit comes from the fact that a triangle's three lines can be positioned more cleverly than three independent points suggest. Take it as the reminder that the heuristic generates a guess, and the two-player game generates the answer. Every other VC question on these papers is a class where the count does happen to work.

Q14–16 · MCQ+MCQ+MSQ · 2+2+2Uniform convergence · comprehension
$D$ is the joint distribution, $H$ a finite hypothesis class, $S\sim D^n$, $h_S\in H$ output by an algorithm, $\epsilon>0$ small. Events: $A = \big\{|\mathrm{er}_S(h_S)-\mathrm{er}_D(h_S)| \ge \epsilon\big\}$ and $B = \big\{\big(\max_{h\in H}|\mathrm{er}_S(h)-\mathrm{er}_D(h)|\big) \ge \epsilon\big\}$.
(14) What is $|\mathrm{er}_S(h_S)-\mathrm{er}_D(h_S)|$? (15) Which is true: $P(A)\le P(B)$, $\ge$, or $=$? (16) Uniform convergence gives $P(A)\le\delta$ whenever $n\ge n_0$. Which are true?
Answers — Generalisation error; $P(A)\le P(B)$; then "$\epsilon$ decreases ⇒ $n_0$ increases" and "$|H|$ increases ⇒ $n_0$ increases"

(14) Generalisation error. Train minus test for the same classifier. The tell is that it is the only one of the three gaps containing $\mathrm{er}_S$. Estimation and approximation both compare two $\mathrm{er}_D$ quantities; Bayes error is a single number, not a gap.

(15) $P(A)\le P(B)$. Since $h_S\in H$, if $A$ occurs then the maximum over $H$ is at least $\epsilon$ too, so $A\subseteq B$. This is the subset bound from Week 1, and it is the pivot of the entire uniform-convergence proof: $A$ mentions a data-dependent classifier and Hoeffding cannot touch it, while $B$ ranges only over classifiers fixed in advance. Equality fails because $B$ can be triggered by some other $h$ while $h_S$ itself is fine.

(16) From $n_0 = \frac{1}{2\epsilon^2}\log\frac{2|H|}{\delta}$:

  • $\epsilon\downarrow \Rightarrow n_0\uparrow$ — true, and quadratically so.
  • $|H|\uparrow \Rightarrow n_0\uparrow$ — true, logarithmically.
  • $\delta\uparrow \Rightarrow n_0\uparrow$ — false. $\delta$ is the allowed failure probability; tolerating more failure needs less data. $n_0$ carries $\log(1/\delta)$, which decreases as $\delta$ grows.
  • $n_0$ independent of $|H|$ — false. It is in there; a logarithm is not an absence.

The $\delta$ option is the mark-loser on this whole paper. Read $\delta$ as "probability of the bad event", never as "confidence" — confidence is $1-\delta$, and conflating the two flips the direction of the answer.

Q17–18 · NAT · 2+2Estimation & approximation · comprehension
Two concentric circles of radii $1$ and $2$. Green region: $\|x\|\le1$, label $1$. Red region: $1<\|x\|\le2$, label $0$. To sample from $D$: toss a fair coin for $y$; if $y=1$ pick $x$ uniformly from green, if $y=0$ pick $x$ uniformly from red. $H=\{h_r : r\ge0\}$ with $h_r(x)=1$ iff $\|x\|\le r$.
(17) $|$estimation error$|$ for $h_{0.5}$, to three decimals. (18) $|$approximation error$|$.
Answers — 0.375, then 0

The test error of a general $h_r$. Uniform on a disc means $P(\|x\|\le t) = t^2$ for $t\le1$; uniform on the annulus (area $4\pi-\pi = 3\pi$) means $P(\|x\|\le t\mid y=0) = \frac{t^2-1}{3}$ for $1<t\le2$.

$$\mathrm{er}_D[h_r] = \begin{cases} 0.5\,(1-r^2), & r\le1 \quad\text{(misses green points beyond } r)\\[4pt] 0.5\,\dfrac{r^2-1}{3}, & 1<r\le2 \quad\text{(swallows red points inside } r) \end{cases}$$

(17) At $r = 0.5$: $\;\mathrm{er}_D[h_{0.5}] = 0.5(1-0.25) = 0.375$. The class minimum: the first branch decreases to $0$ at $r=1$ and the second increases from $0$, so $\mathrm{er}_D[H] = 0$, attained at $r=1$. Hence

$$|\text{estimation error}| = |0.375 - 0| = \mathbf{0.375}$$

(18) $h_1$ is a perfect classifier — it labels exactly the green disc $1$ — so $\mathrm{er}_D[H] = 0$. The regions are disjoint, so the Bayes classifier is also perfect and $\mathrm{er}_D^* = 0$. Therefore

$$|\text{approximation error}| = |0 - 0| = \mathbf 0$$

The two-mark shortcut. Before integrating anything, ask: does $H$ contain a zero-error classifier? Here it obviously does — the true decision boundary is a circle of radius $1$ centred at the origin, and $h_1\in H$. That single observation answers Q18 in one line and hands you $\mathrm{er}_D[H]=0$ for Q17.

Traps: forgetting that "uniform on a disc" makes probability scale with $r^2$, not $r$ (a linear reading gives $0.5(1-0.5) = 0.25$); using $4\pi$ instead of $3\pi$ for the annulus area; and multiplying by the wrong prior — both are $0.5$ here, which is a mercy.

Q19–20 · NAT · 2+2Bayes · comprehension
Labels $\{0,1\}$, one feature in $\mathbb{R}$. $P(y=0)=P(y=1)=0.5$; $x\mid y=0\sim\mathrm{Exp}(1)$; $x\mid y=1\sim\mathrm{Exp}(2)$, where $f_X(x)=\lambda e^{-\lambda x}$ and $F_X(x)=1-e^{-\lambda x}$ for $x\ge0$.
(19) The Bayes classifier is $h^*(x)=1$ for $0\le x\le\theta$ and $0$ otherwise. Find $\theta$, to two decimals. (20) Find the Bayes error $\mathrm{er}_D^*$, to three decimals.
Answers — 0.69, then 0.375

(19) Equal priors, so cross the densities. $f_1(x) = 2e^{-2x}$, $f_0(x) = e^{-x}$:

$$2e^{-2x} \ge e^{-x} \iff 2 \ge \frac{e^{-x}}{e^{-2x}} = e^{x} \iff x \le \ln 2$$ $$\theta = \ln 2 = \mathbf{0.69}$$

The shape is worth a ten-second sketch: $\mathrm{Exp}(2)$ starts higher ($f_1(0)=2$ against $f_0(0)=1$) but decays faster, so class $1$ owns the region near zero and class $0$ owns the tail. The question's stated form of $h^*$ confirms it.

(20) $h^*$ says $1$ on $[0,\ln2]$ and $0$ beyond, so it errs on class-$1$ points in the upper tail and class-$0$ points in the lower:

$$\mathrm{er}_D^* = 0.5\,P\big(x>\ln2 \mid y{=}1\big) + 0.5\,P\big(x\le\ln2 \mid y{=}0\big) = 0.5\,e^{-2\ln2} + 0.5\big(1-e^{-\ln2}\big)$$

Now $e^{-2\ln2} = 2^{-2} = \tfrac14$ and $e^{-\ln2} = \tfrac12$:

$$= 0.5\times\tfrac14 + 0.5\times\tfrac12 = 0.125 + 0.25 = \mathbf{0.375}$$

Traps. Charging the wrong tail to the wrong class — class $1$ errs above $\theta$, class $0$ below, and the two contributions ($0.125$ and $0.25$) are unequal, so swapping them changes nothing about the total here but would in any asymmetric variant. Also: use the given CDF rather than integrating, and exploit $e^{-\lambda\ln2} = 2^{-\lambda}$ to keep the arithmetic exact. The accepted range was a wide $0.32$–$0.45$.


Past papers · Quiz 2

Quiz-2 papers, solved

The two quiz-2 papers, fully solved. They are not end-term papers — but they are the only worked drill available for the Weeks 1–6 quarter of the syllabus, so treat them as a topic bank rather than a mock.

How much of this still matters

On the end term, Weeks 1–6 are examined as statements, not derivations. So mine these papers for the facts — $k$ independent of $d$, Eckart–Young's off-by-one, the LSH knobs, the Laplacian row-sum test — and do not spend end-term revision time re-deriving JL or tracing randomized SVD. The end-term papers are the ones to time yourself against.

What the papers look like

T2: 11 questions, 50 marks — 6 MCQ, 2 MSQ, 4 numeric.  T3: 9 questions, 50 marks — 2 MCQ, 4 MSQ, 10 numeric (T3 leans much harder on comprehension blocks and numeric answers). Neither paper has negative marking.

Both source PDFs are truncated at 9 pages — T2 Q13 and T3 Q95 are absent from the files, and T2 Q12's last two options are cut off. Everything else is complete.

Where the marks actually are

TopicQuestionsMarks (T2+T3)What gets asked
JL / random projections521$k$ independent of $d$; $AA^\top$ covariance; $\mathbb{E}\|Mu\|^2 = \|u\|^2$; rotation invariance
Spectral clustering520Build $L = D-W$ for a small graph; compute cuts; find the mincut
SVD / randomized SVD718Eckart–Young; singular vs eigen values; sketch coverage; oversampling
LSH517Read the partition off a picture; effect of $L$; bucket convexity
Concentration inequalities28Always Markov, always with a complement step
Probability foundations14Venn diagram for $X \Rightarrow Y$
Spectral sparsification13Only unbiasedness, $\mathbb{E}[L_H] = L_G$

The big four carry roughly 90% of both papers. Note what never appears despite being in the syllabus: Chebyshev and Hoeffding numerics, the Chernoff derivation, effective-resistance machinery. That is a reason to be efficient in revision — not a reason to skip them, since two papers is a small sample and the syllabus is the syllabus.

2025 T2

Q2 · MCQ · 4Markov
$X$ is a random vector in $\mathbb{R}^d$ whose mean distance from the origin is $10$. Let $p$ be the probability that the distance of $X$ from the origin is at most $50$. Enter the tightest bound.
  • A$p \ge 0.8$
  • B$p \le 0.8$
  • C$p \ge 0.2$
  • D$p \le 0.2$
Answer — A

Let $Z = \|X\| \ge 0$ with $\mathbb{E}[Z] = 10$. Markov: $P(Z \ge 50) \le 10/50 = 0.2$. Complement: $p = P(Z \le 50) \ge 1 - 0.2 = \mathbf{0.8}$.

Traps: D is the raw Markov number without the complement. B has the complement but keeps the inequality direction — an upper bound on the tail is a lower bound on $p$. C is true but weaker, and the question says "tightest".

Q3 · MCQ · 4JL
Two datasets $D_1, D_2$ with the same number of points and $\epsilon = 0.01$, living in $\mathbb{R}^{d_1}$ and $\mathbb{R}^{d_2}$ with $d_1/d_2 = 1000$. Relation between $k_1$ and $k_2$?
  • A$k_1 \ge 1000\,k_2$
  • B$k_2 \ge 1000\,k_1$
  • C$k_1$ can never equal $k_2$
  • D$k_1$ and $k_2$ can be chosen equal
Answer — D

$k \in O(\log n/\epsilon^2)$ — no $d$. Same $n$, same $\epsilon$ ⟹ the same $k$ works for both.

Traps: A and B encode "a 1000× bigger space needs a 1000× bigger embedding" — exactly the intuition JL demolishes. The load-bearing phrase is "same number of data-points": that is the only quantity that matters.

Q4 · MCQ · 4Probability
Which Venn diagram represents $X \Rightarrow Y$?
  • ATwo disjoint circles
  • B$Y$ nested inside $X$
  • C$X$ nested inside $Y$
  • DTwo overlapping circles
Answer — C

"Whenever $X$ occurs, $Y$ occurs" is set containment $X \subseteq Y$: the smaller event sits inside. Hence $P(X) \le P(Y)$ — the subset inequality used throughout the JL proof.

Trap: B is the reversed containment and is the most common error — the arrow in "$X \to Y$" makes it feel like $X$ should be the bigger, outer set. Implication shrinks the event.

Q5 · MCQ · 4Random matrices
$A$ is a $10^4 \times 10^5$ matrix with i.i.d. standard normal entries. What does the histogram of its non-zero singular values look like?
  • ASymmetric bell curve
  • BFlat / uniform
  • CU-shaped "bathtub"
  • DA single narrow spike
Answer — D

The singular values of a Gaussian matrix concentrate in a narrow band — for aspect ratio $\beta = 10^4/10^5 = 0.1$ they lie roughly in $\sqrt N(1\pm\sqrt\beta) \approx [0.68, 1.32]\sqrt N$. Plotted from zero, that band is a spike.

This is the matrix-level restatement of JL: $\sigma_{\min} \approx \sigma_{\max}$ means the map is nearly a scaled isometry — the sphere goes to a nearly spherical ellipsoid. Same fact as the "$\sigma_i \approx \sqrt{d/k}$" line in the Week 2 linear-algebra lecture.

Trap: A is the reflex — "Gaussian entries, so Gaussian singular values". Singular values are a highly non-linear function of the entries.

Q6 · MCQ · 4Random projections
$A = \begin{bmatrix}1&4\\3&1\end{bmatrix}$ and $\omega \sim \mathcal N(0, I_2)$. Find $\operatorname{Cov}(A\omega)$.
  • A$\begin{bmatrix}17&7\\7&10\end{bmatrix}$
  • B$\begin{bmatrix}10&7\\7&17\end{bmatrix}$
  • C$\begin{bmatrix}1&16\\9&1\end{bmatrix}$
  • D$I_2$
Answer — A

$\operatorname{Cov}(A\omega) = A\operatorname{Cov}(\omega)A^\top = AA^\top$. Row 1 of $A$ is $(1,4)$: $1+16 = 17$. Row 2 is $(3,1)$: $9+1 = 10$. Cross: $3+4 = 7$.

Trap: B is $A^\top A$ — same trace, same off-diagonal, only the diagonal order differs, so it survives a glance. This is the identity behind randomized SVD ($\operatorname{Cov}(A\omega) = AA^\top$, whose eigenvectors are the left singular vectors); getting it backwards breaks that whole story. C squares each entry.

Q7 · MSQ · 4LSH
$h \sim \mathcal H_{w=2}$, a Datar family on $\mathbb{R}^2$. Which partitionings of $\mathbb{R}^2$ are possible?
  • AEvenly spaced parallel diagonal lines
  • BConcentric circles about the origin
  • CDiagonal lines that bend around a closed ellipse
  • DParallel diagonal lines, finer spacing
Answer — A and D

Level sets of $\lfloor(a^\top x + b)/w\rfloor$ are parallel slabs perpendicular to $a$, of equal width $w$. The direction of $a$ is random (any slope allowed) and $b$ shifts them, so both stripe pictures are realisable.

Traps: B is seductive — "Euclidean LSH, so round buckets" — but rings hash by norm: two antipodal points on the same ring collide despite being maximally far apart. C is half-right: a single linear projection can never carve out a bounded closed region. And since this is an MSQ, ticking only A scores zero.

Q8 · MSQ · 4LSH
An LSH uses $L$ tables of $k$ hashes each; collision if any table matches. Increasing $L$ with everything else fixed:
  • ATPR increases
  • BFPR increases
  • CTPR decreases
  • DFPR decreases
Answer — A and B

$P(p) = 1-(1-p^k)^L$ is strictly increasing in $L$ for every $p \in (0,1)$. So it lifts the rate for near pairs ($p \ge p_1$) and for far pairs ($p \le p_2$) at the same time. More tables buy recall and pay in precision, memory, and candidate-filtering time.

Trap: D comes from conflating $L$ with $k$. It is $k$ (the AND) that drives both rates down. Ticking only A also loses the marks — the point of the question is that both move the same way.

Q9 · NAT · 5JL
$n$ points in $\mathbb{R}^d$, all on the unit hypersphere. With $\epsilon = 0.0201$ and a suitable $k$, find an upper bound for the distance between any two points in $\mathbb{R}^k$. Two decimal places.
Answer — 2.02

Step 1 — diameter upstairs. For $x,y$ on the unit sphere, the triangle inequality through the origin gives $\|x-y\| \le \|x\| + \|y\| = 2$.

Step 2 — apply JL, then square-root. $\|f(x)-f(y)\|^2 \le (1+\epsilon)\|x-y\|^2$, so

$$\|f(x)-f(y)\| \le \sqrt{1.0201}\times 2 = 1.01 \times 2 = \mathbf{2.02}$$

Traps: (i) Using diameter $1$ instead of $2$ — the points lie on the unit sphere, so the farthest pair is antipodal. (ii) Multiplying the distance by $(1+\epsilon)$ instead of $\sqrt{1+\epsilon}$, giving $2.0402$. The value $\epsilon = 0.0201$ is engineered so $\sqrt{1+\epsilon} = 1.01$ exactly — that is the examiner telling you to take a square root.

Q10 · NAT · 4SVD
$A$ has non-zero singular values $50, 20, 10, 1, 0.01, 0.001$. If $B$ is the best rank-4 approximation, compute $\|A-B\|_2$.
Answer — 0.01

Eckart–Young: $\|A - A_k\|_2 = \sigma_{k+1}$. With $k=4$, that is $\sigma_5 = \mathbf{0.01}$.

Traps: $\sigma_4 = 1$ (off-by-one — the error is the first value discarded). Or the Frobenius answer $\sqrt{0.01^2 + 0.001^2} \approx 0.01005$ — the subscript $2$ means spectral norm, so only the largest discarded value counts. The tiny $\sigma_6 = 0.001$ exists purely to make that mistake feel reasonable.

Q11 · NAT · 4Cuts
Comprehension: two disjoint triangles $\{1,2,3\}$ and $\{4,5,6\}$, each with edge weights $1$ (top), $2$ (left), $3$ (right); no edges between them. Among all cuts with $|A| = 1$, find the smallest cut weight.
Answer — 3

For a singleton, the cut equals the weighted degree. Degrees: $d_1 = 1+2 = 3$, $d_2 = 1+3 = 4$, $d_3 = 2+3 = 5$, and identically $3, 4, 5$ for vertices $4,5,6$. Minimum is $\mathbf{3}$ at $A = \{1\}$ or $\{4\}$.

Trap: The graph is deliberately disconnected, so the global mincut really is $0$ (take $A = \{1,2,3\}$). The constraint $|A| = 1$ forbids that. Reading past the cardinality constraint is the entire trap. Secondary slip: answering $1$, the smallest single edge weight, instead of summing all edges at the vertex.

Q12 · MCQ · 4Laplacian
Find the Laplacian $L$ of the same two-triangle graph.
Answer — the block-diagonal $D - W$ $$L = \begin{bmatrix} 3&-1&-2&&&\\ -1&4&-3&&\huge0&\\ -2&-3&5&&&\\ &&&3&-1&-2\\ &\huge0&&-1&4&-3\\ &&&-2&-3&5 \end{bmatrix}$$

Diagonal = weighted degrees $(3,4,5,3,4,5)$; off-diagonal $= -w_{ij}$; zeros across the blocks because the components are disconnected. Since there are two components, $\lambda = 0$ has multiplicity $2$.

Trap: The distractor is $-W$ — right off-diagonals, right sparsity, but a zero diagonal. Kill it with the row-sum test: every row of a Laplacian sums to $0$; in $-W$ every row sums to a negative number. (The source PDF is truncated here, so options C and D are not recoverable.)

2025 T3

Q80 · MSQ · 4JL
$M \in \mathbb{R}^{k\times d}$ is an approximate isometry per JL, and $Q$ is a $k\times k$ orthogonal matrix. Which are true?
  • A$QM$ is an approximate isometry
  • B$Q^\top M$ is an approximate isometry
  • CExactly one of them is
  • DNeither is
Answer — A and B

For square orthogonal $Q$, $\|Qv\|^2 = v^\top Q^\top Q v = \|v\|^2$ — an exact isometry on $\mathbb{R}^k$. So $\|QMx\| = \|Mx\|$ and $QM$ inherits the identical $\epsilon$. And $Q$ orthogonal ⟹ $Q^\top = Q^{-1}$ is orthogonal too, so the same argument gives B.

Trap: C targets students half-remembering "$Q^\top Q = I$ but $QQ^\top \ne I$". That caveat is for rectangular matrices with orthonormal columns. Here $Q$ is explicitly square, so both products are $I$ and A and B stand or fall together — which makes C self-defeating.

Q81 · MSQ · 3LSH
$x_1, x_2$ collide under $g$ (a $k$-fold AND of Datar hashes) and $x_3 = \lambda x_1 + (1-\lambda)x_2$ for some $\lambda \in (0,1)$. Select all that apply.
  • A$x_3$ collides with $x_1$
  • B$x_3$ collides with $\beta x_1 + (1-\beta)x_2$ for all $\beta \in \mathbb{R}$
  • C$x_3 + (1-\lambda)x_1 + \lambda x_2$ collides with $x_1 + x_2$
  • D$x_3 - \tfrac\lambda2 x_1 + \tfrac\lambda2 x_2$ collides with both $x_1$ and $x_2$
Answer — A, C and D

The structural fact: each hash's level set is a slab (convex), so a bucket of $g$ is an intersection of $k$ slabs — also convex. If $x_1, x_2$ share a bucket, the whole segment between them does.

A: $x_3$ is a convex combination, so it's on the segment. ✓

C: pure algebra — $x_3 + (1-\lambda)x_1 + \lambda x_2 = \lambda x_1 + (1-\lambda)x_2 + (1-\lambda)x_1 + \lambda x_2 = x_1 + x_2$. It is literally the same point, so it trivially collides with itself. Expand before you think geometrically.

D: $= \tfrac\lambda2 x_1 + (1-\tfrac\lambda2)x_2$, a convex combination with $\mu = \lambda/2 \in (0,\tfrac12)$. ✓

Trap — B, and it is one word: $\forall \beta \in \mathbb{R}$. Convexity protects $\beta \in [0,1]$ only. Outside that you are on the line's extension, which walks out of the slab. Convex hull, not affine hull.

Q82 · NAT · 4Markov
$X, Y \ge 0$ with $\mathbb{E}[X] = 10$, $\mathbb{E}[Y] = 20$. If $Z = X+Y$ and $P(Z \ge 60) \le b$, find the tightest $b$ with the available information. One decimal place.
Answer — 0.5

$Z \ge 0$, and by linearity of expectation (which needs no independence) $\mathbb{E}[Z] = 30$. Markov: $P(Z \ge 60) \le 30/60 = \mathbf{0.5}$.

Trap: "with the available information" is load-bearing. No variance, no independence ⟹ Chebyshev and Hoeffding are unavailable and $0.5$ genuinely is the tightest derivable bound. Splitting into $P(X\ge20) + P(Y\ge40) \le 1$ via the union bound is legal but strictly weaker.

Q83 · NAT · 4JL
$R$ is $25 \times 10000$ with standard normal entries, $u \in \mathbb{R}^{10000}$ with $\|u\| = 10$, and $A = R/5$. Find $\mathbb{E}\big[\|Au\|^2\big]$.
Answer — 100

Each row satisfies $r_i^\top u \sim \mathcal N(0, \|u\|^2)$, so $\mathbb{E}[(r_i^\top u)^2] = \|u\|^2 = 100$. Over $k = 25$ rows: $\mathbb{E}\|Ru\|^2 = 25 \times 100 = 2500$. Then $A = R/5$ scales the squared norm by $1/25$:

$$\mathbb{E}\big[\|Au\|^2\big] = \frac{2500}{25} = \mathbf{100} = \|u\|^2$$

Note $5 = \sqrt{25} = \sqrt k$ — this is $M = R/\sqrt k$, and the answer coming out as exactly $\|u\|^2$ is the unbiasedness result, not a coincidence.

Traps: forgetting the scaling ($2500$); dividing by $5$ once instead of $25$ ($500$) — the scalar squares inside $\|\cdot\|^2$. The ambient $10000$ is a pure red herring, which is itself the JL punchline.

Q84 · NAT · 3Sparsification
$H$ sparsifies $G$: edge $(u,v)$ retained with probability $p_{uv}$ and reweighted $W'[uv] = W[uv]/p_{uv}$. Find $\mathbb{E}\big[f^\top(L_H - L_G)f\big]$.
Answer — 0

With $X_{uv} \sim \mathrm{Bernoulli}(p_{uv})$ indicating retention,

$$\mathbb{E}\big[f^\top L_Hf\big] = \sum_{(u,v)\in E} p_{uv}\cdot\frac{w_{uv}}{p_{uv}}(f_u-f_v)^2 = f^\top L_Gf$$

so the difference has expectation $\mathbf{0}$, for every fixed $f$.

Trap: grinding out algebra expecting an $f$-dependent mess — the whole design of the $1/p$ reweighting is to make this identically zero. Deeper trap: unbiasedness holds for any $p_{uv} > 0$. Effective resistance buys concentration, not correctness-on-average. Zero expected error is not zero error.

Q85–86 · MCQ · 3+3LSH
Four partitions of $\mathbb{R}^2$: (A) concentric tilted ellipses, (B) ~8 lines through the origin making wedges, (C) evenly spaced parallel diagonal strips, (D) concentric axis-aligned squares. Q85: which one means "same bucket ⟹ close in Euclidean distance"? Q86: which one means "same bucket ⟹ high cosine similarity"?
Answer — Q85: C  ·  Q86: B

Q85 → C. Euclidean (Datar) LSH buckets are parallel slabs of width $w$ perpendicular to a random direction. Two points in the same slab differ by at most $w$ along that direction; ANDing $k$ of them bounds the separation in $k$ random directions, hence the Euclidean distance w.h.p.

Q86 → B. Cosine similarity depends only on the angle and is scale-invariant, so its buckets must be cones through the origin — exactly what lines through the origin produce (SimHash: $h_a(x) = \mathrm{sign}(a^\top x)$, collision probability $1-\theta/\pi$).

Traps: A and D bucket by norm — antipodal points on the same ring always collide, which is anti-locality-sensitive; and no single linear hash can produce a bounded region. The paired structure is deliberate: answering both with the same partition guarantees losing one. Discriminator: is the similarity scale-invariant? Cosine yes → wedges. Euclidean no → stripes.

Q87–91 · Comprehension · 3+3+3+1+0Randomized SVD
$\{v_1,\dots,v_5\}$ orthonormal in $\mathbb{R}^{10}$. Dataset $\mathcal D$ repeats $v_j$ exactly $i_j$ times with $(i_1,\dots,i_5) = (12,9,2,1,1)$; $D$ is the $n\times d$ data matrix. Q87 find $n$. Q88 which of $0, 1, 3, 12$ are singular values of $D$? Q89 $W$ is $n\times\ell$ with 0/1 entries, each column summing to 1; $Z_\ell = D^\top W$. For $k=1, p=0$, find $\Pr[\mathrm{span}(e_1) \subseteq \mathrm{span}(Z_\ell)]$. Q90 same with $p=3$. Q91 after one power step $Z^{(2)} = D^\top D Z^{(1)}$?
Answers — 25 · {0,1,3} · 0.48 · 0.93 · 0.93

Setup. Using the paper's hint $D^\top D = \sum_j i_j v_jv_j^\top$. Since the $v_j$ are orthonormal this is the spectral decomposition: eigenvalues $12, 9, 2, 1, 1$ plus $0$ with multiplicity $d - 5 = 5$.

Q87 → 25. $n = 12+9+2+1+1$. Note $n = 25$, $d = 10$, $\mathrm{rank} = 5$ are three different numbers, each used in a different sub-question.

Q88 → A, B, C ($0$, $1$, $3$). Singular values are square roots: $\sqrt{12}\approx3.46$, $\sqrt9 = 3$, $\sqrt2$, $1$, $1$, and $0$ (five times, since $d > \mathrm{rank}$). $12$ is an eigenvalue of $D^\top D$, not a singular value of $D$ — the multiplicities are handed to you looking like an answer list. Also easy to miss $0$.

Q89 → 0.48. Decode $W$ first: a 0/1 column summing to $1$ is a random standard basis vector, so $D^\top\varepsilon_t$ is the $t$-th row of $D$ — one uniformly sampled data point. This is a sampling sketch, not a Gaussian one. With $\ell=1$, $\mathrm{span}(Z_\ell)$ is a single line, and since the $v_j$ are orthonormal it contains $v_1$ iff the sampled point is $v_1$: $12/25 = \mathbf{0.48}$.

Q90 → 0.93. $\ell = k+p = 4$ draws; $v_1$ is captured iff at least one hits: $1 - 0.52^4 = \mathbf{0.9269}$. Three extra columns take failure from $52\%$ to $7\%$ — the whole argument for oversampling, in one number.

Q91 → 0.93, unchanged. $Z^{(2)} = (D^\top D)Z^{(1)}$ multiplies each sampled column $v_j$ by the positive scalar $i_j$, which does not change the span. Power iteration improves accuracy, never coverage — if no draw was $v_1$, nothing conjures it.

Traps: answering $1$ on Q89 by reading $W$ as Gaussian; answering $0.2$ by sampling uniformly over the 5 directions instead of the 25 points (the multiplicities are the sampling weights — this is why leverage-score sampling exists); $4 \times 0.48 = 1.92 > 1$ on Q90; and expecting Q91 to go up.

Q92–94 · Comprehension · 4+4+4Spectral clustering
Weighted graph on $V = \{1,2,3,4\}$: $w_{12}=3$, $w_{13}=2$, $w_{14}=10$, $w_{24}=2$, $w_{34}=1$, no edge $2$–$3$. Q92 $\mathrm{cut}(\{1,2,3\}, \{4\})$? Q93 which vertices are in $A^*$, the set with the smallest non-zero cut? Q94 $L_{11} - L_{42}$?
Answers — 13 · {1,2,4} · 17

Weighted degrees: $d_1 = 3+2+10 = 15$, $d_2 = 3+2 = 5$, $d_3 = 2+1 = 3$, $d_4 = 10+2+1 = 13$.

Q92 → 13. $V\setminus A = \{4\}$, so the cut is just $d_4 = 10+2+1 = \mathbf{13}$. Trap: summing the edges inside $A$ ($3+2+0 = 5$), or missing $w_{34}=1$ (drawn as a long curved arc along the bottom — that layout is deliberate).

Q93 → A, B, D, i.e. $A^* = \{1,2,4\}$. Enumerate: $\mathrm{cut}\{1\} = 15$, $\{2\} = 5$, $\{3\} = 3$, $\{4\} = 13$, $\{1,2\} = 14$, $\{1,3\} = 14$, $\{1,4\} = 8$. The smallest non-zero value is $\mathbf{3}$, achieved by the complementary pair $\{3\}$ and $\{1,2,4\}$; the key commits to the large side. Vertex 3 is the loosely-attached one, so peeling it off is cheapest — exactly what the Fiedler vector would find.

Careful: $\{3\}$ and $\{1,2,4\}$ have identical cut value, so this MSQ is genuinely ambiguous. Reasoning toward the singleton makes you tick only C and score zero. Heuristic: when three of four membership options are true, the large side is intended. Also note "non-zero" — without it, $A = \emptyset$ gives $0$ and the question is degenerate.

Q94 → 17. $L_{11} = d_1 = 15$ and $L_{42} = -w_{42} = -2$, so $15 - (-2) = \mathbf{17}$. The double negative is the whole point of asking for a difference. Secondary traps: using the unweighted degree $3$ for $L_{11}$; and indexing — the paper says "indices start from one" for a reason.


Practice

Mixed practice bank

Forty questions in random topic order, written in the style of the real papers — including the deliberately ambiguous phrasings and the plausible-looking wrong options. Do these cold, on paper, before checking. Part A covers Weeks 1–6, Part B Weeks 7–12.

Part A — Weeks 1–6

Suggested run

Give yourself 45 minutes for Part A. Anything you cannot start within 90 seconds, flag and move on — that flagged list is your revision plan.

01 · NAT
The waiting time $T$ at a service desk is non-negative with $\mathbb{E}[T] = 4$ minutes. What is the tightest lower bound you can state for $P(T < 25)$? Two decimals.
Answer — 0.84

Markov: $P(T \ge 25) \le 4/25 = 0.16$. Complement: $P(T < 25) \ge 1 - 0.16 = \mathbf{0.84}$.

The complement step is the recurring archetype — it appeared in both past papers.

02 · MSQ
A JL map takes $n$ points from $\mathbb{R}^d$ into $\mathbb{R}^k$. Which quantities does the required $k$ depend on?
  • A$n$, the number of points
  • B$d$, the ambient dimension
  • C$\epsilon$, the distortion
  • D$\delta$, the failure probability
Answer — A, C and D

The union-bound step is $P(E) \le n^2 e^{-c\,k\epsilon^2} \le \delta$, so $k$ is driven by $n$, $\epsilon$ and $\delta$ — never $d$. $\delta$ counts because it enters when you solve that inequality, though only inside a logarithm, so its influence is weak.

The headline $k \in O(\log n/\epsilon^2)$ suppresses $\delta$ by treating it as a fixed constant. That is fine for the big-oh statement, but the question asks what $k$ depends on — so D counts. If you ticked only A and C you would score zero on an MSQ.

03 · MCQ
An LSH family is $(1, 4, 0.9, 0.1)$-sensitive. Two points are $3.5$ apart. What is guaranteed?
  • ACollision probability $\ge 0.9$
  • BCollision probability $\le 0.1$
  • CNothing is guaranteed
  • DCollision probability is exactly $0.5$
Answer — C

$r = 1$, $cr = 4\times1 = 4$. Distance $3.5$ satisfies neither $\le 1$ nor $\ge 4$ — it lies in the annulus $(1,4)$, where the definition asserts nothing. Always compute $cr$; never compare against $c$ alone.

04 · NAT
$A$ is $6\times4$ with singular values $9, 4, 2, 0$. What is $\mathrm{rank}(A)$, and what is $\|A - A_2\|_2$? Give the product of the two answers.
Answer — 6

$\mathrm{rank}(A) = $ number of non-zero singular values $= 3$. And $\|A - A_2\|_2 = \sigma_3 = 2$. Product $= 3 \times 2 = \mathbf 6$.

Trap on the rank: it is not $\min(6,4) = 4$, because $\sigma_4 = 0$.

05 · NAT
A path graph on 4 vertices: edges $1$–$2$, $2$–$3$, $3$–$4$, all weight $1$. Compute $L_{22} + L_{13}$.
Answer — 2

$\deg(2) = 2$ so $L_{22} = 2$. Vertices $1$ and $3$ are not adjacent, so $w_{13} = 0$ and $L_{13} = -0 = \mathbf{0}$. Sum $= \mathbf{2}$.

For reference, $L = \begin{bmatrix}1&-1&0&0\\-1&2&-1&0\\0&-1&2&-1\\0&0&-1&1\end{bmatrix}$ — check each row sums to zero.

06 · MCQ
$X_1,\dots,X_n$ are i.i.d. with $X_i \in [2, 6]$. To bound $P(\bar X - \mathbb{E}\bar X \ge 0.5)$ by Hoeffding, what is the exponent?
  • A$-2n(0.5)^2/16$
  • B$-2n(0.5)^2/4$
  • C$-2n(0.5)^2/36$
  • D$-2n(0.5)^2$
Answer — A

$(b-a)^2 = (6-2)^2 = 16$. So the bound is $e^{-2n(0.25)/16} = e^{-n/32}$.

Traps: B uses $b-a = 2$ (the lower endpoint, not the range); C uses $b^2 = 36$; D silently assumes $[0,1]$. The range matters, not the endpoints individually — the bound is invariant to shifting the interval.

07 · MSQ
Randomized SVD is run on $A \in \mathbb{R}^{m\times n}$ with $\ell = k+p$. Which are correct?
  • A$Q$ has shape $m \times \ell$.
  • BThe exact SVD is computed on a matrix of shape $\ell \times n$.
  • C$\hat U = Q\tilde U_k$ has shape $m \times k$.
  • D$\Omega$ has shape $m \times \ell$.
Answer — A, B and C

D is false: $\Omega$ is $n \times \ell$, so that $Y = A\Omega$ works dimensionally ($m\times n$ times $n\times\ell$). Getting $\Omega$'s orientation wrong breaks the whole pipeline, and it is the easiest shape to invert mentally.

Shape chain to memorise: $\Omega_{n\times\ell} \to Y_{m\times\ell} \to Q_{m\times\ell} \to B_{\ell\times n} \to \hat U_{m\times k}$.

08 · NAT
An LSH scheme has $p_1 = 0.5$, $p_2 = 0.25$ and $n = 2^{20}$. Find the number of AND-ed hashes $k$ that makes the expected number of false-positive collisions equal to $1$.
Answer — 10

Solving $n\,p_2^k = 1$ gives $k = \dfrac{\log n}{\log(1/p_2)}$. Base-2 throughout: $\log_2 n = 20$, $\log_2(1/0.25) = \log_2 4 = 2$. So $k = 20/2 = \mathbf{10}$.

Check: $n p_2^k = 2^{20} \times 4^{-10} = 2^{20}/2^{20} = 1$. ✓  Bonus: $\rho = \log(1/0.5)/\log(1/0.25) = 1/2$, so $L = \theta n^{0.5} = \theta \cdot 1024$.

09 · MCQ
Which is the correct order of steps in spectral clustering?
  • Ak-means → build graph → eigenvectors → normalise
  • BBuild graph → $L = D-W$ → eigenvectors (drop $f_1$) → normalise rows → k-means
  • CBuild graph → $L = D-W$ → eigenvectors (keep $f_1$) → k-means → normalise
  • D$L = D-W$ → k-means → eigenvectors → build graph
Answer — B

Two details separate B from C: $f_1$ is discarded (it is the constant vector at $\lambda_1 = 0$ and carries no clustering information), and normalisation comes before k-means, not after — the point of projecting the embeddings onto the unit sphere is to make k-means' job easy.

10 · NAT
Sparsifying a graph, edge $e$ has weight $8$ and is retained with probability $0.25$. If retained, what is its new weight? And what is the expected contribution of $e$ to $f^\top L_Hf$ if $(f_u - f_v)^2 = 3$?
Answer — new weight 32, expected contribution 24

$w' = 8/0.25 = \mathbf{32}$. Expected contribution $= p \cdot w' \cdot (f_u-f_v)^2 = 0.25 \times 32 \times 3 = \mathbf{24}$, which equals $w \cdot (f_u-f_v)^2 = 8 \times 3 = 24$. ✓ Unbiased, as designed.

Note the variance is enormous here: the contribution is $96$ a quarter of the time and $0$ otherwise. That is exactly why the choice of $p$ matters — it controls variance, not the mean.

11 · MSQ
Which are valid reasons to prefer randomized SVD over exact SVD?
  • ACost drops from $O(mn^2)$ to $O(mn\ell)$.
  • BIt gives the exact top-$k$ singular vectors.
  • CIt works well when the spectrum decays quickly.
  • DOnly $\ell = k+p$ passes over the data are needed rather than a full factorisation.
Answer — A, C and D

B is false — the output is an approximation, guaranteed only to be within $(1+\epsilon)\sigma_{k+1}$ with probability $\ge 1-\delta$. Exactness is precisely what you trade away.

C is the real precondition: if the spectrum is flat, $\sigma_{k+1}/\sigma_k \approx 1$ and the subspace bound is vacuous — you then need power iteration.

12 · MCQ
Which is the tightest statement you can make about a random variable $X$ with $\mathbb{E}[X]=0$ and $\mathrm{Var}(X)=9$, regarding $P(X \ge 12)$?
  • A$\le 1/16$ by Chebyshev
  • B$\le 0$ by Markov
  • C$\le e^{-8}$ by Hoeffding
  • DCannot bound it at all
Answer — A

$\sigma = 3$, so $12 = 4\sigma$ and Chebyshev gives $P(|X| \ge 12) \le 1/16$, hence $P(X \ge 12) \le 1/16$ too.

B is wrong because Markov needs $X \ge 0$, and a mean-zero non-degenerate variable is not non-negative. C is wrong because Hoeffding needs many independent bounded variables — you have one variable of unknown range. This question is really asking: which hypotheses do you actually have?

13 · NAT
Triangle graph on $\{1,2,3\}$ with $w_{12} = 5$, $w_{13} = 1$, $w_{23} = 1$. Find the smallest non-zero cut value.
Answer — 2

Singleton cuts are the weighted degrees: $d_1 = 5+1 = 6$, $d_2 = 5+1 = 6$, $d_3 = 1+1 = \mathbf 2$. On three vertices every non-trivial cut is a singleton (or its complement), so the minimum is $\mathbf 2$, at $A = \{3\}$.

Note where the heavy edge ends up: the mincut keeps $1$ and $2$ together precisely because $w_{12} = 5$ is expensive to cross.

14 · MCQ
In the JL proof, the Chernoff step applies Markov's inequality to which quantity?
  • A$\|x\|^2$ directly
  • B$e^{\lambda\|x\|^2}$ for a free parameter $\lambda > 0$
  • C$\|x\|$
  • D$\log\|x\|^2$
Answer — B

Exponentiating first is what turns Markov's weak $1/a$ decay into exponential decay: the free $\lambda$ can then be optimised, which is what produces a bound of the form $e^{-c\,k\epsilon^2}$. Applying Markov to $\|x\|^2$ directly (A) gives only $1/(1+\epsilon)$ — useless.

The MGF of each $x_i^2 \sim \chi^2_1$ is $(1-2\lambda)^{-1/2}$, and independence lets you take the product over the $k$ coordinates.

15 · NAT
With $p_1 = 0.8$, $p_2 = 0.2$, $n = 10^6$ and $\theta = 3$: find $\rho$ to two decimals, then $L$ to the nearest integer.
Answer — ρ = 0.14, L ≈ 20

$\rho = \dfrac{\ln(1/0.8)}{\ln(1/0.2)} = \dfrac{0.2231}{1.6094} = \mathbf{0.1386} \approx 0.14$.

$L = \theta n^\rho = 3 \times (10^6)^{0.1386} = 3 \times 10^{0.8316} = 3 \times 6.78 \approx \mathbf{20}$.

Sanity: $\theta = 3$ ⟹ TPR $= 1 - e^{-3} = 0.95$. Twenty tables gives 95% recall on a million points — that is the headline result of the whole unit.

16 · MSQ
Which are true of the Fiedler vector $f_2$?
  • AIt is orthogonal to the all-ones vector.
  • BIt minimises $f^\top Lf$ among unit vectors orthogonal to $\mathbf 1$.
  • CIts entries are all in $\{0,1\}$.
  • DIts eigenvalue $\lambda_2$ equals the minimum value of the relaxed objective.
Answer — A, B and D

C is false and is the crux of the relaxation: we abandoned $\{0,1\}^n$ (NP-hard) for $\mathbb{R}^n$. The entries are arbitrary reals, which is exactly why a thresholding or 1-D k-means step is needed afterwards to recover a discrete partition.

A and D restate each other: orthogonality to $\mathbf 1$ deletes the trivial $\lambda_1 = 0$ direction, so the constrained minimum is $\lambda_2$.

17 · MCQ
A JL map with $\epsilon = 0.04$ is applied to points on a sphere of radius $5$. What is the tightest upper bound on the distance between two images?
  • A$10.2$
  • B$10.4$
  • C$5.1$
  • D$10.0$
Answer — A

Diameter upstairs is $2\times 5 = 10$. JL is on squared distances, so the multiplier on the distance is $\sqrt{1+\epsilon} = \sqrt{1.04} = 1.0198$. Bound $= 10 \times 1.0198 = \mathbf{10.198} \approx 10.2$.

B is $(1+\epsilon)\times10$ — forgetting the square root. C uses the radius instead of the diameter. This is the T2 Q9 archetype with different numbers.

18 · MSQ
Randomized SVD's error guarantee holds with probability at least $1-\delta$ and is expressed through an error term $\epsilon$. Which are true of $\epsilon$?
  • AIt depends on $\delta$, $k$ and $p$.
  • BIt degrades badly as $p \to 0$.
  • CIt depends on the matrix dimensions $m$ and $n$.
  • D$\epsilon = 0$ would mean $QQ^\top$ recovers the optimal rank-$k$ subspace exactly.
Answer — A, B and D

The guarantee is $\|A - QQ^\top A\|_2 = (1+\epsilon)\,\sigma_{k+1}$ with probability at least $1-\delta$.

A is the guarantee as stated. B is why oversampling is structurally required rather than a tuning nicety: with $\ell = k$ exactly the sketch has no slack, and one unlucky draw loses a direction outright.

C is false, and this is the striking part. The quality of the approximation is governed by the spectrum and by how much you oversample — not by how big the matrix is. A $10^6\times10^5$ matrix and a $100\times50$ matrix with the same singular-value profile get the same guarantee from the same $\ell$. That is what makes the method scale.

D is true: $\epsilon = 0$ gives $\|A-QQ^\top A\|_2 = \sigma_{k+1}$, which by Eckart–Young is exactly the best any rank-$k$ approximation achieves — i.e. $QQ^\top = U_kU_k^\top$.

19 · MSQ
Which failures of k-means does spectral clustering fix, and how?
  • ANon-convex clusters — because the graph captures connectivity, not straight-line distance.
  • BThe need to specify the number of clusters $k$.
  • CConcentric rings — each ring is densely connected internally, weakly to the other.
  • DThe two-moons dataset, where the closest pair of points spans the two clusters.
Answer — A, C and D

B is false: spectral clustering still needs $k$ — you choose how many eigenvectors to keep, and you still run k-means at the end. It fixes the shape limitation, not the model-selection problem.

All of A, C, D are the same fact in three costumes: Euclidean proximity is the wrong similarity; graph connectivity is the right one.

20 · MCQ
Which chain correctly traces how randomness is used across the whole course?
  • ARandom matrix → preserves distances (JL) → random hash → sub-linear NN (LSH) → random sketch → fast SVD → random edge sample → sparse graph
  • BRandom sampling → exact answers everywhere
  • CRandomness reduces memory but never affects running time
  • DRandomness is only used in JL
Answer — A

That is the course in one line, and the same three-beat pattern each time: exact is too expensive → randomize → concentrate. The concentration inequalities of Week 1 are the shared engine; the union bound is what upgrades a per-item guarantee into an all-items-at-once guarantee.

And the loop closes: JL (Week 1) is the tool used to compute effective resistances quickly (Week 6), which is what makes sparsification — and hence spectral clustering at scale — practical.

Part B — Weeks 7–12

Suggested run

Another 45 minutes for these twenty. Because the end term is two-thirds learning theory, this is the half to do twice.

21 · MCQ
A dataset $S$ of $n$ points is drawn i.i.d. from $D$. Which quantity is a random variable because $S$ is random?
  • A$\mathrm{er}_D[h]$ for a fixed $h$
  • B$\mathrm{er}_D^*$
  • C$\mathrm{er}_D[h_S]$
  • D$\mathrm{er}_D[H]$
Answer — C

A, B and D are all properties of $D$ (and $H$) alone — fixed numbers, unknown but not random. $h_S$ is chosen from the sample, so it inherits the sample's randomness, and therefore so does its test error.

This is the exact reason Hoeffding cannot be applied directly to $|\mathrm{er}_S[h_S]-\mathrm{er}_D[h_S]|$: both sides move with $S$. The $A\subseteq B$ trick exists to trade that expression for one where the classifiers are all fixed in advance.

22 · NAT
$P(y=1)=0.5$. $x\mid y=1 \sim U[0,2]$ and $x\mid y=0 \sim U[1,5]$. Find the Bayes error, to three decimals.
Answer — 0.125

Densities: $f_1 = \tfrac12$ on $[0,2]$; $f_0 = \tfrac14$ on $[1,5]$. Equal priors, so compare densities directly.

  • $[0,1)$: $f_1=\tfrac12 > f_0=0$ ⇒ $h^*=1$
  • $[1,2]$: $f_1=\tfrac12 > f_0=\tfrac14$ ⇒ $h^*=1$  (class 1 still denser)
  • $(2,5]$: $f_1=0 < f_0=\tfrac14$ ⇒ $h^*=0$

So $h^*=1$ exactly on $[0,2]$. Class $1$ never lands outside $[0,2]$, so it is never misclassified; the only errors are class-$0$ points landing in $[1,2]$, which happens with probability $\tfrac{2-1}{4} = \tfrac14$:

$$\mathrm{er}_D^* = \underbrace{0.5 \times 0}_{\text{class }1} + \underbrace{0.5 \times \tfrac14}_{\text{class }0} = \mathbf{0.125}$$

Traps. $0.375$ charges both classes for the overlap $[1,2]$ — but in the overlap $h^*$ picks the denser class ($1$) and is correct for it, so only class $0$ pays. $0.25$ forgets to multiply by the prior.

23 · MSQ
Which are true of the uniform convergence theorem for a finite $H$?
  • AIt holds for every $h \in H$ simultaneously.
  • BIt bounds $\mathrm{er}_D[h_S]$.
  • CThe sample complexity grows as $\log|H|$.
  • DIt requires the losses to be independent across data-points.
Answer — A, C and D

A is what "uniform" means, and it is precisely what lets the bound be applied to $h_S$ whichever member the algorithm returned. C: $|H|$ enters logarithmically, which is why a class of $10^6$ classifiers needs only about twice the data of one with $10^3$. D: Hoeffding needs independence — the unbiasedness step needs only identical distribution, but the concentration step needs both.

B is the headline misreading. The theorem equates the train and test errors; it never claims either is small.

24 · NAT
$H$ is the class of axis-parallel boxes in $\mathbb{R}^5$. What is $\mathrm{VCdim}(H)$?
Answer — 10

One interval per coordinate, $2$ endpoints each: $2d = 2\times 5 = \mathbf{10}$.

Same argument as the $\mathbb{R}^3$ cuboid on the T3 paper. Lower bound: put the $10$ points at $\pm e_1,\dots,\pm e_5$ — the face centres — and slide each of the $10$ faces independently. Upper bound: for any $11$ points, take the $10$ achieving the extreme coordinate in each of the $10$ directions, label them $1$ and one remaining point $0$; the bounding box of the extremes swallows everything.

Traps: $5$ (the dimension), $32 = 2^5$ (vertices of a hypercube), $6$ (the $\mathbb{R}^3$ answer not generalised).

25 · NAT
Randomized response with $\epsilon = \ln 3$. True data $X = (0,1,1)$. Compute $P\big(Y = (0,0,1)\big)$ as an exact fraction, then give it to three decimals.
Answer — 0.141

$e^{\epsilon} = 3$, so $p = \tfrac{3}{4}$ (truth) and $q = \tfrac14$ (flip) — the reason $\ln 3$ is a pleasant choice.

Compare coordinatewise: $X=(0,1,1)$ against $Y=(0,0,1)$ — agree at $1$ and $3$, flip at $2$.

$$P = p^2 q = \left(\tfrac34\right)^2\left(\tfrac14\right) = \frac{9}{64} = \mathbf{0.141}$$

Method check: $\#\text{agree} + \#\text{flip} = 3$ ✓. And note that unlike the $\epsilon=0.1$ past-paper questions (where $p\approx q$ and a sign error is nearly invisible), here $p$ and $q$ differ by a factor of three — swapping them gives $\tfrac{3}{64}=0.047$, which is obviously wrong. Practising at $\ln 3$ exposes the error that $\epsilon = 0.1$ hides.

26 · MCQ
An algorithm returns $h_S$ with train error $0$ on $n=50$ points, drawn from a class with $\mathrm{VCdim}(H)=\infty$. What can you conclude about $\mathrm{er}_D[h_S]$?
  • AIt is close to $0$ with high probability
  • BIt is close to the Bayes error
  • CNothing
  • DIt is close to $\mathrm{er}_D[H]$
Answer — C

Infinite VC dimension means the labeling count is $2^n$, so the bound $2^ne^{-2n\epsilon^2}$ does not go to zero and there is no uniform convergence. Without it, the train error carries no information about the test error — and with an unrestricted class you can always drive the train error to zero by memorising.

A and D each require a generalisation or estimation guarantee that does not exist here. B additionally requires the approximation error to vanish, which is a separate matter entirely. This is the formal content of "overfitting".

27 · NAT
A trusted curator releases $d=64$ statistics from $n=1000$ records, each statistic $\tfrac1n$-sensitive, with $\epsilon=1$. Take the ratio (Laplace noise spread) $\div$ (Gaussian noise spread), ignoring the $\sqrt{\ln(1/\delta)}$ factor. What is it?
Answer — 8

Laplace uses $\ell_1$ sensitivity: $\Delta_1 = \sum_{i=1}^{64}\tfrac1n = \tfrac{64}{n}$, giving spread $\tfrac{64}{n\epsilon}$.

Gaussian uses $\ell_2$: $\Delta_2 = \sqrt{64\cdot\tfrac{1}{n^2}} = \tfrac{8}{n}$, giving spread $\tfrac{8}{n\epsilon}$ up to the log factor.

$$\text{ratio} = \frac{64/(n\epsilon)}{8/(n\epsilon)} = \frac{d}{\sqrt d} = \sqrt d = \sqrt{64} = \mathbf 8$$

Notice $n$ and $\epsilon$ cancel — the ratio is $\sqrt d$ regardless. That is the entire payoff of relaxing to $(\epsilon,\delta)$-DP: quadratically less noise in the output dimension, for the price of a $\delta$ and a logarithm.

28 · MSQ
Which of these follow from the fact that $\mathrm{VCdim}(H) \le \lfloor\log_2|H|\rfloor$ for finite $H$?
  • AA class of $256$ classifiers has VC dimension at most $8$.
  • BThe infinite-$H$ sample complexity with $d$ in place of $\log|H|$ is consistent with the finite case.
  • CA class with VC dimension $10$ must have at least $1024$ classifiers.
  • DA class of $256$ classifiers has VC dimension exactly $8$.
Answer — A, B and C

A: $\log_2 256 = 8$. C is the same inequality read backwards — shattering $10$ points needs $2^{10}=1024$ distinct labelings, hence at least that many classifiers. B is the conceptual point: the two uniform-convergence theorems agree at the boundary, which is why "replace $\log|H|$ by $d$" is the right mental substitution.

D is the trap — it is an upper bound. A class of $256$ classifiers could have VC dimension $0$ (if they all agree on every point) or anything up to $8$.

29 · NAT
Using $n \ge \frac{1}{2\epsilon^2}\log\frac{2|H|}{\delta}$ with natural log: $\epsilon = 0.1$, $\delta = 0.05$, $|H| = 500$. Round up to the nearest integer.
Answer — 496 $$n \ge \frac{1}{2(0.01)}\ln\frac{2\times 500}{0.05} = 50\,\ln(20000) = 50 \times 9.9035 = 495.2 \Rightarrow \mathbf{496}$$

With the board variant $\log\frac{|H|}{\delta}$ it is $50\ln(10000) = 460.5 \Rightarrow 461$ — the two conventions differ by $50\ln 2 \approx 35$, which is why a well-posed question always states the form.

Sensitivity worth noticing: multiplying $|H|$ by $10$ adds only $50\ln 10 \approx 115$, whereas halving $\epsilon$ would quadruple the whole thing. Accuracy is the expensive axis.

30 · MCQ
Which pair correctly matches an obstruction to its cause?
  • ABayes classifier — computational; ERM — informational
  • BBayes classifier — informational; ERM — computational
  • CBoth informational
  • DBoth computational
Answer — B

$h^*$ is defined by a threshold on $P(y=1\mid x)$, a property of the unknown $D$ — you lack the information, not the compute. ERM has everything it needs in hand and still cannot run: minimising the $0$–$1$ loss over $H_{\mathrm{lin}}$ is NP-hard.

Keeping the two apart also explains the two fixes: you approximate $h^*$ by learning from data, and you approximate ERM by swapping in a convex surrogate. Different problems, different escapes.

31 · NAT
Seven mechanisms, each $(0.3,\,10^{-7})$-DP, run on the same dataset with all outputs published. Under basic composition, what is the total $\epsilon$? Give it to one decimal.
Answer — 2.1

Basic composition: $k$ mechanisms each $(\epsilon,\delta)$-DP compose to $(k\epsilon,\,k\delta)$-DP.

$$\epsilon_{\text{total}} = 7 \times 0.3 = \mathbf{2.1}, \qquad \delta_{\text{total}} = 7\times10^{-7}$$

An $\epsilon$ of $2.1$ means $e^{2.1}\approx 8.2$ — the adversary's likelihood ratio between neighbouring datasets is now a factor of eight, which is a weak guarantee. That degradation is why advanced composition matters: its leading term is $\epsilon\sqrt{k\log(1/\delta')}$, so the $k$ becomes $\sqrt k$.

Trap: advanced composition is available for the Gaussian mechanism only — with Laplace you are stuck with $k\epsilon$. That single fact is why DP-SGD adds Gaussian noise.

32 · MSQ
$S$ has $n$ points labelled by some $h\in H_{\mathrm{apr}}$. Which are true of its size-$4$ compression scheme?
  • AThe four retained points are all positive.
  • BDecompression must relabel all $n$ points correctly.
  • CThe retained points need not belong to $S$.
  • DIt fails if every point of $S$ is negative.
Answer — A, B and D

A: you keep the extremes in each of the four directions, all from the positive class — negatives carry no information about where the rectangle's edges go. B is the defining requirement. D is the professor's own stated caveat: with no positives there is nothing to retain, and the sketch as given breaks. Complete versions handle the corner cases; the exam only asks for the size.

C is false and is what makes this compression: $T \subseteq S$. You select points, you do not synthesise them. A scheme allowed to invent points would be model fitting, and the connection to VC dimension would evaporate.

33 · NAT
Valuations $5, 5, 5, 100$. Under the exponential mechanism with revenue as the score, what is $OPT$?
Answer — 100

Revenue is $S(x,p) = p \times \#\{i : v_i \ge p\}$. Check the only prices that can be optimal — the valuations themselves, since revenue only drops between them:

  • $p=5$: all four buy ⇒ $5\times 4 = 20$
  • $p=100$: one buys ⇒ $100\times 1 = \mathbf{100}$

So $OPT = \mathbf{100}$ at $p^\star = 100$.

Why the optimum sits at a valuation: raising the price between two valuations loses no buyers and gains revenue, so the maximum is always attained at some $v_i$. That reduces the search to $n$ candidates — and it is also why the revenue curve is a sawtooth rather than smooth, which is what breaks naive Laplace perturbation of the price.

Trap: $115 = 20+100$ adds the two branches; the seller sets one price.

34 · MCQ
Which statement about SRM is correct?
  • AIt reduces the generalisation error by adding data.
  • BIt balances train error against a VC-dimension penalty across a nested family of classes.
  • CIt is the standard practical algorithm for training classifiers.
  • DIt requires the Bayes classifier to be known.
Answer — B

SRM runs ERM inside each $H_i$ of a nested family and scores the results by $\mathrm{er}_S[h_i^{\mathrm{ERM}}] + \sqrt{\frac{d_i\log(n/d_i)+\log(1/\delta)}{n}}$. Bigger classes fit better but pay more penalty, which is exactly the approximation-versus-estimation trade-off made explicit.

C is false — the professor is emphatic that SRM is impractical (ERM alone is NP-hard, and SRM wants many of them). In practice the same effect is achieved indirectly by regularisation, with $\lambda$ playing the penalty's role and cross-validation choosing it. A is the wrong error (SRM targets approximation, not generalisation); D would defeat the purpose.

35 · NAT
How many distinct labelings can $H_{\mathrm{int}}$ realise on $8$ distinct points in $\mathbb{R}$?
Answer — 37 $$\frac{n(n+1)}{2} + 1 = \frac{8\times 9}{2} + 1 = 36 + 1 = \mathbf{37}$$

Contiguous runs (choose a first and last point: $\binom82 + 8 = 28+8 = 36$) plus the empty labeling.

Compare with $2^8 = 256$ for unrestricted classifiers. The restriction has cut the effective class size by a factor of seven at $n=8$, and the gap widens fast — that is why uniform convergence survives for $H_{\mathrm{int}}$ and dies for the class of all functions. Traps: $36$ (forgot all-zeros); $45 = 9+8+\cdots+1$ (the board's over-counting bound).

36 · MSQ
Which are true of $\epsilon$-differential privacy?
  • AThe guarantee must hold for every measurable subset of the output space.
  • BNeighbouring datasets differ in exactly one entry.
  • CAny post-processing of a private output remains private.
  • DSmaller $\epsilon$ means weaker privacy.
Answer — A, B and C

A is what makes the definition usable for continuous outputs, where every single output has probability zero. B is the definition of "neighbouring" — and note it generalises beyond bit flips: swap one point of $\mathcal X^n$ for any other point of $\mathcal X$. C is the post-processing property, and it is what lets you hand a private release to anyone without further accounting.

D is backwards. Privacy is the ratio bound $e^\epsilon$; $\epsilon \to 0$ drives the ratio to $1$, meaning the output distribution is identical for neighbouring datasets — maximal privacy. Larger $\epsilon$ lets the adversary distinguish more easily.

37 · MCQ
Two classifiers assign identical labels to all $n$ training points. What follows?
  • AThey have the same train error and the same test error.
  • BThey have the same train error but possibly different test errors.
  • CThey are the same classifier.
  • DThey have the same test error but possibly different train errors.
Answer — B

The train error is computed only from the $n$ labelled points, so identical labelings force identical train errors. The test error is an expectation over all of $D$, and the two classifiers can disagree everywhere off the sample — $h_{3,7.5}$ and $h_{3.001,7.499}$ label the same points identically but are different functions.

This is precisely the gap the professor flags when he says the labeling-count argument needs a symmetrisation trick to become a real theorem, and defers it to a full learning-theory course. For this course, the conclusion to carry is that the effective class size is what appears in the bound — with an honest asterisk about how the proof is completed.

38 · NAT
Binary labels, one feature. $P(y=1)=0.8$, $x\mid y=1\sim U[0,1]$, $x\mid y=0\sim U[0,1]$. Find the Bayes error.
Answer — 0.2

The class-conditional densities are identical, so $x$ carries no information about $y$ — the feature is useless. Bayes' rule gives $P(y=1\mid x) = P(y=1) = 0.8 \ge 0.5$ for every $x$, so $h^*(x) = 1$ everywhere.

$$\mathrm{er}_D^* = P(y=0) = \mathbf{0.2}$$

The lesson: the Bayes error is the irreducible noise floor. No classifier — in any hypothesis class, with any amount of data — beats $0.2$ here. It is also a clean illustration of why $\mathrm{er}_D^*$ need not be zero, and why "the Bayes error is zero" was a wrong option on both May-2025 papers.

Traps: $0.5$ ignores the prior and assumes a coin flip; $0$ assumes optimal always means perfect.

39 · MCQ
A curator uses the Laplace mechanism to release the average of $n$ bits. Which change requires more noise?
  • AIncreasing $n$
  • BDecreasing $\epsilon$
  • CIncreasing $\epsilon$
  • DReleasing the average instead of the sum
Answer — B

The spread is $\tfrac{\Delta}{\epsilon} = \tfrac{1}{n\epsilon}$. Smaller $\epsilon$ ⇒ larger spread. Intuitively, a stricter privacy requirement means the two output densities must overlap more, which needs wider noise.

A goes the other way: more people dilute each individual, so $\Delta = \tfrac1n$ shrinks and less noise is needed. C is the opposite of B. D is inverted — the sum has $\Delta = 1$ while the average has $\Delta = \tfrac1n$, so switching to the average needs $n$ times less noise.

40 · MCQ
Which sentence best captures the arc of the whole course?
  • ARandomness makes computation cheap (W1–6), lets us prove that learning generalises (W7–10), and protects individuals (W11–12) — with concentration inequalities and the union bound as the shared engine.
  • BRandomness is used only to speed up matrix computations.
  • CWeeks 1–6 and 7–12 are unrelated topics sharing a course code.
  • DStatistical learning theory replaces the need for concentration inequalities.
Answer — A

Three uses of the same tool. Weeks 1–6: probability as an algorithmic tool — randomise the computation, then use a tail bound to show the answer is nearly right. Weeks 7–10: probability as an analytical tool — the same Hoeffding and the same union bound, now proving that a train error measured on $n$ random points predicts behaviour on unseen data. Weeks 11–12: probability as a shield — inject calibrated noise so the output reveals the population but not the person.

D is exactly backwards, and it is the misconception worth killing before the exam: the uniform convergence proof is Hoeffding plus the union bound plus the subset bound $A\subseteq B \Rightarrow P(A)\le P(B)$ — all three straight from Week 1. Nothing was replaced; the Week 1 toolkit was pointed at a new question.


The last thirty minutes

Night-before checklist

If you can answer these out loud without looking, close the laptop. The cards are ordered by marks on the paper, not by week number.

The two-thirds — Weeks 7–12

VC dimension

The two-player game, and both halves of the definition with their quantifiers. Derive a VC dimension for a class you have not seen — count free parameters, then verify. Know $H_{\mathrm{int}}=2$, $H_{\mathrm{apr}}=4$, boxes in $\mathbb{R}^d = 2d$, $H_{\mathrm{lin}}=d$ (with bias $d+1$), origin-centred circles $=1$, $\mathrm{sign}(p)$ with $\deg\le m$ gives $m+1$, triangles $=7$, finite class $\le\log_2|H|$. Reproduce the $H_{\mathrm{lin}}$ proof in both directions.

The decomposition

Write all three gaps from memory. Which is $\ge0$, which is $\ge0$, which is unsigned. The tells: generalisation is the only one with $\mathrm{er}_S$; approximation the only one with $\mathrm{er}_D^*$. Which is fixed by more data, and which is not.

Bayes classifier & error

Cross the two class-conditional densities (with priors if unequal), find $\theta$, then charge each class only where $h^*$ gets that class wrong. Uniform, exponential and discrete PMF versions. Know that $\mathrm{er}_D^*$ is non-negative — sometimes zero, sometimes not.

ERM

It maximises accuracy. It is NP-hard for $H_{\mathrm{lin}}$; surrogates are logistic→LR, hinge→SVM, exp→boosting. The $\epsilon/2$ estimation bound and why the $2$ costs a factor of four in $n$. Be able to find the best $w$ or $\theta$ on a four-point dataset by hand.

Uniform convergence

Unbiased (needs i.d.), then Hoeffding (needs independence), then $A\subseteq B$, then the union bound. $n\ge\frac{1}{2\epsilon^2}\log\frac{2|H|}{\delta}$ — and the direction each of $\epsilon,\delta,|H|$ moves it. What the theorem does not say.

Infinite classes

Why $2^ne^{-2n\epsilon^2}$ fails and $n^de^{-2n\epsilon^2}$ works — exponential vs polynomial growth. The exact interval count $\frac{n(n+1)}{2}+1$, and $c^n$ for $c$ classes.

SRM & compression

Nested classes, ERM in each, plus the VC penalty; regularisation as the practical proxy. Compression sizes $2$ and $4$; size $k$ ⇒ VC $=O(k)$, converse open.

Privacy

Randomized response: $p=\frac{e^\epsilon}{1+e^\epsilon}$, and $P(Y=b\mid X)=p^{\#\text{agree}}q^{\#\text{flip}}$. The $e^\epsilon$ proof by cancelling $n-1$ factors. $\epsilon$-DP and $(\epsilon,\delta)$-DP. Sensitivity of the average $=\tfrac1n$; Laplace spread $\Delta/\epsilon$. Laplace $\frac{1}{\epsilon n}$ beats RR $\frac{1}{\epsilon\sqrt n}$. Post-processing, composition $k\epsilon$ vs $\epsilon\sqrt k$. Exponential mechanism scores, not perturbs.

The other quarter — Weeks 1–6, statements only

Concentration

All three bounds with hypotheses: which needs non-negativity, which needs independence, which is two-sided. Chebyshev in $\sigma$-units. The union bound and the subset bound — you will use both in the SLT proofs.

JL

$(1\pm\epsilon)$ on squared distances, and only for pairs in $D$ — never all of $\mathbb{R}^d$. $k\in O(\log n/\epsilon^2)$, independent of $d$. And $a^\top r \sim \mathcal N(0,\|a\|^2)$.

LSH

Both inequalities in the right direction — near pairs get the large probability. AND lowers both rates, OR raises both: TPR $=1-(1-p_1^k)^L$, FPR $=1-(1-p_2^k)^L$. TPR $>$ FPR strictly.

SVD

Eckart–Young: $\|A-A_k\|_2 = \sigma_{k+1}$, the first one discarded. Best rank-$k$ is $U_k\Sigma_kV_k^\top$ — for rank-1, only $\sigma_1u_1v_1^\top$ matters and the rest of $U$ is noise in the question.

Spectral

$L=D-W$, every row sums to zero, $L\mathbf1=0$, so $0$ is an eigenvalue and $L$ is PSD but never PD. Sparsifier: $L_H$ sandwiched by $(1\pm\epsilon)\theta^\top L_G\theta$.

Cross-unit

Notice the reuse: the subset bound from W1 L5 is the pivot of the W8 uniform-convergence proof, and $a^\top r\sim\mathcal N(0,\|a\|^2)$ powers both JL and the LSH collision analysis. The exam likes these joins.

Six habits that convert knowledge into marks
  1. For a VC question, play the game. Count free parameters for a guess, then discharge both halves: construct one good set of $k$ points, and argue every set of $k+1$ fails. Ask what structural property forces the contradiction — connectedness, linear dependence, "at most $m$ roots", monotonicity.
  2. For a Bayes question, sketch the two densities. Ten seconds, and it prevents every sign error. Then charge only the losing density in each region — never both.
  3. Read $\delta$ as "probability of the bad event". Not confidence. Larger $\delta$ means less data needed. This single reading was worth marks on the T3 paper.
  4. For randomized response, count agreements and flips. Answer is $p^aq^f$ with $p>\tfrac12$. Sanity-check against $2^{-n}$ when $\epsilon$ is small.
  5. On MSQs, evaluate every option. No negative marking, but under-selecting scores zero. Several past MSQs had three correct options.
  6. Handle comprehension blocks as blocks. Both papers cluster two or three sub-questions on one setup, so a single modelling error costs all of them. Before answering part one, ask whether $H$ contains a zero-error classifier — on the concentric-circles block that one observation answered a whole two-mark part in a line.
If you remember one thing

Every result in this course is built from four things you met in Week 1: Markov, Chebyshev, Hoeffding, and the union bound (plus its quiet sibling, $A\subseteq B\Rightarrow P(A)\le P(B)$).

In Weeks 1–6 they certify that a randomised computation is nearly right. In Weeks 7–10 the identical machinery — Hoeffding on $\{0,1\}$ losses, the subset bound to handle a data-dependent classifier, the union bound over a hypothesis class — certifies that a measured train error is nearly right. In Weeks 11–12 the same probabilistic thinking, run backwards, calibrates how much noise hides a person while still revealing a population. Learning theory did not replace the Week 1 toolkit. It pointed it at a new question.