The bill for being wrong — and why the squares are squares
A tailor cuts three sleeves to a rule of thumb — "sleeve length is w times the arm measurement". Each sleeve comes out a little long or a little short, and every miss costs a square patch of cloth with the miss as its side: miss by 1 cm, pay for 1 cm²; miss by 3 cm, pay for 9 cm². Short and long cost the same, and one big miss costs more than three small ones. The bill is the total area of the patches. Turn the knob w and watch the patches grow and shrink:
Everything a model does while "training" is on that picture. The knob is a parameter. The three points are the data. The bill is the loss, and the squares are not a metaphor: the loss is the total area of the squares. Slide the knob and the areas change together — the first square wants the line steeper, the third wants it flatter, and the knob settles where they stop being able to shrink at once. That is the bottom of the bill curve on the right: slope zero, bill smallest.
For one knob you can read the bottom off the curve. With many knobs the bill is still a sum of squares — one square per data row, now with the side "what I predicted minus what was true" — and there is no curve to look at, only the tilt under your feet. The tilt has a beautiful shape once you see the squares: each square pushes the knobs in the direction of its own data row, harder when its miss is bigger. The uphill direction is just all those pushes added up.
Each row pulls the knobs along its own feature vector, in proportion to its miss. Positive miss (predicted too much) ⇒ push the knobs down along that row. That one sentence is the whole gradient of least squares — and it is the sentence you would have written after watching the squares.
Press ▶ on the tailor's bill with the stride : the knob hops , the bill . Each hop closes the remaining gap to the bottom by the same fraction, — the bouncing ball of Unit 9, now with a bill attached. Push past and the hops overshoot by more than they gain: the squares grow. Keep that number in mind; the whole unit is about what sets it.
The tailor's three misses are currently : every sleeve is too short (the line is below all three points). Which way does the bill's tilt push the knob ?
If you want the algebra · 2 proofs, step by step
Claim. For , .
Claim. For , and : , , , and the per-step factor at stride is .
The parachute drop — where you start
Before the walk in the fog there is a parachute drop: somebody has to choose where the walker lands. Two mistakes are famous. Drop from too high, in the wrong place, and the first step is so violent it throws you off the map. And drop a whole team on the same square metre, all facing the same way, and they will take exactly the same steps for ever — a team of one. Watch the first mistake happen in numbers:
The overflow ladder is the surprising one. A modest start (), a plain feature (), a small-looking stride () — and the error does not shrink by a factor, it multiplies by every step. By step 163 the number is larger than any a computer can hold; it becomes , then , which is , and the whole run is dead. Now slide anywhere you like: nothing changes. The start was never the culprit. The factor per step is , and with that is . The feature's size, squared, is what set the speed limit, and the only escape is a stride under — absurdly tiny, because is absurdly big. That is why the lecture's advice for the start is so modest: small numbers in (or when the knobs must stay positive). Small starts do not cause overflow; they just do not add to a problem the data's units have already created. Sections 4 and 10 fix the units.
The clones tab is the second mistake. Two knobs that play symmetric roles, started at exactly the same value, receive exactly the same tilt — so they stay equal after every step, for ever. Two neurons started as clones never stop being clones: the network has half the neurons it seems to have. Nudge one start a little (drag separation off zero) and the tie breaks at once. That is the whole reason initialisation is random: randomness costs nothing and it is the only thing that lets identical knobs become different.
Start small, central and random. Small: , so you do not throw the first step off the map. Random: so no two symmetric knobs are clones. And when the numbers blow up anyway, look at the factor — it is the data's units, not your start, that need fixing.
With and every start overflows. You halve the start to . What happens?
If you want the algebra · 1 proof, step by step
Claim. For the one-feature bill , gradient descent multiplies the error by every step, whatever is; it converges iff .
Full marks by memorising — knobs versus facts
Two students sit the same three-question test. One learned the subject and gets 96 %. The other memorised last year's answer key — and this year's paper happens to be the same three questions, so she scores 100 %. Which one would you hire? The trap is that the number you can see says the memoriser is better. The lecture's data has exactly this shape: three rows, five knobs, and the truth is simply y ≈ x₁. Drag the unseen point:
The honest model has one knob set to 1 and the rest to 0: it says y = x₁. On the three rows it misses by , a bill of . The memoriser ignores altogether and uses the other columns and the constant to hit all three rows exactly — a bill of . Any optimiser told "make the bill smallest" will choose the memoriser without a flicker of doubt.
Now drag the unseen point. Its truth slides along the diagonal, because the truth really is . The honest model's prediction slides with it. The memoriser's prediction is a flat line at : it does not contain , so it cannot respond to it. At it is off by — and that is a typical error, not an unlucky one. Zero on the training rows, hopeless on the world.
How was zero even possible? Count. Five knobs, three facts. Three equations in five unknowns have infinitely many exact solutions — two knobs are left completely free. Being told "two numbers add to 10" does not tell you the numbers. The data never pinned the knobs down, so the optimiser handed you one of the infinitely many settings that fit, and it has no way of knowing which one means something. The honest model's is not a failure to fit; it is the size of the noise in the three rows. Chasing that last to zero is where learning turned into memorising.
More knobs than facts ⇒ zero training bill is free ⇒ zero training bill means nothing. Judge a model on rows it has never seen. (Later units will make the memoriser expensive by adding a penalty on big knobs — a regulariser — so that "fits the data with small knobs" beats "fits the data with any knobs".)
The deck quotes the memorising solution as . Check row 1: , but . Solving the three equations properly gives (the drawer below and Practice Problem 8 do it line by line). The lesson is untouched; only the arithmetic needed a nudge.
A model has knobs and you train it on rows. The training bill lands on exactly . How pleased should you be?
You drag the unseen point from to (truth ). What do the two models predict?
If you want the algebra · 2 proofs, step by step
Claim. With , the three rows are hit exactly by ; the slide's does not hit row 1.
Claim. If a linear model has knobs and training rows whose feature vectors are independent, there are infinitely many with .
The hair-trigger and the stiff knob
An old radio has two knobs. One is a hair-trigger: a millimetre of turn swings the station wildly. The other is stiff: you can spin it and almost nothing happens. Now imagine you are only allowed to turn both by the same amount per move. Any move gentle enough not to over-turn the hair-trigger is far too gentle to budge the stiff one. You will overshoot on one dial and crawl on the other. That is precisely what one stride does to two parameters whose features have different sizes:
The lecture's model predicts wealth from age and years of college: . Age runs to ; college runs to . At a typical person (, ) the bill is times more sensitive to the age knob than to the college knob — because sensitivity is the feature's value, squared, and . Same stride, so the age knob moves times further per step. Press ▶ and watch the needles: the age dial swings past its mark and back; the college dial creeps.
Try to fix it with the stride alone. Protect the hair-trigger (a stride that moves by ) and the stiff knob needs thousands of steps per unit. Serve the stiff knob and the hair-trigger swings by whole units and oscillates. There is no stride that suits both, because the imbalance is not in the stride — it is in the units of the features. Age in years and college in years are both "years", but their sizes differ by ten, and the bill feels sizes squared. The only real fix is to make the two features the same size. That is the next section, and — after a detour through valleys and canyons — the whole of Section 10.
: a knob's sensitivity is its feature's size, squared. One stride moves knob by . Different feature sizes ⇒ one knob overshoots while another crawls, and no can serve both. Normalisation exists to make the same size for every .
At the current step, and , and one stride serves both. How far does each knob move this step, and roughly how many steps does need to travel one unit?
If you want the algebra · 1 proof, step by step
Claim. For and a squared-error bill, one stride moves by and by per row — a ratio of ( at ).
Three ways to fix the units — centre, standardise, min–max
A map of a country drawn with kilometres east and metres north is a long thin smear: every route looks like it runs east–west. Nothing about the country is thin; the units are. Redraw the north axis in kilometres and the shape reappears. The data is the map. Here are the three redrawings the lecture uses, side by side, on a cloud you can watch move:
Three operations, each a motion you just saw. Centring subtracts each column's mean: the cloud slides so its centre sits on the origin. Shape unchanged; it only removes the "everything is around 15" offset that makes all columns look alike to a knob. Standardising also divides each column by its spread: the cloud squeezes so that every column has spread . After this, "one unit" means "one standard deviation of surprise" in every column — the radio's two knobs now have the same stiffness. Min–max squashes every column into : the cloud is pressed into a box. Simple and bounded, but look at the outlier preset: one wild point squashes everybody else into a corner, and a new value beyond the training maximum lands outside the box ( on the practice column, where standardising would have said an unremarkable ).
One rule the widget insists on: the unseen point is transformed with the training statistics. The mean and spread are part of the model now. Recompute them with the test point and the test point has leaked into the training.
| Repair | Formula | What moves | Use it when |
|---|---|---|---|
| centre | the cloud slides onto the origin; shape unchanged | the offset is the problem, not the scale | |
| standardise | slides, then squeezes to spread per column | almost always — the default before gradient descent | |
| min–max | pressed into the unit box | bounded inputs matter and there are no outliers |
Normalisation changes the units, not the meaning. Standardised columns each have mean and — every column is now the same size — so one stride can serve every knob. What it does not remove is a tilt: two columns that rise and fall together stay tilted after standardising. That leftover is Section 10's last word.
A training column has , minimum and maximum . A new value arrives. What do standardising and min–max make of it?
If you want the algebra · 1 proof, step by step
Claim. For with and : and .
The wrong valley — the watershed and the combination lock
Rain falls on a mountain ridge. Every drop rolls downhill and ends in a lake — but which lake was decided the instant it landed, by which side of the ridge it fell on. A drop one centimetre left of the crest ends in the shallow lake; one centimetre right, in the deep one. The crest is the watershed. Gradient descent is a raindrop. Drop a few dozen on the lecture's landscape and watch them sort themselves:
The lecture's curve has two valleys: a shallow one at (height ) and a deep one at (height ), with a hilltop between them at . Every marble that lands left of the hilltop rolls into the shallow valley and stops there, reporting success, with a valley five units deeper sitting next door. It never had a hint. The walk in Unit 9 only ever found "the valley downhill from here"; this is the price. Drop the marbles on and about reach the deep valley — the share of the range that lies right of the watershed. Nothing about the walk changed that number; only the drop zone did.
So restart from several random places and keep the best? On a line, yes: with a chance per drop, six drops find the deep valley of the time. Now open the lock tab. A landscape with many knobs is a combination lock: if each knob's own curve has flat spots, the whole landscape has a flat spot for every combination — of them, and exactly one is the true bottom. Ten dials with three notches each: valleys. Fifty dials: about . And the chance that a single drop lands right on every dial multiplies too: . Restarts cannot rescue that. (Deep learning lives with it: on the landscapes of large networks most valleys turn out to be about equally good, and Section 11 says what to do when they are not.)
For a loss that splits into one-knob pieces, , the tilt in knob is alone — so any choice of one flat spot per knob is a flat spot of . Count: local minima. With independent per-knob odds , one run lands in the global basin of every knob with probability , and restarts fail with probability .
Marbles are dropped uniformly on of the lecture's curve, whose watershed is at . What fraction reaches the deep valley, and how many independent drops make the chance of at least one success reach ?
A loss splits into one-knob pieces, each with flat spots of which one is its true bottom, and a random start lands in each knob's best basin with probability . How many flat spots does the whole loss have, and what is the chance one run lands in the best basin of every knob?
If you want the algebra · 3 proofs, step by step
Claim. is flat at , , : valley (), hilltop (), valley ().
Claim. If and has local minima, then has local minima.
Claim. If one run finds the global valley with probability , independent runs (keep the best) succeed with probability ; for and a target, .
The salt flat — where the walk slows to nothing
You have come down a cliff at a run and stepped onto a salt flat. The ground is level in every direction. Your one rule — "feel the tilt, step that way, and step further the steeper it is" — now gives you almost nothing to act on. You are not at the bottom of anything; you are on a plateau, and you shuffle across it in steps you can barely see. Watch the footprints:
The footprints are the whole story. Sparse on the cliff, where every step is long. Then a dense glowing band across the shelf, where two hundred steps pile up in the space a handful covered on the slope. Then long strides again down into the bowl. Nothing is wrong with the walker; the step is times the tilt, and on the flat the tilt is tiny. The height chart on the right shows the same thing as a long horizontal ledge before the final drop.
The arithmetic is brutal. Tilt , stride : each step moves . A flat two units wide takes steps — hours of compute to go nowhere, on a plateau that is not a minimum and never was. Unit 9 already showed the walk slowing down as it nears a valley bottom; that is the same effect and there it is welcome. On a plateau it is a trap: the walker slows for the same reason (small tilt) in a place that deserves no slowing.
Step length . Small tilt ⇒ small step, whether or not you are near a minimum. Steps to cross a flat of width and tilt : about . The cures are the next unit's: momentum, which carries speed across the flat instead of re-deciding at every footstep, and strides that grow when the tilt stays small.
The loss has barely moved for steps: Which is the wrong conclusion?
If you want the algebra · 1 proof, step by step
Claim. Crossing a flat of width where the tilt is about takes roughly steps — for , , .
The canyon — why the fastest way down is the wrong way down
You are skiing down a narrow gully. The way you actually want to go is along the gully, gently downhill. But the steepest slope under your skis points at the wall. So you shoot across, hit the far wall, shoot back. Every run is downhill; you are barely getting anywhere. Two bowls, one round and one stretched, and the same walker on both:
Set : a perfectly round bowl. From anywhere, the tilt points straight at the bottom — the two arrows lie on top of each other — and a stride of lands every point on the bottom in one step. Now set : the lecture's elliptical bowl, four times stiffer across than along. The tilt no longer points at the bottom (watch the angle between the two arrows open up). Press ▶ at the lecture's stride : the -coordinate flips sign every step, , each time correcting the overshoot of the last; the -coordinate creeps, . After six steps is essentially solved and is still at . Most of the motion was sideways.
The two shrink bars say why nothing better was available. Each coordinate is its own one-dimensional problem, multiplied by its own factor each step: along the floor, across the walls. The stiff wall demands or it explodes; at that cap the floor factor is , which for a stiff wall is close to — a crawl. Serve the wall and the floor crawls; serve the floor and the wall blows up. This is the radio of Section 4 again, now drawn as a landscape: different curvatures in different directions are the same disease as different feature sizes. The lecture's phrase is exact: steepest descent is only the best instantaneous direction, never the best direction for the long run.
On : . Stability needs both factors inside , so the stiffest direction sets the speed limit , and the ratio — the condition number — says how badly the soft direction crawls at that limit. is a round bowl and one step; big is a canyon and a zig-zag.
On with you start at . Where are you after one step, and which coordinate is misbehaving?
For , what is the largest stride that does not blow up, and which direction sets it?
If you want the algebra · 2 proofs, step by step
Claim. On , gradient descent gives , ; it converges iff (for ), and the -coordinate bounces (sign flips) once .
Claim. On , sends every point to the origin in one step; on with no single does.
Why the compass crosses the contour lines at a right angle
A path that runs level along a hillside — neither climbing nor descending — is a contour line. Stand on it and ask: which way is straight up? Not along the path (that stays level). Straight across it. Every hiker knows this without a formula: the steepest way up a hill is at a right angle to the level path. Drag the point and watch the compass needle:
Wherever you put the point, the uphill needle meets the contour through it at exactly . The reason is one sentence: a tiny move along the contour does not change the height, and the change in height for a tiny move is "tilt dotted with the move" — so tilt dotted with the along-the-contour move is zero, which is what a right angle means. Press ▶ and the point glides around its own contour while the needle rotates to stay perpendicular.
Now the payoff. On the round bowl, "across the contour" happens to be "toward the centre", so the needle points at the answer from anywhere: that was the one-step finish of Section 8. On the stretched bowl the contours are ellipses, and across an ellipse is not toward its centre — the angle between the needle and the straight line to the bottom is the third readout, and it is the exact size of the zig-zag. On the tilted bowl the ellipses are turned, so even a walker who has fixed the scale of each axis still sees a gap. That tilt is correlation between the features, and it is the one thing the next section's fix does not remove.
Along a contour is constant, so for a small step along it gives : the gradient is perpendicular to every contour. It points at the minimum only when the contours are circles.
On at the point , what is the angle between the gradient and the contour through the point — and between the gradient and the straight line to the minimum?
If you want the algebra · 1 proof, step by step
Claim. If is a small displacement along a contour of , then .
Change the units, not the model — the canyon becomes a bowl
Three countries, two numbers each — guns per person () and ounces of butter per person () — and a happiness score to predict (). The butter numbers are thirty times the gun numbers, so the bill is over a thousand times stiffer in the butter knob than in the gun knob. The landscape is a razor blade. You hold the dial that standardises the two columns. Turn it:
At the surface is the trench from the top of the page: stiff wall, soft floor, . Press ▶: forty steps just under the speed limit bounce wall to wall and barely move along the floor. Now slide to . The trench opens under your finger into a bowl — a slightly tilted one, — and the same forty steps walk nearly straight in. Look at what changed and what did not. The data means exactly what it meant. The model is the same two knobs. The best fit is the same fit, written in new units. Only the units of the columns moved, and fell by a factor of , the safe stride grew from to , and the number of steps to shrink the error a hundredfold along the soft direction fell from thousands to a couple of dozen. This is the cheapest win in all of machine learning, and it is the sentence Sections 4, 5 and 8 were building toward.
Why does standardising land so precisely on the fix? Because the stiffness in each knob is (twice) the sum of squares of its column — the bill feels the columns squared, so a column thirty times bigger is a wall nine hundred times stiffer. Dividing every column by its own spread forces every column's sum of squares to , so every diagonal stiffness becomes the same . The walls are now the same height by construction.
And the leftover tilt? The bowl at still leans, and is , not . The lean comes from the off-diagonal: guns and butter rise and fall together in this data (correlation ), so the two knobs are not independent, and Section 9's tilted contours are exactly what you see. Scaling equalises the axes; it does not straighten them. Try the whiten preset: standardise and then rotate onto the bowl's own axes, and becomes exactly — a perfect round bowl, one step to the bottom. Finding those axes is what Unit 12 is for (it is called PCA); the adaptive strides of the next unit are the practical version of the same wish.
The least-squares bill has Hessian : stiffness in knob is , the column's size squared. Standardising makes every column's , so every diagonal becomes — the walls level out. On this data: , speed limit . The off-diagonal — correlation — survives; removing it is whitening, a rotation, not a rescaling.
You standardise the two columns of the guns-and-butter data. Which of these changes?
After standardising, is rather than . What is the leftover, and which repair would remove it?
If you want the algebra · 2 proofs, step by step
Claim. For : , with . After standardising, every .
Claim. The symmetric matrix with equal diagonals and off-diagonal has eigenvalues and ; hence has and , , against and , , before.
The training clinic — read the loss curve like a doctor
A doctor does not see the disease; she sees the chart. You will not see the landscape either — only the loss, step after step. Everything in this unit has a signature on that chart. Six recorded runs, one diagnosis each. Read the curve, name the cause, pick the fix:
Once you have diagnosed all six, notice that the fixes come in only two families. Reshape the landscape so the plain walk works: scale the features, initialise sensibly, add a penalty on big knobs. That is this unit. Give the walker better instincts: momentum that keeps rolling across a flat, a private stride per knob so the stiff one is not held hostage by the hair-trigger, or a feel for the curvature and not just the slope. That is the next unit. Almost every trick in modern optimisation is one of the two.
| The chart says | What is going on | What to do |
|---|---|---|
| loss becomes / NaN in a few steps | overflow: huge start or unscaled features | start in ; scale the features; lower |
| training loss , test loss climbs | memorising: more knobs than facts | more data, fewer knobs, a penalty on big knobs, stop early |
| sawtooth that grows | in the stiff direction | reduce ; standardise |
| falls fast, then crawls for ever | zig-zag in a canyon (big ) | standardise; momentum, adaptive strides |
| flat from the very first step | a plateau, a dead start, far too small — or a wrong gradient | raise ; momentum; better start; audit the gradient |
| different runs, different answers | several valleys, different watersheds | restarts, keep the best — or accept it |
A run's loss goes — a sawtooth that slowly grows. What is wrong, and what is the first thing to try?
What to carry forward
Four ways the walk goes wrong, one fix that does most of the work, and a picture for each.
| The picture | What it says | The line of math it becomes |
|---|---|---|
| The tailor's patches | the bill is the area of the squares; each row pushes along itself, by its miss | |
| The parachute drop | land small, central, random; blow-ups come from the units, not the start | ; factor |
| Last year's paper | more knobs than facts makes a zero bill free and meaningless | infinitely many exact fits |
| Two knobs, one hand | sensitivity is the feature's size squared; no stride serves both | |
| The map redrawn | centre slides, standardise squeezes, min–max boxes; use training statistics | , |
| Rain on a ridge | the watershed decides the valley; valleys multiply like a combination lock | minima; ; |
| The salt flat | small tilt, small step — a plateau is not a minimum, just slow | steps |
| Skiing the gully | each direction shrinks by its own factor; the stiffest sets the limit | ; ; |
| The hillside path | the tilt crosses every contour at a right angle; it points at the bottom only on circles | |
| Guns and butter | standardising levels every wall to ; only correlation's tilt remains | ; |
| Six patients | every failure has a signature on the loss curve | reshape the landscape, or teach the walker |
Change the units, not the model. The bill feels every feature squared, so features of different sizes make a canyon: one stride overshoots on the stiff wall and crawls along the soft floor. Standardise the columns and the canyon becomes a bowl — same data, same model, same best fit, a hundred times fewer steps. Then remember the other three: land small and random, judge the model on rows it never saw, and know that the valley you find is the one downhill from where you landed.
Practice arena — twelve problems, solved in full
Twelve problems, easy to hard, covering every picture in the unit: the three repairs on a real column and an unseen value, the imbalance one stride creates, the tailor's bill walked and solved, the round bowl against the canyon, standardisation's effect on the gradient and on the Hessian, the least-squares gradient derived and used, knobs versus facts, a walk into the wrong valley, basins and restarts, and the guns-and-butter canyon opened into a bowl. Every number is machine-verified.
Two habits do most of the work: for any stride question, write the per-direction factors first — is the whole story of stability, oscillation and speed; and for any scaling question, compute the sums of squares of the columns, because the Hessian of least squares is and the feature sizes enter it squared.
A feature column holds the five values . (a) Apply min–max scaling to all five. (b) Standardise the column (subtract the mean, divide by the population standard deviation) and check that the -values sum to and their squares sum to . (c) A new value arrives later. Transform it under both schemes using the training statistics, and say whether the min–max result lies in .
What this tests. Two of the three repairs (standardise, min–max) as plain arithmetic, and the one habit that matters at test time: reuse the training statistics, never recompute them. Plan. Read off min, max and range; then mean, deviations, variance, ; divide; run the two sanity sums; finally push through both formulas with the numbers already on the page.
Show the full solution
(a) . (b) , , ; , . (c) min–max (outside ); .
"Change the units, not the model": both repairs are invertible bookkeeping, and the bookkeeping is done once, on the training column. The slip on this type is recomputing , , , with the new point included — that silently changes every training value too. Min–max is fragile to a new extreme; standardisation degrades gracefully.
At the current iterate a loss has partial derivatives and , and one learning rate serves both knobs. (a) Compute the update to each parameter and the ratio of the two moves. (b) If gradients of this size persist, how many steps does need to move by one unit, and how far does travel in that time? (c) Choose instead so that moves a modest per step; give the new , the new move and the new step count for a one-unit move of . (d) State, in one line, what standardising the two feature columns does to the two partials.
What this tests. The hair-trigger knob in pure arithmetic — one stride length, two wildly different slopes — and the cost of protecting either knob at the other's expense. Plan. twice; divide by the small move; scale down so the big move is and redo the count; then name the repair as a computable claim.
Show the full solution
(a) , , ratio . (b) steps, during which moves units. (c) , , steps. (d) standardising makes the partials comparable, so one fits both.
The stride is the same for every knob; it is the gradient that differs, so the actual move gradient is what you compare. Serve the slow knob and the fast one oscillates; serve the fast knob and the slow one takes steps. No choice of escapes — only changing the units does.
Three receipts: , , model with no intercept. (a) Write the bill for being wrong and expand it to the form . (b) Find by setting the slope to zero, confirm it is a minimum, and compute exactly. (c) Run gradient descent from with for five steps, tabulating , the slope and . (d) Give the per-step factor and the largest for which the iteration converges.
What this tests. The smallest possible training run, done twice — once by formula, once by feel — and the fact that the two agree. Plan. Expand three squares and add; differentiate; solve; evaluate as a fraction with denominator ; fill a five-row table; then read the curvature for the factor and the speed limit .
Show the full solution
| slope | new | |||
|---|---|---|---|---|
| 0 | ||||
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | ||||
| 5 | — |
(a) . (b) , , . (c) ; . (d) factor ; converges for .
For one knob the formula wins; the walk exists because for a billion knobs there is no formula. Keep the table — point, slope, new point, — and check it against the closed form: the gap to must shrink by exactly each row. The slip is evaluating at the new but writing it in the old row.
Two bowls: the circle and the canyon . (a) For the circle, write both gradient-descent updates as multiplications by a constant factor and give the that sends every starting point to in one step. (b) For the canyon, write the two factors, find the range of for which the iteration is stable, and say which coordinate sets it. (c) Trace from for three steps, with at each point. (d) Give the Hessian and the condition number , and the two per-step factors that explain the trace.
What this tests. The canyon problem in its cleanest form — same convexity, same minimiser, and yet one bowl is easy and the other bounces off the walls. Plan. Gradient, factor per coordinate; the one-step is where a factor hits ; stability is for the larger ; then multiply through a table and read the signs of the two factors.
Show the full solution
| point | gradient | new point | ||
|---|---|---|---|---|
| 0 | ||||
| 1 | ||||
| 2 | ||||
| 3 | — | — |
(a) , ; finishes in one step. (b) factors , ; stable for , set by . (c) , , ; . (d) , ; factors and .
Everything about the canyon is in two numbers, the per-direction factors : the largest caps at , a negative factor means zig-zag, and is the difficulty score. Answer "why is the canyon slow?" with the two factors, not with prose.
House price is modelled as from area and bedroom count , with and . (a) Compute and at , and their ratio. (b) Standardise both columns (population ) and recompute both partials at . (c) Give the new ratio.
What this tests. Knobs and units: the feature scale multiplies straight into the gradient, and standardising both columns brings the two partials to the same order of magnitude. Plan. At every prediction is , so each partial is ; compute the two sums; then for each column; redo the two sums with in place of ; divide.
Show the full solution
(a) and , ratio . (b) , ; partials and . (c) ratio .
At the gradient is , so a column's scale multiplies straight into its partial. Quote the before/after ratio — — as the whole result. The slip is using the sample (dividing by ) when the population was asked for; the 's then change by .
Consider . (a) Write the gradient-descent updates as multiplications by constant factors and find the exact range of for convergence, naming the coordinate that sets it. (b) With , trace three steps from ; say which coordinate oscillates and give the threshold of above which it does. (c) Give the Hessian and ; give the that finishes in one step on the equal-curvature bowl , and the two values of that one-step convergence would need simultaneously on .
What this tests. The canyon again with the stiff direction along this time — checking you read the factors from the curvatures and not from habit. Plan. ; factors , ; stability from the larger curvature; multiply through three rows; then and the one-step condition .
Show the full solution
| point | gradient | new point | ||
|---|---|---|---|---|
| 0 | ||||
| 1 | ||||
| 2 | ||||
| 3 | — | — |
(a) , ; , set by . (b) , , ; oscillates (factor ) because ; descends (factor ). (c) , ; finishes in one step; would need and simultaneously.
Three thresholds per direction: smooth, one-step, zig-zag, beyond that blow-up. The largest owns the speed limit, the smallest owns the crawl, and is their ratio. The slip is putting the stiff factor on out of habit — read it from the coefficient.
For the least-squares bill : (a) derive . (b) For , , , , compute and at , take one step with , and compute the new residuals and ; give the fraction of the loss removed.
What this tests. The engine behind every gradient in this unit — residual times feature vector, summed — derived once and then run once. Plan. Name the residual , differentiate the square by the chain rule, note ; then residuals at the origin, two scaled vectors added, one update, two new residuals, compare.
Show the full solution
(a) . (b) , , , , new , ; removed.
"Residual times feature vector, summed" is the whole gradient; restricting the sum to a sample gives the mini-batch version, and Problem 5's arithmetic is this formula at . Watch the sign convention: with the formula is and the minus sign lives in the update; with it moves into the gradient.
Knobs versus facts. Three rows : , , ; the model has five knobs, , and the real-world truth is . (a) For the honest model give the three predictions, the three errors and . (b) The memoriser sets and hits all three rows exactly using : write the three equations, solve them, and give its . (c) Check the candidate : compute its row-1 prediction and its . (d) On an unseen row with true , give both models' predictions and errors. (e) Count unknowns and equations for the full model, and state how many free parameters remain in the set of zero-error solutions.
What this tests. Overfitting as arithmetic: more knobs than facts means zero training error is always available and means nothing. Plan. Honest model first (three subtractions); then a linear system by elimination; then plug the candidate into row 1 and recompute ; then one unseen row through both models; finally the count .
Show the full solution
| row | error | squared | ||
|---|---|---|---|---|
| 1 | ||||
| 2 | ||||
| 3 |
(a) , errors , . (b) , , ; . (c) row 1 gives , so . (d) honest (error ); memoriser (error ). (e) unknowns, equations, free parameters — infinitely many zero-error solutions.
More knobs than facts zero training error is available zero training error means nothing; judge on a row the model has not seen. Solve the small system honestly — a plausible-looking triple like is one row-1 check away from being exposed. Regularisation later makes the memoriser (weights ) expensive and the honest model (weight ) cheap.
Let . (a) Find in factored and expanded form, and all stationary points. (b) Classify them with and give at each. (c) Run gradient descent from with for four steps, tabulating , and ; state the limit and which starting points end there. (d) On a plateau where , with , give the step length and the number of steps to cross a plateau of width .
What this tests. One knob, two valleys: the walk converges beautifully into the wrong one and never gets a hint the other exists; plus the salt-flat arithmetic. Plan. Product rule, pull out , quadratic formula; at three points; four table rows with the expanded ; then step and divide the width by it.
Show the full solution
| new | ||||
|---|---|---|---|---|
| 0 | ||||
| 1 | ||||
| 2 | ||||
| 3 | ||||
| 4 | — | — |
(a) ; stationary at , , . (b) (min, ), (max, ), (min, ). (c) ; ; limit , , for every start below . (d) step ; steps.
The watershed is the local maximum between the valleys; which side of it the parachute lands decides everything, and the walk itself carries no information about the other valley. The plateau arithmetic is the same deceleration seen at a true minimum, happening far from one. The slip is calling the deeper valley "the answer" — descent from never sees it.
For , small-step gradient descent converges to the local minimum at from any start and to the global minimum at from any start ; the watershed sits at . Verify these three facts from and the values , , . The start is drawn uniformly from . (a) Compute the probability that a single run finds the global minimum. (b) With independent restarts (keep the best), find the smallest for which the global minimum is found with probability at least , and give that probability. (c) If a separable ten-dimensional objective has this landscape in every coordinate (per-coordinate success , independent), compute the chance that one run lands in the global basin of all ten coordinates at once.
What this tests. Basins as lengths, restarts as "at least one success", and the combination lock: probabilities multiply across coordinates just as basins do. Plan. Factor and evaluate at the three roots; favourable length over total length; with powers computed exactly; then .
Show the full solution
; , , . (a) . (b) fails, works: , success . (c) .
"At least one success in tries" is ; compute the powers precisely, because these numbers are built so that barely fails. Basins multiply across coordinates, so probabilities multiply too — restarts rescue one dial, not a lock with ten.
Guns and butter: , , , model , . (a) Write out, compute the Hessian , its eigenvalues, and the speed limit . (b) Standardise both columns (population ), recompute the three sums, , its eigenvalues, and . (c) Give the improvement factors in and in the admissible stride, and compute the correlation coefficient of the two columns that explains why is and not .
What this tests. Bad scaling and bad curvature meeting: feature scales enter the Hessian squared, standardising forces both diagonals to , and what is left over is correlation. Plan. Three sums, double them; eigenvalues from the formula; then per column, the three sums again, eigenvalues; divide before by after; finally .
Show the full solution
(a) ; ; ; . (b) , ; sums ; ; ; ; . (c) in , in stride; .
Standardising forces every diagonal of to ; whatever survives is correlation, read off the off-diagonal. Two handy facts: eigenvalues of are , and for general symmetric use mean half-difference-and-. The slip is forgetting the factor in and so in .
A linear model is trained on and , with and Hessian . (a) Compute , its eigenvalues (use ), the largest stable stride and . (b) Min–max normalise both columns, recompute , its eigenvalues, and . (c) By what factor did the admissible stride improve?
What this tests. The grand synthesis: a gap in feature scale becomes a gap in curvature, which caps the stride at ; min–max scaling buys it back. Plan. Three sums, double them; because the off-diagonal is tiny in comparison, from the determinant; then scale, three new sums, ; divide the two strides.
Show the full solution
(a) ; , ; ; . (b) , ; ; ; ; . (c) .
Feature scales enter squared, so a scale gap is a curvature gap and a speed limit. Scaling is not cosmetic; it is a computable – speed-up. For a nearly diagonal , the big diagonal entry and — never read off the small diagonal entry (, not ).