In Unit 9 you learned the walk: feel which way is downhill, then take a step. This unit is about how that walk goes wrong, and how to fix it. You can start in a bad place.You can score full marks by memorising and learn nothing. You can settle in the wrong valley, or shuffle for hours across flat ground. And most often the valley is a narrow canyon, so every step bounces off the walls. The good news: one cheap trick fixes most of it. Change the units of the data, not the model, and the canyon becomes a bowl. Watch it happen above.
≈ 90 min read + play11 interactive widgets · 5 in 3D · a trench that opens into a bowl under your finger15 inline checks🧾 16 proofs, folded away — open "if you want the algebra" when you are ready✍ 12 solved practice problems
drag the landscape to orbit
1
The bill for being wrong — and why the squares are squares
Imagine this
Your local tailor uses one rule of thumb for sleeves: sleeve length = w × arm length. He picks a number for w and cuts three sleeves. Each one comes out a little too long or a little too short.
Now a strange rule. For every miss, he must buy a square patch of cloth whose side is the size of the miss. Miss by 1 cm: a 1 cm² patch. Miss by 3 cm: a 9 cm² patch.
His bill is the total area of the patches. His job is to find the w that makes the bill as small as possible. Keep this picture: the formula below is exactly this sentence.
Every model makes guesses. Every guess misses the truth by some amount. We need one number that says how bad all the misses are, taken together. We call it the bill. Mathematicians call it the loss and write it J.
The most common bill is the tailor's: square each miss, then add them up. Squares are a good choice for three plain reasons:
①Short or long costs the same.(−3)2=32=9.
②One big miss hurts more than many small ones. One miss of 3 costs 9. Three misses of 1 cost only 3.
③Squares are smooth. So "which way is downhill" is easy to work out.
A tiny example. Three customers have arms of length 1, 2 and 3. They need sleeves of 2, 5 and 7. Start with w=0, so every sleeve is 0. The misses are −2,−5,−7, and the bill is 4+25+49=78.
Write the bill for any w and it tidies up into one curve:
J(w)=(w−2)2+(2w−5)2+(3w−7)2=14w2−66w+78.
It is a U-shaped curve. Its lowest point is at w∗=33/14≈2.357 (read w∗ as "w-star, the best w"). There the bill is 3/14≈0.214. It is not zero, because no line of the form y=wx passes through all three points.
Which way is downhill? The slope of the bill is dJ/dw=28w−66 (read it: "how fast the bill changes when you nudge w"). At w=0 it is −66. Negative slope means: raise w and the bill falls.
Now look where the −66 comes from. Each customer pushes with "2 × my miss × my arm length": 2[(−2)(1)+(−5)(2)+(−7)(3)]=2(−33)=−66. That pattern works for one knob or a billion. Each row of data pushes the knobs along its own row, in proportion to its miss. Add the pushes and you get the gradient, ∇J (read it: "grad J", the list of slopes, one per knob):
∇J=2i∑missiXi,missi=w⊤Xi−yi.
Then comes the walk from Unit 9: step against the slope, w←w−η×slope. Here η (read "eta") is your stride. With η=0.02 the knob goes 0→1.32→1.90→2.16, and the bill falls 78→15.3→3.1→0.8.
Each step shrinks the gap to the best w by the same factor, 1−28η=0.44. Push η above 1/14≈0.071 and that factor drops below −1. Then every step overshoots by more than it gains, and the patches grow. Remember this limit. The whole unit is about what sets it.
The tailor's patchesThree customers, one knob w — and the bill as what it really is: the total area of three cloth patches. Drag to orbit.
Try: drag w towards 2.36 and watch all three patches shrink. Press ▶ descend: the rod swings in hops and the bill falls 78→15.3→3.1→0.8. Then push η past 0.0714 and press ▶ again: the patches grow.
drag the picture to orbit
—
J(w)=14w2−66w+78 has slope 28w−66, zero at w∗=33/14. Each step multiplies the gap to w∗ by 1−28η, so the walk settles only while η<1/14.
The realization
The bill is the total area of the patches: J=∑imissi2. Its slope is every row's push, added up: ∇J=2∑imissiXi.
A row that guessed too high pushes the knobs down along itself. A row that guessed too low pushes them up. A bigger miss pushes harder.
Pause & predict
Right now (w=0) every sleeve is too short: the misses are −2, −5 and −7. Which way should the knob w move?
If you want the algebra · 2 proofs, step by step
Prove it · the gradient of the least-squares bill
Claim. For J(w)=∑i(w⊤Xi−yi)2, ∇J=2∑i(w⊤Xi−yi)Xi.
1
Name each miss: ri=w⊤Xi−yi. Then J=∑iri2.
A sum of squares of something simple is the easiest shape to differentiate.
2
The miss is linear in w: ∇wri=Xi.
ri⇒∂wj∂ri=j∑wjxij−yi=xij.Knob j touches row i only through the product wjxij; its derivative is the feature value.
3
Chain rule on one square, then add the rows:
∇ri2∇J=2ri∇ri=2riXi,=2i∑riXi.∎Read it: every row pulls the knobs along its own feature vector, in proportion to its miss. With ri=y^i−yi the sign is + and the minus sign lives in the update w←w−η∇J.
Prove it · the tailor's bill has its bottom at w∗=33/14
Claim. For x=(1,2,3), y=(2,5,7) and y^=wx: J(w)=14w2−66w+78, w∗=33/14≈2.357, J∗=3/14≈0.214, and the per-step factor at stride η is 1−28η.
1
Expand the three squares and add:
(w−2)2(2w−5)2(3w−7)2J=w2−4w+4=4w2−20w+25=9w2−42w+49=14w2−66w+78.The coefficient 14=∑xi2 is the column's size squared — the stiffness of this one knob.
2
Set the slope to zero: J′(w)=28w−66=0⇒w∗=66/28=33/14. And J′′=28>0: a valley.
One knob, one parabola, one bottom.
3
The bill at the bottom:
J∗=14214⋅332−1466⋅33+78=141089−2178+1092=143.Not zero: three points do not lie on one line through the origin, and 3/14 is the area the best line cannot remove.
4
One step of descent: w−η(28w−66)=w∗+(1−28η)(w−w∗), since 28w−66=28(w−w∗).
∎The gap to the bottom is multiplied by 1−28η each step: 0.44 at η=0.02, and the walk diverges once 28η>2, i.e. η>1/14.
In one sentence: the bill is the total area of one square patch per data row, and its slope is each row's miss times that row, added up — the same recipe for one knob or a billion.
2
The parachute drop — where you start
Imagine this
You check into a hotel and step into the shower. The tap is very touchy. The water is too cold, so you turn the tap a bit. Now it is boiling, and further from comfortable than before. You turn it back a bit. Now it is icy, and further off again.
Every correction makes things worse. Would it help to start with the tap somewhere else? No. The problem is how touchy the tap is, not where it started.
And a second story. You hire two new cooks. You give them the same station, the same first dish and the same feedback every day. They will cook exactly the same thing, forever. You paid for two cooks and got one.
Before the walk can begin, someone must choose where it starts: the first values of the knobs. Two things can go wrong, and they are the two stories above.
Problem 1: the numbers blow up. Take one feature x=200, a target y=7, a start w0=1 and a small-looking stride η=0.001. The first guess is y^=w0x=200, a miss of 193.
Follow the miss from step to step. Each step multiplies it by the same number:
new miss=(1−2ηx2)×old miss.
Here 2ηx2=2×0.001×40000=80, so the factor is 1−80=−79. The miss goes 193→−15247→1204513→⋯, flipping sign and growing 79 times each step. That is the touchy shower tap, in numbers.
After 163 steps the number passes 1.8×10308, the largest a computer can store (in the usual "float64" format). It becomes ∞, then ∞−∞, which is NaN: "not a number". The run is dead.
Now notice what is not in the factor: the start w0. Changing the start changes nothing. The culprit is the feature's size, squared. The only safe stride is below 1/x2=2.5×10−5, or you must shrink x itself (Sections 4, 5 and 10 show how).
So the advice for the start is modest: pick small numbers, in [−1,1] (or [0,1] if the knobs must stay positive). A small start does not prevent a blow-up. It just does not add to one.
Problem 2: clones. Two knobs that play the same role, started at the same value, feel the same tilt at every step. So they stay equal forever, like the two cooks. The fix is to start them at random values. Randomness costs nothing, and it is the only thing that lets identical knobs become different.
The parachute dropWhere you are dropped decides everything — a start that blows the numbers up, and two clones that can never become different
Try: Press ▶ and watch each bar grow 79 times taller, until the computer runs out of numbers. Then slide log₁₀ η below −4.6: the same start now settles down.
—
Each step multiplies the miss by 1−2ηx2. The start is not in that factor; the size of x is.
The realization
Start small, centred and random: small so the first step stays on the map, random so no two knobs are clones.
And when the numbers explode anyway, look at the factor 1−2ηx2. It is the size of the data, not your start, that needs fixing.
Pause & predict
With x=200 and η=0.001, every start blows up. You halve the start to w0=0.5. What happens?
If you want the algebra · 1 proof, step by step
Prove it · why the start is not the culprit
Claim. For the one-feature bill (wx−y)2, gradient descent multiplies the error wx−y by 1−2ηx2 every step, whatever w0 is; it converges iff η<1/x2.
1
The gradient is 2x(wx−y), so the update is w←w−2ηx(wx−y).
Chain rule on one square: outer 2(wx−y), inner x.
2
Multiply by x and subtract y to follow the error e=wx−y:
enew=(w−2ηxe)x−y=e−2ηx2e=(1−2ηx2)e.The error obeys a one-line rule with a constant factor. w0 only sets e0; the factor is x and η alone.
3
Convergence needs ∣1−2ηx2∣<1, i.e. 0<η<1/x2. With x=200: η<2.5×10−5; at η=10−3 the factor is −79.
∎79k∣e0∣ passes 1.8×10308 (the largest float64) at k=163 for e0≈193: overflow, then ∞−∞=NaN. Halving w0 delays this by ln2/ln79≈0.16 of a step.
In one sentence: start small and random — and when the numbers explode anyway, blame the feature's size squared in the factor 1−2ηx2, not the place you started.
3
Full marks by memorising — knobs versus facts
Imagine this
Two students prepare for a maths test. Meera learns how to solve the problems. Arjun memorises last year's answer key.
By chance, this year's test repeats last year's three questions. Arjun scores 100. Meera scores 96. On paper, Arjun is better.
Next week a new question arrives. Meera works it out. Arjun writes down an answer from the key, and it has nothing to do with the question. A score on questions you have already seen tells you nothing about learning.
A model can do exactly what Arjun did. The lecture's data has three rows and four features, x1 to x4. The truth is simple: y≈x1.
row
x1
x2
x3
x4
true y
1
61
2
3
0.1
59
2
40
0
4
0.5
40
3
68
0
10
1
70
The model has five knobs: one weight per feature, w1 to w4, plus a constant w5.
The learner sets w1=1 and the rest to 0. It says y^=x1 (read y^ as "y-hat, the guess"). Its misses are 2,0,−2, so its bill is 4+0+4=8.
The memoriser ignores x1 completely. It uses y^=12x2+5x3+20. Check row 1: 24+15+20=59. Row 2: 0+20+20=40. Row 3: 0+50+20=70. Every row is hit exactly, so its bill is 0.
Ask any optimiser for "the smallest bill", and it will pick the memoriser without a second thought.
Now try a new row it has never seen: x1=50, x2=1, x3=6, x4=0.3. The truth is about 50. The learner says 50. The memoriser says 12+30+20=62, off by 12. And if you change x1, the memoriser does not even notice: x1 is not in its formula.
How was a zero bill even possible? Count. Five knobs, only three facts. Three equations with five unknowns have endlessly many exact solutions. It is like being told "two numbers add up to 10": you cannot tell which two.
So the data never pinned the knobs down. The optimiser handed back one of the many exact fits, with no way to know which one means something. The learner's bill of 8 is not a failure. It is the size of the noise in the three rows. Chasing that 8 down to 0 is where learning turned into memorising.
Full marks by memorisingFive knobs, three facts: one model learns the rule, the other memorises the rows — and only the unseen row can tell them apart
Try: Switch to the memoriser: it hits all three training dots exactly. Now drag the unseen row: the truth moves, but the memoriser stays stuck at 62.
—
Three rows, five knobs: two knobs are left free, so an exact fit costs nothing. Only a row the model has never seen can tell learning from memorising.
The realization
More knobs than facts means a zero training bill is free, so a zero training bill means nothing. Judge a model on rows it has never seen.
Later units add a small charge for big knobs (a regulariser). Then "fits the data with small knobs" beats "fits the data with any knobs", and the learner wins.
Errata — check this against your slides
The deck quotes the memorising solution as w2=7,w3=5,w5=20. Check row 1: 7⋅2+5⋅3+20=49, but y1=59. Solving the three equations properly gives w3=5,w5=20,w2=12 (the drawer below and Practice Problem 8 do it line by line). The lesson is untouched; only the arithmetic needed a nudge.
Pause & predict
A model has 8 knobs. You train it on 6 rows, and the training bill comes out exactly 0. How pleased should you be?
Pause & predict
You drag the unseen row from x1=50 to x1=70 (the truth is now about 70). What do the two models predict?
If you want the algebra · 2 proofs, step by step
Prove it · the memoriser, solved (and the slide's slip)
Claim. With w1=w4=0, the three rows are hit exactly by w3=5,w5=20,w2=12; the slide's w2=7 does not hit row 1.
1
Write the three rows as equations in w2,w3,w5:
2w2+3w3+w54w3+w510w3+w5=59=40=70.Rows 2 and 3 have x2=0, so w2 drops out of them — two equations in two unknowns.
2
Subtract row 2 from row 3: 6w3=30⇒w3=5. Back into row 2: 20+w5=40⇒w5=20.
Elimination, exactly as in Unit 1.
3
Into row 1: 2w2+15+20=59⇒w2=12. Check the slide's triple: 7⋅2+5⋅3+20=49=59.
∎On the unseen row (50,1,6,0.3) the memoriser says 12+30+20=62 whatever x1 is; the truth is about 50.
Prove it · more knobs than facts ⇒ a zero bill is free
Claim. If a linear model has d knobs and n<d training rows whose feature vectors are independent, there are infinitely many w with J(w)=0.
1
J=0 means every miss is zero: Xw=y, a system of n equations in d unknowns, X being n×d.
A sum of squares is zero only when every square is.
2
With independent rows, rankX=n, so Xw=y is consistent and its solution set is a particular solution plus the null space, of dimension d−n≥1.
Unit 1's rank–nullity: d−n free parameters, hence a whole line, plane, … of exact fits.
3
Every point of that set has a zero bill, so an optimiser told only "minimise J" cannot prefer one; which it returns depends on the start and the walk, not on the truth.
∎The lecture's case: d=5, n=3, two free knobs. A penalty λ∑jwj2 breaks the tie in favour of small knobs — the honest model here has a single knob equal to 1.
In one sentence: with more knobs than facts a zero bill is free and so means nothing — the memoriser hits every training row and still cannot see the one feature that matters.
4
The hair-trigger and the stiff knob
Imagine this
You are filling two buckets from two taps. But both taps are on one handle: every turn opens both by the same amount.
Tap A is a fire hose. A tiny turn floods the floor. Tap B is a slow drip. Turn gently to keep A under control, and B's bucket takes all day. Turn hard to fill B, and A sprays everywhere.
No single turn suits both taps. The problem is not your hand. It is that the two taps have very different pressures.
Gradient descent has exactly one handle: the stride η. Every knob gets the same stride. But the knobs can have very different "pressures".
The lecture's model predicts wealth from age x1 and years of college x2:
y=w1x12+w2x22.
How much does the guess change when you nudge a knob? For w1 it changes by x12. For w2 it changes by x22. That is each knob's sensitivity, its pressure. Mathematicians write it ∂y/∂w1 (read: "how fast y changes when only w1 moves").
A tiny example. Take a typical person: age x1=50, college x2=4. The sensitivities are 502=2500 and 42=16. So the age knob is 2500/16≈156 times touchier than the college knob.
With a stride of η=10−5, one unit of miss moves the age knob by 0.025 and the college knob by only 0.00016. The college knob needs about 6,250 steps to move one unit. The age knob gets there in 40.
Try to fix it with the stride alone. Protect the age knob, and the college knob crawls. Serve the college knob, and the age knob overshoots and swings. No stride suits both, because the problem is not the stride. It is the size of the features: age goes up to 100, college only up to 10, and the bill feels those sizes squared.
The only real fix is to make the two features the same size. That is the next section.
The hair-trigger and the stiff knobOne stride η for two knobs whose sensitivities differ 156-fold: serve one and the other overshoots or crawls
Try: Press serve the stiff knob, then ▶: the age needle swings past its mark. Now press protect the hair-trigger: the college needle barely moves in 8 steps.
—
The age knob is x12/x22 times touchier than the college knob, yet both get the same stride. Only making the features the same size fixes it.
The realization
A knob's sensitivity is its feature's size, squared: ∂y/∂wj=xj2. One stride moves knob j by ηxj2×∣miss∣.
So features of different sizes make one knob overshoot while another crawls. No stride can serve both. Rescaling the features is the fix.
Pause & predict
This step, the slopes are ∂J/∂w1=−640 and ∂J/∂w2=−1.6. One stride γ=10−3 serves both. How far does each knob move? And about how many steps does w2 need to move one unit?
If you want the algebra · 1 proof, step by step
Prove it · the two knobs move x12/x22 times differently
Claim. For y=w1x12+w2x22 and a squared-error bill, one stride η moves w1 by ηx12∣r∣ and w2 by ηx22∣r∣ per row — a ratio of x12/x22 (156 at x1=50,x2=4).
1
Sensitivities of the prediction: ∂y/∂w1=x12, ∂y/∂w2=x22.
Each knob multiplies its own feature-squared; the derivative is that feature-squared.
2
For the bill 21(y−t)2 with miss r=y−t: ∂J/∂w1=rx12, ∂J/∂w2=rx22 (chain rule).
The same miss multiplies both; only the feature-squared differs.
3
The update moves wj by η∣r∣xj2. Ratio: x12/x22=2500/16=156.25.
∎A stride that moves w1 by 0.01 moves w2 by 0.000064 per unit miss; a stride that moves w2 by 0.01 moves w1 by 1.56. No single η is sane for both.
In one sentence: a knob's sensitivity is its feature's size squared, so features of different sizes turn one stride into a fire hose on one knob and a drip on the other — and only rescaling the features can fix it.
5
Three ways to fix the units — centre, standardise, min–max
Imagine this
You scored 80 out of 100 in the maths test and 9 out of 10 in a weekly quiz. Which did you do better on?
You cannot compare 80 with 9 directly. So you ask a better question: how far above the class average am I, measured in "typical gaps"?
Maths: class average 60, typical gap 10. You are (80−60)/10=2 gaps above. Quiz: class average 8, typical gap 0.5. You are (9−8)/0.5=2 gaps above. Equally good. You just put both marks on the same scale.
That is exactly how we fix the features. We re-measure each column so that all columns are the same size. Nothing about the data's meaning changes; only its units do. There are three common ways.
Repair
In everyday words
In symbols
Centre
"Above or below average?" Subtract the column's average. The cloud of points slides onto the origin; its shape stays the same.
x−μ
Standardise
"How many typical gaps from average?" Subtract the average, then divide by the spread. Every column now has spread 1.
z=σx−μ
Min–max
"What fraction of the way from lowest to highest?" Every column is squeezed into a box from 0 to 1.
max−minx−min
Here μ (read "mu") is the column's average, and σ (read "sigma") is its spread, the standard deviation: the typical gap from the average.
A tiny example. A column holds 30,50,70,90,110. Its average is μ=70 and its spread is σ≈28.28. Standardised, the values become −1.414,−0.707,0,0.707,1.414. Min–max turns them into 0,0.25,0.5,0.75,1.
One firm rule. A new value must be treated with the training numbers. Say 130 arrives later. Standardise it with the old μ and σ: z=(130−70)/28.28≈2.12. Min–max it with the old min and max: (130−30)/80=1.25, outside the box. Never recompute the average with the new value included. That quietly leaks test data into training.
Which to use? Standardising is the usual default before gradient descent. Min–max is simple and bounded, but one wild value (an outlier) sets the box and squashes everyone else into a corner. Try the outlier cloud below.
Three ways to fix the unitsCentre, standardise, or squash into a box — watch the cloud move, and what happens to a value the training set never saw
Try: Click standardise: the long smear becomes a round blob. Then pick cloud + one outlier and click min–max: one point grabs the corner and squashes the rest.
—
Every repair uses the training average, spread, min and max, and new data must use the same numbers. After standardising, one unit means "one typical gap" in every column.
The realization
Rescaling changes the units, not the meaning. After standardising, every column has average 0 and ∑izi2=n, so every column is the same size and one stride can serve every knob.
What rescaling does not fix: two columns that rise and fall together. That leftover comes back in Section 10.
Pause & predict
A training column has average μ=40, spread σ=8, smallest value 20 and largest 60. A new value x=72 arrives. What do standardising and min–max give?
If you want the algebra · 1 proof, step by step
Prove it · a standardised column has mean 0 and ∑z2=n
Claim. For zi=(xi−μ)/σ with μ=n1∑xi and σ2=n1∑(xi−μ)2: ∑izi=0 and ∑izi2=n.
1
∑i(xi−μ)=∑ixi−nμ=nμ−nμ=0, so ∑izi=0.
Subtracting the mean makes the deviations cancel exactly.
2
∑izi2=σ21∑i(xi−μ)2=σ2nσ2=n.
∎This is why, after standardising, every diagonal of 2Z⊤Z is the same 2n: every column is now the same size. On the practice column (30,…,110): z=(−1.414,−0.707,0,0.707,1.414), sum 0, sum of squares 5.
In one sentence: centring slides, standardising squeezes, min–max boxes — all three put every column on the same scale, and all three treat new data with the training numbers.
6
The wrong valley — the watershed and the combination lock
Imagine this
Monsoon rain falls on the Western Ghats. A drop that lands just west of the crest flows down to the Arabian Sea. A drop that lands a few metres east travels hundreds of kilometres to the Bay of Bengal.
Where each drop ends up was decided the moment it landed, by which side of the crest it hit. The crest is called the watershed. Once a drop starts rolling, it never climbs back over.
Gradient descent is a raindrop. It only ever rolls downhill from wherever it starts.
So far our bills have had one valley. Real bills can have several. The lecture's curve is
F(x)=(x−1)2((x−3)2−1).
It has a shallow valley at x=1 (height 0) and a deep valley at x≈3.37 (height ≈−4.85). Between them is a small hilltop, the watershed, at x≈1.63.
A walker that starts left of 1.63 rolls into the shallow valley and stops. It reports "done", with a valley almost five units deeper right next door. It never had a clue.
A tiny example. Drop marbles evenly between 0 and 4. The share that lands right of the watershed is (4−1.634)/4≈0.59. So about 59 % reach the deep valley. The walk did not choose that number. The drop zone did.
The obvious fix: restart a few times and keep the best. Each drop misses the deep valley with chance 0.41. Six drops all miss with chance 0.416≈0.005. So six restarts succeed more than 99 % of the time. On a line, this works.
With many knobs, it stops working. Think of a combination lock. Suppose each knob, on its own, has 3 dips to settle in. With 10 knobs there is a dip for every combination: 310=59,049 of them. Only one is the true bottom.
Now suppose each knob lands in its best dip with chance 0.6. A single run must be lucky on all ten at once: 0.610≈0.006, about one run in 165. Restarts alone cannot search that. (Large neural networks are kinder than this worst case: most of their valleys turn out to be about equally good.)
The marble rain and the combination lockRain on a ridge: every marble rolls downhill into one of two lakes, and the side of the watershed it lands on decides which. Then a combination lock shows how the valleys multiply. Drag to orbit.
Try: press ▶ drop the marbles. The rain splits at the watershed x=1.634, and about 59% reach the deep lake. Then open the lock tab and set 10 dials: the chance of opening it in one go is 0.610≈0.006.
drag the picture to orbit
—
A marble only rolls downhill, so it never climbs the watershed: the start alone picks the lake. With d knobs of k dips each there are kd dips, far too many for restarts to search.
The realization
Descent finds the valley downhill from where it starts, and the watershed decides which one. Restarts give k chances: all fail with probability (1−p)k.
With d knobs of k dips each, the dips multiply to kd, and the chance of being right on every knob shrinks to pd.
Pause & predict
Marbles are dropped evenly on [0,4]. The watershed is at x=1.634. What share reaches the deep valley? And how many drops give a 99% chance of at least one success?
Pause & predict
A bill splits into 10 separate one-knob pieces. Each piece has 3 dips, and one of them is its best. A random start lands in each knob's best dip with chance 0.6. How many dips does the whole bill have? And what is the chance that one run lands in the best dip of every knob?
If you want the algebra · 3 proofs, step by step
Prove it · the lecture's curve has a watershed at (5−3)/2
Claim.F(x)=(x−1)2((x−3)2−1) is flat at x=1, 1.634, 3.366: valley (F=0), hilltop (F=0.348), valley (F=−4.848).
1
Product rule with u=(x−1)2, v=(x−3)2−1:
F′=2(x−1)v+(x−1)2⋅2(x−3)=2(x−1)[(x−3)2−1+(x−1)(x−3)].Pull out the common 2(x−1) first; it hands you the root x=1 for free.
2
Simplify the bracket: (x2−6x+8)+(x2−4x+3)=2x2−10x+11. So F′=2(x−1)(2x2−10x+11)=4x3−24x2+42x−22.
Two quadratics added; nothing cancels except the arithmetic.
3
2x2−10x+11=0⇒x=410±100−88=25±3=1.634,3.366.
The discriminant 12=4⋅3 is what makes 3 appear.
4
F′′=12x2−48x+42: F′′(1)=6>0, F′′(1.634)=−4.39<0, F′′(3.366)=16.39>0. Heights F(1)=0, F(1.634)=0.348, F(3.366)=−4.848.
∎Valley, hilltop, valley. A downhill walker from x0<1.634 ends at F=0 with F=−4.848 next door.
Prove it · the combination lock — ∏ki local minima
Claim. If F(x1,…,xd)=A1(x1)+⋯+Ad(xd) and Ai has ki local minima, then F has ∏iki local minima.
1
∂F/∂xi=Ai′(xi): every other term is a constant as far as xi is concerned.
Separable means each knob sees only its own piece.
2
So ∇F=0 exactly when every Ai′(xi∗)=0, and F curls up in every direction exactly when every Ai′′(xi∗)>0 (the Hessian is diagonal with entries Ai′′).
A local minimum of F is a choice of a local minimum of each piece, independently.
3
Independent choices multiply: k1k2⋯kd. With k=3, d=10: 59,049; d=50: 350≈7×1023.
∎Only one combination is the global bottom; a random start lands in it with probability ∏pi (0.610≈0.006).
Prove it · how many restarts
Claim. If one run finds the global valley with probability p, k independent runs (keep the best) succeed with probability 1−(1−p)k; for p=0.6 and a 99% target, k=6.
1
All k fail with probability (1−p)k (independence); at least one succeeds otherwise.
"At least one" is always easiest through its complement.
2
Require 0.4k≤0.01: 0.45=0.01024 (just fails), 0.46=0.004096 (works). So k=6, success 0.9959.
∎Compute the powers exactly; k=5 misses by a hair. In general k=⌈ln0.01/ln(1−p)⌉.
In one sentence: the side of the watershed you start on decides the valley you reach, and with many knobs the valleys multiply like the settings of a combination lock — so restarts alone cannot save you.
7
The salt flat — where the walk slows to nothing
Imagine this
You are walking in the Rann of Kutch at night, in thick fog. You want to reach the lowest point, and your only guide is the slope under your feet. Your rule: the steeper the ground, the bigger your step.
Coming down the rocky edge, the slope is steep, so you take big strides. Then you step onto the white salt flat. It is almost perfectly level. Your feet feel almost no slope, so your steps become tiny.
You are not at the bottom. You are just on flat ground, and you shuffle across it for hours.
A flat stretch of the bill, far from any valley, is called a plateau. On a plateau, gradient descent slows to a crawl for a simple reason. Each step is stride × tilt. Small tilt, small step.
A tiny example. The tilt is 0.001 and the stride is 0.01. Each step moves 0.01×0.001=10−5. A flat stretch two units wide takes 2/10−5=200,000 steps. That can be hours of computing, spent getting nowhere.
In symbols: crossing a flat of width W where the tilt is about g takes roughly W/(γg) steps (γ, read "gamma", is the stride).
Unit 9 showed the same slowing near the bottom of a valley. There it is welcome: you are where you want to be. On a plateau it is a trap. The walker slows down for the same reason, in a place that deserves no slowing.
The salt flatA cliff, a nearly level shelf, then a bowl — the walker races down the cliff and then shuffles for two hundred steps where the ground is flat. Drag to orbit.
Try: Press ▶ from the cliff. The footprints are far apart on the slope, then pile up into a bright band on the flat, where every step is tiny.
drag the picture to orbit
—
Step = stride × tilt. On the flat the tilt is tiny, so the walker is slow — not finished.
The realization
Step length is stride × tilt: γ∣∇f∣. Small tilt means small steps, whether or not you are near a valley. A flat of width W and tilt g costs about W/(γg) steps.
The cure comes next unit: momentum, which keeps rolling across the flat instead of deciding every footstep afresh.
Pause & predict
For 500 steps the bill has barely moved: 6.00,5.99,5.99,5.98,… Which conclusion is wrong?
If you want the algebra · 1 proof, step by step
Prove it · steps to cross a plateau
Claim. Crossing a flat of width W where the tilt is about g takes roughly W/(γg) steps — 200,000 for W=2, g=0.001, γ=0.01.
1
Each step moves γ∣∇f∣≈γg along the flat.
The update is −γ∇f; on a plateau the direction barely changes and the size is γg.
2
Steps =W/(γg)=2/(0.01⋅0.001)=2×105.
∎Near a true minimum the same slowing is harmless (you are where you want to be); on a plateau it is pure waste. Momentum, next unit, is the cure.
In one sentence: each step is stride times tilt, so a plateau — small tilt, but no valley — can swallow hundreds of thousands of steps.
8
The canyon — why the fastest way down is the wrong way down
Imagine this
Drop a marble into a long, narrow rain gutter that tilts gently toward one end.
Does it roll neatly along to the end? No. The sides of the gutter are much steeper than its length. So the marble rocks from wall to wall, and only slowly drifts along.
Every movement is downhill. Most of them go sideways.
That gutter is the most common shape of a bill in machine learning. We call it a canyon: steep across, gentle along. The simplest one is
L(x,y)=x2+cy2.
The number c says how much steeper the walls are than the floor. With c=1 you get a round bowl. With c=4, the walls are four times steeper.
Each direction behaves on its own. One step of descent multiplies each coordinate by its own factor:
x←(1−2η)x,y←(1−2cη)y.
A tiny example. Take c=4, η=0.24, and start at (10,10). The factors are 1−0.48=0.52 for x and 1−1.92=−0.92 for y. After one step you are at (5.2,−9.2). Then (2.70,8.46), then (1.41,−7.79).
Look at y. The minus sign flips it to the other wall every step, and it shrinks only 8 % each time. Meanwhile x halves every step. After six steps x is about 0.2, nearly solved, while y is still about 6. That bouncing is the zig-zag.
Why not pick a better stride? The steep wall only stays under control while ∣1−2cη∣<1, that is η<1/c. Go past that and y blows up. But at that limit, the floor factor is 1−2/c. For a very steep wall, that is close to 1: the floor crawls.
Serve the wall and the floor crawls. Serve the floor and the wall blows up. This is the one-handle tap from Section 4 again, drawn as a landscape.
Naming the pieces. The steepness of the bill along a direction is its curvature, written λ (read "lambda"). Here λ=2 along the floor and λ=2c across the walls. The steepest direction sets the speed limit, η<2/λmax. And the ratio of steepest to gentlest,
κ=λminλmax(read "kappa"),
is the condition number. It says how badly the floor crawls at the speed limit. κ=1 is a round bowl, where one step of η=0.5 lands exactly on the bottom. A big κ is a canyon and a long zig-zag.
The canyonL = x² + c·y² — the stiffer the y-wall, the further the gradient points from the bottom, and the walker bounces off the walls. Drag to orbit.
Try: Press ▶ at c=4, η=0.24: y flips to the other wall every step while x creeps in. Then set c=1 and η=0.5: one step lands on the bottom.
drag the picture to orbit
—
Each direction has its own factor: 1−2η along the floor, 1−2cη across the walls. The steep wall sets the limit η<1/c.
The realization
Each direction shrinks by its own factor, 1−ηλ. The steepest direction sets the speed limit, η<2/λmax. At that limit the gentlest direction crawls, and κ=λmax/λmin measures how badly.
Steepest descent is the best direction for this one step, never the best direction for the whole trip.
Pause & predict
On L=x2+4y2 with η=0.24, you start at (10,10). Where are you after one step, and which coordinate misbehaves?
Pause & predict
For L=x2+9y2, 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
Prove it · each direction shrinks by its own factor; the stiffest sets the limit
Claim. On L=x2+cy2, gradient descent gives xk+1=(1−2η)xk, yk+1=(1−2cη)yk; it converges iff η<1/c (for c≥1), and the y-coordinate bounces (sign flips) once η>1/(2c).
1
∇L=(2x,2cy), so x←x−2ηx, y←y−2cηy.
The bowl has no cross term, so the two coordinates never talk to each other: two one-dimensional problems.
2
Each is a geometric sequence: xk=(1−2η)kx0, yk=(1−2cη)ky0. Convergence needs ∣1−2η∣<1 and ∣1−2cη∣<1, i.e. η<1 and η<1/c.
The stiffer direction's condition is the tighter one: η<1/c=2/λmax with λmax=2c.
3
For 1/(2c)<η<1/c the y-factor is negative: y overshoots the floor every step. At c=4, η=0.24: factors 0.52 and −0.92; from (10,10): (5.2,−9.2), (2.70,8.46), (1.41,−7.79).
∎At the cap η→1/c the floor factor is 1−2/c: for c=4, 0.5 — fine; for c=1487, 0.9987 — the crawl of Section 10.
Prove it · the one-step finish on a round bowl, and why a canyon has none
Claim. On L=x2+y2, η=1/2 sends every point to the origin in one step; on L=x2+cy2 with c=1 no single η does.
1
Round bowl: both factors are 1−2η; at η=1/2 both are 0, so (x1,y1)=(0,0).
The gradient (2x,2y) points straight at the origin, and η=1/2 walks exactly that far.
2
Canyon: a one-step finish needs 1−2η=0 and 1−2cη=0 at once, i.e. η=1/2 and η=1/(2c) — impossible unless c=1.
∎The condition number κ=λmax/λmin=c measures exactly this conflict; κ=1 is the only case where one stride suits every direction.
In one sentence: in a canyon each direction shrinks by its own factor 1−ηλ, the steepest wall sets the speed limit, and κ, steepest over gentlest, tells you how much of the walk is wasted bouncing.
9
Why the compass crosses the contour lines at a right angle
Imagine this
In the tea gardens of Munnar, the paths between the bushes run level around the hillside. Walk along one and you never climb or drop.
Stand on such a path and ask: which way is straight up the hill? Not along the path; that stays level. Straight across it, at a right angle.
Every tea picker knows this without a formula.
On a map, those level paths are contour lines: lines joining points of equal height. The gradient is the "straight up" direction. And it always crosses the contour at exactly 90∘.
Why? For a tiny move, the change in height is "tilt dotted with the move" (Unit 8), that is ∇F⋅δx. Along a contour the height does not change, so that dot product is zero. A zero dot product means a right angle.
The payoff. On a round bowl the contours are circles. "Straight across a circle" points at its centre, which is the bottom. So the gradient aims right at the answer. That is why the round bowl of Section 8 finished in one step.
On a stretched bowl the contours are ovals. Straight across an oval does not point at its centre. A tiny example: on F=x2+4y2 at the point (2.2,1.1), the gradient is (4.4,8.8). The straight line to the bottom points along (2.2,1.1). The angle between them is about 37∘. That gap is the zig-zag.
On a tilted bowl the ovals are also turned. Even after you fix the scale of each axis, a gap remains. That tilt comes from features that move together, and it is the one thing the next section's fix does not remove.
The compass crosses the contour linesThe gradient is always at right angles to the level curve — which is only "toward the bottom" when the bowl is round
Try: Drag the point around the oval. The gradient always meets the contour at 90∘, but it points up to about 37∘ away from the bottom. Switch to circle: the two arrows line up.
—
Moving along a contour does not change the height, so the gradient is at right angles to it. On a circle that points at the centre; on an oval it does not.
The realization
Along a contour the height does not change, so ∇F⋅δx=0: the gradient is at right angles to every contour.
It points at the bottom only when the contours are circles. On ovals, the angle between "steepest" and "towards the bottom" is the zig-zag.
Pause & predict
On F=x2+4y2 at the point (2.2,1.1): what angle does the gradient make with the contour? And with the straight line to the bottom?
If you want the algebra · 1 proof, step by step
Prove it · the gradient is perpendicular to every contour
Claim. If δx is a small displacement along a contour of F, then ∇F⋅δx=0.
1
First-order Taylor (Unit 8): F(x+δx)≈F(x)+∇F⋅δx.
The change in height for a small move is the tilt dotted with the move.
2
Along a contour the height does not change: F(x+δx)=F(x). Hence ∇F⋅δx=0.
∎Zero dot product means a right angle. On F=x2+4y2 at (2.2,1.1): ∇F=(4.4,8.8), tangent (−8.8,4.4), dot 0; the line to the origin (2.2,1.1) makes cosθ=0.8, θ≈36.9∘ with the gradient.
In one sentence: a step along a contour changes nothing, so the gradient crosses every contour at a right angle — which points at the bottom only when the contours are circles.
10
Change the units, not the model — the canyon becomes a bowl
Imagine this
A friend sends you a photo of a round steel thali. But your phone's app has stretched it: thirty times wider than it is tall. On your screen, the plate is a thin silver line.
Nothing about the plate is thin. Only the display is. Fix the aspect ratio and the round plate comes back.
A canyon-shaped bill is often exactly this: a round-ish bowl, drawn in badly mismatched units.
The lecture's data: three countries, two features each, and a happiness score to predict.
country
guns per person x1
butter per person x2
happiness y
A
0.1
25
7
B
0.8
10
1
C
0.4
10
4
The butter numbers are about thirty times bigger than the gun numbers. Remember Section 4: the bill feels each feature's size squared. So the butter wall is about a thousand times steeper than the gun wall.
The numbers. A column's steepness is 2 × the sum of its squares. Guns: 2(0.01+0.64+0.16)=1.62. Butter: 2(625+100+100)=1650. The condition number is κ≈1487: a razor-thin canyon. The safe stride is only about 0.0012.
Now standardise both columns (Section 5). The bill becomes a gently tilted bowl with κ≈10. The safe stride grows to about 0.18. Walking at 90 % of the safe stride, shrinking the error a hundredfold along the gentle direction drops from about 3,800 steps to about 24.
And look at what did not change. The data means the same thing. The model is the same two knobs. The best fit is the same fit, written in new units. Only the units moved. This is the cheapest win in all of machine learning.
Why does standardising land exactly on the fix? After standardising, every column's sum of squares is n, the number of rows. So every wall has the same steepness, 2n=6 here. The walls are level by construction.
What is left over? The bowl still leans, and κ is 10, not 1. In this data, guns and butter move together (their correlation is −0.82): more guns tends to mean less butter. That tilts the bowl, like the tilted ovals of Section 9. Rescaling evens out the axes; it does not straighten them. Turning the axes to match the bowl (called whitening) gives κ=1, a perfectly round bowl. Finding those axes is Unit 12's job (PCA).
Change the units, not the modelThe guns-and-butter loss with the standardising dial in your hand — slide t and watch the razor-blade trench open into a bowl. Drag to orbit.
Try: Press ▶ at t=0: the steps bounce wall to wall and barely move along the trench. Slide t to 1 (κ falls from 1487 to 10) and press ▶ again: the same steps walk nearly straight in.
drag the picture to orbit
—
Changing the units changes the bowl's shape, not the model or the best fit. Standardising removes the stretch; the leftover tilt needs a rotation (Unit 12).
The realization
The bill's steepness in knob j is 2∑ixij2: the column's size, squared. The full table of steepnesses is H=2X⊤X. Standardising makes every diagonal entry 2n, so the walls level out: here κ falls from 1487 to 10.2.
The part that survives is the off-diagonal, from columns moving together. Removing it takes a rotation, not a rescaling.
Pause & predict
You standardise the two columns of the guns-and-butter data. Which of these changes?
Pause & predict
After standardising, κ is 10.2, not 1. What is left over, and what would remove it?
If you want the algebra · 2 proofs, step by step
Prove it · the Hessian of least squares is 2X⊤X, and standardising levels its diagonal
Claim. For J(w)=∑i(w⊤Xi−yi)2: H=2∑iXiXi⊤=2X⊤X, with Hjj=2∑ixij2. After standardising, every Hjj=2n.
1
From the first drawer, ∇J=2∑iriXi with ri=w⊤Xi−yi. Differentiate once more: ∇ri=Xi, so H=2∑iXiXi⊤.
The targets yi vanish: the bowl's shape depends only on the features. Its position depends on y.
2
Entry by entry: Hjk=2∑ixijxik; on the diagonal Hjj=2∑ixij2 — the column's size, squared. Guns and butter: sums 0.81,14.5,825 give H=(1.6229291650).
A column thirty times bigger is a wall nine hundred times stiffer; 1650/1.62≈1019.
3
Standardise: ∑izij2=n for every column (Section 5's drawer), so Hjj=2n=6. Off-diagonal: 2∑izi1zi2=2(−2.466)=−4.93. Hstd=(6−4.93−4.936).
∎The walls are level by construction; the off-diagonal is 2n times the correlation coefficient (−0.822), and it is what keeps κ at 10.2 rather than 1.
Prove it · a symmetric 2×2 with equal diagonals has eigenvalues a±b — so κ falls from 1487 to 10.2
Claim. The symmetric matrix with equal diagonals a and off-diagonal b has eigenvalues a+b and a−b; hence Hstd has 10.93 and 1.07, κ≈10.2, against 1650.5 and 1.11, κ≈1487, before.
1
(abba)(11)=(a+b)(11) and (abba)(1−1)=(a−b)(1−1).
Unit 4: two eigenvectors found by inspection — the diagonal directions of the tilted bowl.
2
With a=6, b=−4.93: λ=1.07,10.93; κ=10.93/1.07≈10.2; speed limit 2/10.93≈0.183.
The eigenvectors (1,1) and (1,−1) are exactly the axes whitening rotates onto.
3
Before: for (1.6229291650), λ=825.81±824.192+292=1650.51,1.11; κ≈1487; limit 2/1650.5≈0.00121.
∎κ improved 145× and the admissible stride 151× — and neither the data's meaning, the model, nor the best fit changed.
In one sentence: the bill feels each column squared, so dividing every column by its own spread levels every wall — the canyon becomes a bowl, the safe stride grows a hundredfold, and the model and the data's meaning stay untouched.
11
The training clinic — read the loss curve like a doctor
Imagine this
A doctor cannot see inside you. She reads the chart: your temperature, hour by hour. A spike, a slow climb, a fever that comes and goes. Each shape points to a different illness.
You cannot see the bill's landscape either. You only see the bill, step after step. And every problem in this unit leaves its own shape on that chart.
Here are six recorded training runs, one problem each. Read the curve, name the problem, choose the fix. The table below is your cheat sheet.
The chart shows
What is going on
What to do
bill becomes ∞ or NaN within a few steps
blow-up: a huge start, or features of very different sizes
start in [−1,1]; rescale the features; lower η
training bill falls to 0, test bill climbs
memorising: more knobs than facts
more data, fewer knobs, a charge for big knobs, or stop early
a zig-zag that grows
the stride is over the speed limit, η>2/λmax
lower η; standardise
falls fast, then crawls for ever
bouncing in a canyon (big κ)
standardise; momentum; a separate stride per knob
flat from the very first step
a plateau, a stride far too small — or a bug in the gradient
raise η; momentum; a better start; check the gradient
different runs, different answers
several valleys, different watersheds
restart and keep the best — or accept it
Notice that the fixes come in just two families. Reshape the landscape so the plain walk works: rescale the features, start sensibly, charge for big knobs. That is this unit. Give the walker better instincts: momentum to roll across flats, a separate stride per knob, a feel for the curve and not just the slope. That is the next unit.
The training clinicSix recorded training runs walk in — read the loss curve, name the disease, prescribe the fix
Try: Open case 2: the training bill falls to 0 while the test bill turns up at step 25. Pick a diagnosis — a right answer draws the healthy curve the fix would give.
—
Six failures, six shapes on the loss curve. The cheat sheet above lists them all.
The realization
Every failure has a signature on the loss curve: blow-up, the train–test scissors, a growing zig-zag, fast-then-crawl, flat from the start, a different answer every run.
Every fix either reshapes the landscape or teaches the walker.
Pause & predict
A run's bill goes 12,4,11,5,13,6,… — a zig-zag that slowly grows. What is wrong, and what do you try first?
In one sentence: every failure in this unit leaves its own shape on the loss curve, and every fix either reshapes the landscape or gives the walker better instincts.
12
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 maths it becomes
The tailor's patches
the bill is the area of the squares; each row pushes along itself, by its miss
∇J=2∑i(w⊤Xi−yi)Xi
The touchy shower tap
start small and random; blow-ups come from the feature's size, not the start
w0∈[−1,1]; factor 1−2ηx2
Last year's answer key
more knobs than facts makes a zero bill free, and meaningless
d>n⇒ endlessly many exact fits
Two taps, one handle
sensitivity is the feature's size squared; no single stride serves both
∂y/∂wj=xj2
Maths out of 100, quiz out of 10
centre slides, standardise squeezes, min–max boxes; use the training numbers
z=(x−μ)/σ, (x−min)/(max−min)
Rain on the Western Ghats
the watershed decides the valley; valleys multiply like a combination lock
∏iki minima; pd; 1−(1−p)k
The salt flat at night
small tilt, small step — a plateau is slow, not finished
steps ≈W/(γg)
The marble in the gutter
each direction shrinks by its own factor; the steepest sets the limit
1−ηλi; η<2/λmax; κ
The tea-garden path
the gradient crosses every contour at a right angle; it points at the bottom only on circles
∇F⋅δx=0
The stretched photo
standardising levels every wall to 2n; only the tilt from correlation remains
H=2X⊤X; κ1487→10
The doctor's chart
every failure has a signature on the loss curve
reshape the landscape, or teach the walker
The one thing to remember
Change the units, not the model. The bill feels every feature squared, so features of different sizes make a canyon. One stride then overshoots on the steep wall and crawls along the gentle 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: start small and random, judge the model on rows it has never seen, and know that the valley you find is the one downhill from where you started.
In one sentence: most training troubles are a badly shaped landscape, and the cheapest way to reshape it is to put every feature on the same scale.
13
Practice arena — twelve problems, solved in full
Twelve problems, from easy to hard, one for every picture in this unit. Every number has been checked by computer.
Two habits do most of the work. For any stride question, write down each direction's factor first: 1−ηλi tells you whether it settles, bounces or blows up. For any scaling question, add up the squares of each column: the bill feels feature sizes squared, through H=2X⊤X.
Problem 1easy
A feature column holds the five values {30,50,70,90,110}. (a) Apply min–max scaling x′=(x−min)/(max−min) to all five. (b) Standardise the column (subtract the mean, divide by the population standard deviation) and check that the z-values sum to 0 and their squares sum to 5. (c) A new value x=130 arrives later. Transform it under both schemes using the training statistics, and say whether the min–max result lies in [0,1].
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 130 through both formulas with the numbers already on the page.
Show the full solution
(a) Step 1 — min–max. Here min=30, max=110, range =80:
3070110↦800=0,↦8040=0.5,↦8080=1.5090↦8020=0.25,↦8060=0.75,
Evenly spaced inputs give evenly spaced outputs — min–max is a pure stretch-and-shift.
(b) Step 2 — mean and deviations.μx−μ=530+50+70+90+110=5350=70,=(−40,−20,0,20,40).
Step 3 — variance and standard deviation. Square the deviations and average over n=5:
σ2σ=51600+400+0+400+1600=54000=800,=800≈28.28.
Step 4 — divide, then check.z=(x−70)/28.28:
z=(28.28−40,28.28−20,0,28.2820,28.2840)=(−1.414,−0.707,0,0.707,1.414).
Sanity sums:
∑z∑z2=−1.414−0.707+0+0.707+1.414=0,=2+0.5+0+0.5+2=5=n.
Both hold, so the column now has mean 0 and variance 5/5=1. ✓
(c) Step 5 — the unseen value, training statistics only.x′z=80130−30=80100=1.25,=28.28130−70=28.2860≈2.12.1.25 lies outside[0,1]: the promise "everything lands in [0,1]" was only ever a promise about the training column. The z-score 2.12 is unusual (two standard deviations up) but perfectly well defined — z-scores are unbounded by design.
"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 min, max, μ, σ with the new point included — that silently changes every training value too. Min–max is fragile to a new extreme; standardisation degrades gracefully.
Problem 2easy
At the current iterate a loss has partial derivatives ∂J/∂w1=−640 and ∂J/∂w2=−1.6, and one learning rate γ=10−3 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 w2 need to move by one unit, and how far does w1 travel in that time? (c) Choose γ instead so that w1 moves a modest 0.01 per step; give the new γ, the new w2 move and the new step count for a one-unit move of w2. (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.Δwj=−γ∂J/∂wj twice; divide 1 by the small move; scale γ down so the big move is 0.01 and redo the count; then name the repair as a computable claim.
Show the full solution
(a) Step 1 — the two moves.Δw1Δw2Δw2Δw1=−10−3(−640)=0.64,=−10−3(−1.6)=0.0016,=0.00160.64=400.
One stride, but a 400:1 imbalance in how far each knob turns.
(b) Step 2 — the slow coordinate.N≈0.00161=625steps
for w2 to move one unit. Meanwhile w1 moves
625×0.64=400units
— long since past its target and bouncing.
(c) Step 3 — protect w1 instead. Require γ×640=0.01:
γΔw2N=6400.01=1.5625×10−5,=1.5625×10−5×1.6=2.5×10−5,≈2.5×10−51=40000steps.
The hair-trigger knob is now tame; the stiff knob crawls 64 times more slowly than before.
(d) Step 4 — the repair. After standardising both columns, the two partials come out of the same order of magnitude (a ratio near 1 instead of 400), so a single γ serves both knobs — Problem 5 does this arithmetic on real columns and watches 576 turn into 1.07.
(a) Δw1=0.64, Δw2=0.0016, ratio 400:1. (b) ≈625 steps, during which w1 moves 400 units. (c) γ=1.5625×10−5, Δw2=2.5×10−5, ≈40000 steps. (d) standardising makes the partials comparable, so one γ fits both.
Remember
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 40000 steps. No choice of γ escapes — only changing the units does.
Problem 3easy
Three receipts: x=(1,2,3), y=(2,5,7), model y^=wx with no intercept. (a) Write the bill for being wrong J(w)=∑(wxi−yi)2 and expand it to the form aw2+bw+c. (b) Find w∗ by setting the slope to zero, confirm it is a minimum, and compute J(w∗) exactly. (c) Run gradient descent from w0=0 with η=0.02 for five steps, tabulating w, the slope and J. (d) Give the per-step factor 1−ηλ 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 J∗ as a fraction with denominator 14; fill a five-row table; then read the curvature 28 for the factor and the speed limit 2/28.
Show the full solution
(a) Step 1 — write and expand the scorecard.J(w)=(w−2)2+(2w−5)2+(3w−7)2.
Each square on its own line:
(w−2)2(2w−5)2(3w−7)2=w2−4w+4,=4w2−20w+25,=9w2−42w+49.
Add columns:
J(w)=(1+4+9)w2−(4+20+42)w+(4+25+49)=14w2−66w+78.
Step 3 — the lowest possible bill, exactly. Put everything over 14:
J(w∗)=14(1433)2−66⋅1433+78=141089−142178+141092=141089−2178+1092=143≈0.214.
(14⋅332/142=332/14=1089/14; 66⋅33=2178; 78⋅14=1092.)
(c) Step 4 — the parachute drop and the walk. Update w←w−0.02(28w−66), one row per step:
k
wk
slope 28wk−66
new w
J(wk)
0
0
−66
0+0.02⋅66=1.3200
78
1
1.3200
36.96−66=−29.04
1.3200+0.5808=1.9008
15.27
2
1.9008
53.22−66=−12.78
1.9008+0.2556=2.1564
3.13
3
2.1564
60.38−66=−5.62
2.1564+0.1124=2.2688
0.78
4
2.2688
63.53−66=−2.47
2.2688+0.0495=2.3183
0.32
5
2.3183
64.91−66=−1.09
—
0.24
Two of the J values in full, to see the arithmetic:
J(1.3200)J(1.9008)=14(1.7424)−66(1.3200)+78=24.39−87.12+78=15.27,=14(3.6130)−66(1.9008)+78=50.58−125.45+78=3.13.
The slope column shrinks every step: 66→29→13→5.6→2.5→1.1. Descent naturally decelerates as it nears the floor, and the limit is w=2.357, J=0.214 — the formula's answer, reached by feel.
(d) Step 5 — the per-direction factor and the speed limit. Subtract w∗ from both sides of the update:
wk+1−w∗=wk−w∗−η(28wk−66)=(1−28η)(wk−w∗).
With η=0.02 the factor is 1−0.56=0.44: the distance to w∗ is multiplied by 0.44 each step (check: 2.357−1.320=1.037; 0.44×2.357=1.037 ✓). Convergence needs ∣1−28η∣<1, i.e.
0<η<282=141≈0.0714.
At η=1/28 the factor is 0 and one step finishes; between 1/28 and 1/14 the iterates alternate sides of w∗; beyond 1/14 they blow up.
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, J — and check it against the closed form: the gap to w∗ must shrink by exactly 1−ηλ each row. The slip is evaluating J at the new w but writing it in the old row.
Problem 4easy
Two bowls: the circle L=x2+y2 and the canyon L=x2+4y2. (a) For the circle, write both gradient-descent updates as multiplications by a constant factor and give the η that sends every starting point to (0,0) 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 η=0.24 from (10,10) for three steps, with L 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 0; stability is ∣1−ηλ∣<1 for the larger λ; then multiply through a table and read the signs of the two factors.
Show the full solution
(a) Step 1 — the circle.∇L=(2x,2y), so
xy←x−η(2x)=(1−2η)x,←y−η(2y)=(1−2η)y.
Both coordinates shrink by the same factor. Choose η=0.5: 1−2(0.5)=0, so (x,y)→(0,0) in a single step from anywhere. The gradient points straight at the centre because the contours are circles.
(b) Step 2 — the canyon.∇L=(2x,8y), so
xy←(1−2η)x,←(1−8η)y.
Stability needs each factor inside (−1,1):
∣1−2η∣<1∣1−8η∣<1⇒0<η<1,⇒0<η<0.25.
The y-coordinate, with ∂2L/∂y2=8, sets the ceiling η<0.25 — even though x would happily accept a stride four times longer.
The new points come straight from the factors: 0.52×10=5.2, −0.92×10=−9.2; 0.52×5.2=2.704, −0.92×(−9.2)=8.464; 0.52×2.704=1.406, −0.92×8.464=−7.787.
(d) Step 4 — Hessian, κ, and what the trace shows.H=[2008],κ=28=4.
In three steps x has gone 10→1.4 (factor 0.52 each time, monotone); y has gone 10→−9.2→8.5→−7.8, flipping sign every step and losing only 8% of its size each time (factor −0.92). Most of the motion is sideways across the canyon, not down it — L fell only from 500 to 244.5.
(a) x←(1−2η)x, y←(1−2η)y; η=0.5 finishes in one step. (b) factors 1−2η, 1−8η; stable for 0<η<0.25, set by y. (c) (5.2,−9.2), (2.704,8.464), (1.406,−7.787); L=500,365.6,293.9,244.5. (d) H=diag(2,8), κ=4; factors 0.52 and −0.92.
Remember
Everything about the canyon is in two numbers, the per-direction factors 1−ηλi: the largest λ caps η at 2/λmax, a negative factor means zig-zag, and κ=λmax/λmin is the difficulty score. Answer "why is the canyon slow?" with the two factors, not with prose.
Problem 5medium
House price y is modelled as y^=w1x1+w2x2 from area x1=(1000,1500,2000) and bedroom count x2=(2,3,3), with y=(50,75,90) and J(w)=∑i(w1xi1+w2xi2−yi)2. (a) Compute ∂J/∂w1 and ∂J/∂w2 at w=(0,0), and their ratio. (b) Standardise both columns (population σ) and recompute both partials at w=(0,0). (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 w=0 every prediction is 0, so each partial is −2∑yixij; compute the two sums; then μ,σ,z for each column; redo the two sums with z in place of x; divide.
Show the full solution
(a) Step 1 — raw partials at the origin. With ri=y^i−yi, the chain rule gives ∂J/∂wj=2∑irixij. At w=0 all y^i=0, so ri=−yi and ∂J/∂wj=−2∑iyixij:
∂w1∂J∂w2∂J=−2[1000(50)+1500(75)+2000(90)]=−2[50000+112500+180000]=−2(342500)=−685000,=−2[2(50)+3(75)+3(90)]=−2[100+225+270]=−2(595)=−1190.
Ratio:
1190685000≈576.
The bill is about 576 times more sensitive to w1, purely because square feet are numerically huge.
Step 4 — the partials again, with z in place of x.∂w1∂J∂w2∂J=−2[(−1.2247)(50)+0(75)+(1.2247)(90)]=−2[−61.24+0+110.22]=−2(48.99)=−97.98,=−2[(−1.4142)(50)+(0.7071)(75)+(0.7071)(90)]=−2[−70.71+53.03+63.64]=−2(45.96)=−91.92.
(c) Step 5 — the new ratio.91.9297.98≈1.07.
From 576 to 1.07: the two knobs now feel the same stride in the same way, so one γ drives both at similar speeds — no oscillation in w1 while w2 crawls.
(a) −685000 and −1190, ratio ≈576. (b) z1=(−1.2247,0,1.2247), z2=(−1.4142,0.7071,0.7071); partials −97.98 and −91.92. (c) ratio ≈1.07.
Remember
At w=0 the gradient is −2∑yix⋅j, so a column's scale multiplies straight into its partial. Quote the before/after ratio — 576→1.07 — as the whole result. The slip is using the sample σ (dividing by n−1) when the population σ was asked for; the z's then change by 2/3.
Problem 6medium
Consider L(x,y)=9x2+y2. (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 η=0.1, trace three steps from (1,3); 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 9x2+9y2, and the two values of η that one-step convergence would need simultaneously on L.
What this tests. The canyon again with the stiff direction along x this time — checking you read the factors from the curvatures and not from habit. Plan.∇L=(18x,2y); factors 1−18η, 1−2η; stability from the larger curvature; multiply through three rows; then κ=18/2 and the one-step condition 1−ηλ=0.
Show the full solution
(a) Step 1 — decoupled updates.∇L=(18x,2y), so
xk+1yk+1=(1−18η)xk,=(1−2η)yk.
Stability needs both factors inside (−1,1):
∣1−18η∣<1∣1−2η∣<1⇒η<182=91,⇒η<1.
The stiff direction is x (curvature 18), so the range is
0<η<91≈0.111.
Both coordinates lose 20% of their size per step, but x flips sign every time: its factor is negative because η=0.1 exceeds 1/18≈0.056, the value at which 1−18η crosses zero. Each step overshoots the floor in the stiff direction and lands on the opposite wall; y descends monotonically. (The two halves of L stay equal because 9x2 and y2 both shrink by 0.64 per step.)
(c) Step 3 — Hessian, κ, the ideal bowl.H=[18002],κ=218=9.
Descent is fastest when curvature is equal in every direction, κ=1: on 9x2+9y2 both factors are 1−18η, so η=1/18 makes both zero and every start reaches (0,0) in one step. On L itself one-step convergence would need 1−18η=0and1−2η=0, i.e. η=1/18 and η=1/2 at once — impossible with a single stride.
(a) x←(1−18η)x, y←(1−2η)y; 0<η<1/9≈0.111, set by x. (b) (−0.8,2.4), (0.64,1.92), (−0.512,1.536); x oscillates (factor −0.8) because η>1/18≈0.056; y descends (factor 0.8). (c) H=diag(18,2), κ=9; η=1/18 finishes 9x2+9y2 in one step; L would need 1/18 and 1/2 simultaneously.
Remember
Three thresholds per direction: η<1/λ smooth, η=1/λ one-step, 1/λ<η<2/λ 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 y out of habit — read it from the coefficient.
Problem 7medium
For the least-squares bill J(w)=∑i=1n(w⊤Xi−yi)2: (a) derive ∇J(w)=2∑i(w⊤Xi−yi)Xi. (b) For X1=(2,1), y1=4, X2=(1,3), y2=5, compute J and ∇J at w0=(0,0), take one step with γ=0.02, and compute the new residuals and J1; 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 ri, differentiate the square by the chain rule, note ∇ri=Xi; then residuals at the origin, two scaled vectors added, one update, two new residuals, compare.
Show the full solution
(a) Step 1 — the chain rule. Write J=∑iri2 with ri=w⊤Xi−yi. Since w⊤Xi is linear in w, its gradient is the vector Xi, and yi is a constant:
∇wri=Xi.
Differentiate each square:
∇J=i∑2ri∇wri=2i∑(w⊤Xi−yi)Xi.
Reading: each row pulls w along its own feature vector, in proportion to its current error.
(b) Step 2 — at the origin. Predictions are 0, so
r1J0=0−4=−4,=16+25=41.r2=0−5=−5,
The gradient:
∇J(w0)=2[(−4)(2,1)+(−5)(1,3)]=2[(−8,−4)+(−5,−15)]=2(−13,−19)=(−26,−38).
Step 3 — one step.w1=(0,0)−0.02(−26,−38)=(0.52,0.76).
Step 4 — verify the drop. New residuals:
r1r2J1=0.52(2)+0.76(1)−4=1.04+0.76−4=−2.20,=0.52(1)+0.76(3)−5=0.52+2.28−5=−2.20,=(−2.2)2+(−2.2)2=4.84+4.84=9.68.9.68<41 ✓. Fraction removed:
4141−9.68=4131.32≈0.76,
i.e. 76% of the bill in a single step.
"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 w=0. Watch the sign convention: with ri=y^i−yi the formula is +2∑riXi and the minus sign lives in the update; with ri=yi−y^i it moves into the gradient.
Problem 8medium
Knobs versus facts. Three rows (x1,x2,x3,x4,y): (61,2,3,0.1,59), (40,0,4,0.5,40), (68,0,10,1.0,70); the model has five knobs, y^=w1x1+w2x2+w3x3+w4x4+w5, and the real-world truth is y≈x1. (a) For the honest model w=(1,0,0,0,0) give the three predictions, the three errors and J. (b) The memoriser sets w1=w4=0 and hits all three rows exactly using w2,w3,w5: write the three equations, solve them, and give its J. (c) Check the candidate w=(0,7,5,0,20): compute its row-1 prediction and its J. (d) On an unseen row x=(50,1,6,0.3) with true y≈50, 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 3×3 linear system by elimination; then plug the candidate into row 1 and recompute J; then one unseen row through both models; finally the count 5−3.
Show the full solution
(a) Step 1 — the honest model y^=x1.
row
y^=x1
y
error y^−y
squared
1
61
59
+2
4
2
40
40
0
0
3
68
70
−2
4
J=4+0+4=8.
Close to zero, not zero.
(b) Step 2 — the memoriser's three equations. With w1=w4=0, row by row:
2w2+3w3+w54w3+w510w3+w5=59=40=70(row 1)(row 2)(row 3)
Row 3 minus row 2 kills w5:
10w3−4w36w3w3=70−40=30=5.
Into row 2:
4(5)+w5=40⇒w5=20.
Into row 1:
2w2+3(5)+202w2+352w2w2=59=59=24=12.
So the memoriser is y^=12x2+5x3+20. Check all three rows: 24+15+20=59 ✓, 20+20=40 ✓, 50+20=70 ✓. Its J=0 exactly.
(c) Step 3 — the candidate (0,7,5,0,20). Row 1:
7(2)+5(3)+20=14+15+20=49=59.
Rows 2 and 3 do not involve w2 and are still exact. So
J=(49−59)2+0+0=(−10)2=100,
not 0: that triple is not a zero-error solution, w2=12 is.
(d) Step 4 — one unseen row.x=(50,1,6,0.3), truth y≈50:
honest:y^memoriser:y^=x1=50,=12(1)+5(6)+20=12+30+20=62,errorerror=0,=12.
Perfect on the three training rows, off by 12 on the first row it has never seen — it was memorising with variables that have nothing to do with the answer.
(e) Step 5 — the count. The full model has 5 unknowns; the data supply 3 equations (one per row). Three independent equations in five unknowns leave
5−3=2
free parameters: the zero-error solutions form a two-parameter family — infinitely many of them — and the optimiser hands you one of them with no idea which is meaningful. The memoriser of (b) is the member with w1=w4=0.
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 (7,5,20) is one row-1 check away from being exposed. Regularisation later makes the memoriser (weights 12,5,20) expensive and the honest model (weight 1) cheap.
Problem 9medium
Let F(x)=(x−1)2((x−3)2−1). (a) Find F′(x) in factored and expanded form, and all stationary points. (b) Classify them with F′′ and give F at each. (c) Run gradient descent from x0=0.5 with η=0.02 for four steps, tabulating x, F′ and F; state the limit and which starting points end there. (d) On a plateau where ∣F′∣=0.001, with η=0.01, give the step length and the number of steps to cross a plateau of width 2.
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 2(x−1), quadratic formula; F′′ at three points; four table rows with the expanded F′; then step =η∣F′∣ and divide the width by it.
Show the full solution
(a) Step 1 — product rule. With u=(x−1)2, v=(x−3)2−1: u′=2(x−1), v′=2(x−3), so
F′=u′v+uv′=2(x−1)[(x−3)2−1]+(x−1)2⋅2(x−3)=2(x−1)[(x−3)2−1+(x−1)(x−3)].
Simplify the bracket:
(x−3)2−1(x−1)(x−3)sum=x2−6x+8,=x2−4x+3,=2x2−10x+11.
Hence
F′(x)=2(x−1)(2x2−10x+11).
Expanded:
F′=2(2x3−10x2+11x−2x2+10x−11)=2(2x3−12x2+21x−11)=4x3−24x2+42x−22.
Step 2 — stationary points. Either x=1, or 2x2−10x+11=0:
x=410±100−88=410±12=410±23=25±3.
Numerically 1.634 and 3.366. Three stationary points: x=1,1.634,3.366.
(b) Step 3 — curvature and depth.F′′(x)=12x2−48x+42:
F′′(1)F′′(1.634)F′′(3.366)=12−48+42=6>0,=32.04−78.43+42=−4.39<0,=135.96−161.57+42=16.39>0.
So x=1 is a minimum, 1.634 a maximum, 3.366 a minimum.
Values:
F(1)F(1.634)F(3.366)=02⋅(4−1)=0,=(0.634)2[(−1.366)2−1]=0.4020×0.866=0.348,=(2.366)2[(0.366)2−1]=5.598×(−0.866)=−4.848.
The valley at x=1 has floor 0; the valley at 3.366 has floor −4.848. The watershed between them is the hilltop at 1.634.
(c) Step 4 — the walk from x0=0.5. Update x←x−0.02F′(x):
k
xk
F′(xk)
new x
F(xk)
0
0.5000
−6.500
0.5+0.1300=0.6300
1.3125
1
0.6300
−4.065
0.63+0.0813=0.7113
0.6321
2
0.7113
−2.829
0.7113+0.0566=0.7679
0.3532
3
0.7679
−2.089
0.7679+0.0418=0.8097
0.2146
4
0.8097
—
—
0.1376
The first row in full:
F′(0.5)F(0.5)=4(0.125)−24(0.25)+42(0.5)−22=0.5−6+21−22=−6.5,=(−0.5)2[(−2.5)2−1]=0.25×5.25=1.3125.∣F′∣ shrinks every step — the walk decelerates as it nears a floor — and the limit is x=1, F=0. It reports success while F=−4.848 existed the whole time. Every start below the watershed 1.634 ends at x=1; only a start above it finds the good valley.
(d) Step 5 — the salt flat. Step length =η∣F′∣:
stepsteps=0.01×0.001=10−5,=10−52=200000.
Not at a minimum, just on level ground, inching.
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 0.5 never sees it.
Problem 10hard
For F(x)=3x4−4x3−12x2+5, small-step gradient descent converges to the local minimum at x=−1 from any start x0<0 and to the global minimum at x=2 from any start x0>0; the watershed sits at x=0. Verify these three facts from F′ and the values F(−1), F(2), F(0). The start x0 is drawn uniformly from [−2,3]. (a) Compute the probability that a single run finds the global minimum. (b) With k independent restarts (keep the best), find the smallest k for which the global minimum is found with probability at least 0.99, and give that probability. (c) If a separable ten-dimensional objective has this landscape in every coordinate (per-coordinate success 0.6, 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 F′ and evaluate F at the three roots; favourable length over total length; 1−0.4k≥0.99 with powers computed exactly; then 0.610.
Show the full solution
Step 1 — the landscape.F′(x)=12x3−12x2−24x=12x(x2−x−2)=12x(x−2)(x+1).
Roots −1,0,2. Values:
F(−1)F(0)F(2)=3+4−12+5=0,=5,=48−32−48+5=−27.F′′(x)=36x2−24x−24: F′′(−1)=36>0, F′′(0)=−24<0, F′′(2)=72>0. So x=−1 is a local minimum (floor 0), x=0 the hilltop between the valleys (the watershed), x=2 the global minimum (floor −27). Left of 0 the slope pushes toward −1; right of 0 toward 2.
(a) Step 2 — one run. Success needs x0>0 (the single point x0=0 has probability zero under a continuous draw). Favourable length over total length:
p=3−(−2)3−0=53=0.6.
(b) Step 3 — restarts. One run fails with probability 0.4; all k fail with probability 0.4k. Require
1−0.4k≥0.99⟺0.4k≤0.01.
Compute the powers exactly:
0.450.46=0.01024>0.01(fails),=0.004096≤0.01(works).
So k=6, with success probability 1−0.004096=0.995904≈0.9959. Five restarts just miss at 1−0.01024=0.98976.
(c) Step 4 — ten dials at once. By independence,
P=0.610=0.0060466≈0.006,
about 0.6%. With per-coordinate odds well above a half, joint success collapses exponentially — the combination lock has 210=1024 settings here and only one opens the door.
"At least one success in k tries" is 1−(1−p)k; compute the powers precisely, because these numbers are built so that k=5 barely fails. Basins multiply across coordinates, so probabilities multiply too — restarts rescue one dial, not a lock with ten.
Problem 11hard
Guns and butter: x1=(0.1,0.8,0.4), x2=(25,10,10), y=(7,1,4), model y^=w1x1+w2x2, J=∑(y^i−yi)2. (a) Write J(w) out, compute the Hessian H=2[∑x12∑x1x2∑x1x2∑x22], its eigenvalues, κ and the speed limit 2/λmax. (b) Standardise both columns (population σ), recompute the three sums, Hstd, its eigenvalues, κ and 2/λmax. (c) Give the improvement factors in κ and in the admissible stride, and compute the correlation coefficient of the two columns that explains why κ is 10 and not 1.
What this tests. Bad scaling and bad curvature meeting: feature scales enter the Hessian squared, standardising forces both diagonals to 2n, and what is left over is correlation. Plan. Three sums, double them; eigenvalues from the 2×2 formula; then μ,σ,z per column, the three sums again, a±b eigenvalues; divide before by after; finally ∑z1z2/n.
Show the full solution
(a) Step 1 — the bill, written out.J(w)=(0.1w1+25w2−7)2+(0.8w1+10w2−1)2+(0.4w1+10w2−4)2.
Its second derivatives are 2∑xi12, 2∑xi22 and 2∑xi1xi2.
Step 2 — the three sums and H.∑x12∑x22∑x1x2=0.01+0.64+0.16=0.81,=625+100+100=825,=2.5+8+4=14.5.H=2[0.8114.514.5825]=[1.6229291650].
Step 3 — eigenvalues, κ, speed limit. For a symmetric [pqqs], λ=2p+s±(2s−p)2+q2:
2p+s2s−pλ=21651.62=825.81,=21648.38=824.19,=825.81±824.192+292=825.81±679289+841=825.81±824.70,
so λmax≈1650.5, λmin≈1.11. Then
κλmax2=1.111650.5≈1487,=1650.52≈0.00121.
A canyon about 1487≈39 times longer than it is wide, and a stride capped near 10−3 in the w1 direction, whose curvature is only 1.62.
(b) Step 4 — standardise the guns column.μ1x1−μ1σ12σ1z1=30.1+0.8+0.4=31.3=0.4333,=(−0.3333,0.3667,−0.0333),=30.1111+0.1344+0.0011=0.0822,=0.0822=0.2867,=(−1.163,1.279,−0.116).
Step 5 — standardise the butter column.μ2x2−μ2σ22σ2z2=325+10+10=345=15,=(10,−5,−5),=3100+25+25=3150=50,=50=7.071,=(1.414,−0.707,−0.707).
Step 6 — the three sums again.∑z12∑z22∑z1z2=1.352+1.635+0.014=3.000,=2.000+0.500+0.500=3.000,=−1.644−0.904+0.082=−2.466.
The first two are exactly 3=n — dividing a column by its own σ forces ∑z2=n, so every diagonal entry of the Hessian becomes 2n.
Hstd=[6−4.93−4.936].
Equal diagonal, so the eigenvalues are a±b:
λκλmax2=6±4.93=10.93,1.07,=1.0710.93≈10.2,=10.932≈0.183.
(c) Step 7 — the improvement, and what is left.κstdκraw0.001210.183=10.21487≈145,≈151.
About 145× in κ and 151× in the admissible stride, without touching the model, the algorithm or the data's meaning. The leftover κ=10.2 comes from the off-diagonal −4.93: the columns are correlated,
ρ=n∑z1z2=3−2.466≈−0.822.
Scaling equalises the axes; it does not decorrelate them, so the contours stay tilted. Removing the tilt is what PCA-whitening is for.
Standardising forces every diagonal of H to 2n; whatever κ survives is correlation, read off the off-diagonal. Two handy facts: eigenvalues of [abba] are a±b, and for general 2×2 symmetric use mean ± half-difference-and-q. The slip is forgetting the factor 2 in H and so in 2/λmax.
Problem 12hard
A linear model y^=w1x1+w2x2 is trained on x1=(100,500,900) and x2=(0.9,0.3,0.6), with J=∑(y^i−yi)2 and Hessian H=2∑iXiXi⊤. (a) Compute H, its eigenvalues (use λmin=detH/λmax), the largest stable stride γmax=2/λmax and κ. (b) Min–max normalise both columns, recompute H′, its eigenvalues, γmax′ and κ′. (c) By what factor did the admissible stride improve?
What this tests. The grand synthesis: a 103 gap in feature scale becomes a 106 gap in curvature, which caps the stride at 10−6; min–max scaling buys it back. Plan. Three sums, double them; λmax≈H11 because the off-diagonal is tiny in comparison, λmin from the determinant; then scale, three new sums, a±b; divide the two strides.
Show the full solution
(a) Step 1 — raw sums and H.∑x12∑x1x2∑x22=104+25×104+81×104=107×104=1070000,=90+150+540=780,=0.81+0.09+0.36=1.26.H=2[10700007807801.26]=[2.14×106156015602.52].
Step 2 — eigenvalues, stride, κ. The off-diagonal 1560 is tiny next to 2.14×106, so λmax≈H11=2.14×106. The other eigenvalue comes from the determinant:
detHλmin=(2.14×106)(2.52)−15602=5392800−2433600=2959200,=λmaxdetH=2.14×1062959200≈1.38.
Then
γmaxκ=2.14×1062≈9.3×10−7,=1.382.14×106≈1.6×106.
Any stride above ∼10−6 blows up, and at 10−6 the w2 direction (curvature 1.38) moves by a factor 1−1.38×10−6 per step — glacially.
(b) Step 3 — min–max both columns. Column 1: min=100, range 800; column 2: min=0.3, range 0.6:
x1′x2′=(8000,800400,800800)=(0,0.5,1),=(0.60.6,0.60,0.60.3)=(1,0,0.5).
Step 4 — the new Hessian.∑x1′2∑x1′x2′∑x2′2=0+0.25+1=1.25,=0+0+0.5=0.5,=1+0+0.25=1.25.H′=2[1.250.50.51.25]=[2.5112.5].
Equal diagonal, so λ=a±b:
λγmax′κ′=2.5±1=3.5,1.5,=3.52≈0.571,=1.53.5≈2.33.
(c) Step 5 — the improvement.γmaxγmax′=9.3×10−70.571≈6×105.
The stride grew by roughly six orders of magnitude, and κ fell from ∼106 to 2.33 — the quantitative content of "scale your features before descending".
Feature scales enter H squared, so a 103 scale gap is a 106 curvature gap and a 10−6 speed limit. Scaling is not cosmetic; it is a computable 105–106× speed-up. For a nearly diagonal 2×2, λmax≈ the big diagonal entry and λmin=det/λmax — never read λmin off the small diagonal entry (2.52, not 1.38).
You reshaped the ground; Unit 11 reshapes the walker. Memory so that agreeing pushes stack and flapping ones cancel, a private stride per knob built from its own history, and forgetting so that history never becomes a life sentence — momentum, AdaGrad, RMSProp and Adam, raced on one valley. Then someone builds a wall, the answer moves onto it with the gradient still tilted, and a whole new test has to be built: the Lagrangian as a fine, complementary slackness, the five KKT conditions, and the dual that prices the wall from the other side.