Training a two-layer ReLU network looks like a rugged, non-convex search. It is secretly a convex problem: pick a few hinges from a finite list, and every run lands on the same answer.
Learn why a neural network trained with weight decay is a sparse selection of hinges, how a convex program finds it, and what that buys when the signal is a heartbeat.
Pick a trainer, then slide the penalty. The convex answer stays the same on every visit. The gradient-descent runs differ from each other, most at four hours, where the data has a gap. Then we build, piece by piece, why: springs and sparsity, hinges and masks, the dual, and a count of patterns.
You need a feel for a neural network as a stack of weighted sums and what a derivative is. We teach ReLU, convexity and the rest from zero.
Based on Lecture 16 of Stanford EE269: Signal Processing and Quantization for Machine Learning, taught by Mert Pilanci (slides of 18 November 2020, listed on the slides page), and the paper by Pilanci and Ergen it presents. Every idea is re-taught here in our own words and devices.
Ten made-up grade points in the style of the lecture’s slide 21 (hours studied against course grade), not its data. The network has 30 hidden ReLU neurons with biases, trained with Adam for 4,000 steps from a seeded random start on ½‖f − y‖² + (λ/2)(‖W1‖F² + ‖W2‖F²). The convex answer is the lecture’s convex program in one dimension, restricted to 38 candidate hinges (a kink at each data point and halfway between) and solved to convergence. Inputs and grades are rescaled to the range 0 to 1 inside, so λ is in those units.
Chapter 0
See why two networks can match every training point and still disagree, and meet the question the whole lecture answers
You have ten points: hours studied against a course grade. You train a small neural network on them, and it hits every point exactly. A friend trains another network on the same ten points, with a different random start. It also hits every point exactly.
Then you both ask the same question: what grade does a student get who studies four hours? You say 66. Your friend says 61. The data allowed both answers, and gradient descent picked whichever one it happened to reach.
This lecture is Lecture 16 of Stanford EE269, given by Mert Pilanci on 18 November 2020. It asks one question about that disagreement. Can we describe all the networks that fit the data, and say which one training chooses? For a network with two layers, the answer is yes, and it comes from convex optimization.
A neuron here is a very small function. It takes a weighted sum of its inputs and then applies the ReLU (rectified linear unit): keep the number if it is positive, otherwise output zero. We write ReLU as (u)+ = max(0, u). Plot it and you see a flat line that bends upward at zero, like a hinge on a door.
A two-layer network, also called a network with one hidden layer, uses m neurons side by side. Each neuron looks at the input x, makes a hinge, and the output is a weighted sum of the m hinges. The lecture writes it like this.
Count the numbers. The input x has d entries, so w(1)j ∈ Rd. Stack the m vectors side by side and you get a matrix W1 ∈ Rd×m. The output weights form a column W2 ∈ Rm×1. For grades, d is 1 (hours) or 2 if we add a bias, and the network has about 3 numbers per neuron.
The first slide of ideas says two-layer networks are universal approximators. Given enough neurons, they can match any reasonable function to any precision, because enough hinges at enough angles can trace any curve. The catch is in the slide too: it may take infinitely many neurons for perfect precision. And deeper networks need fewer neurons for the same error.
Real networks use many neurons, often more than there are training points. The lecture calls this overparametrization. Take labels y that are +1 or −1. The equation f(xi) = yi for every training point means zero training loss, a perfect fit. With more unknowns than equations, this equation has many solutions.
A worked count. Ten data points give ten equations. A network with 30 neurons has about 30 × 3 = 90 free numbers. That leaves roughly 80 directions in which you can move the weights and still fit all ten points. Which of those 80 directions does training use?
The lecture’s answer is a phrase: the numerical optimizer (gradient descent, stochastic gradient descent, momentum and so on) may have an inductive bias, a built-in taste for one solution over another. The whole lecture is about making that taste visible. Try it first. Below, two networks fit the same ten points exactly. Each uses the same rule, the smallest weights that fit, applied to a different random set of hinges.
The purple line is one network, the dashed purple line another. Both pass through all ten blue points. Press New random networks, or add neurons, and see where they disagree.
Illustrative. Each network is m random hinges, with kinks placed between hours 0 and 12 (a little beyond the data), and output weights chosen as the smallest ones that fit all ten points exactly (the minimum norm solution of ten linear equations). It is a stand-in for what training finds, not the lecture’s experiment. The grade points are made up.
Both curves hit the points. Between them they differ, and the gap at four hours is the question mark from the hero. Nothing in the data tells the two networks apart. Only the way we chose among the solutions does.
A note on the course. The lecture follows the earlier ones on neural networks and deep learning, and leans on convex duality. If those are fresh, you are ready. If not, this lesson teaches what it needs on the way. The slides are on the course slides page; there is no reading to do first.
Chapter 1
Meet three honest complaints about neural networks: they are hard to train, hard to read and easy to fool
A deep network wins a benchmark. A newspaper prints the result. Then someone asks a plain question: what did it learn? Nobody can answer, not even the people who trained it. This is the mood of the lecture’s next few slides.
The slides state the problem in two bullet points. Deep learning models often give the best performance because of their large capacity (the number of different functions they can represent), and that makes them challenging to train. They are also complex black boxes built on non-convex optimization (a search over a bumpy landscape; Chapter 2 draws it), so it is hard to interpret what the model is actually learning.
The slides give a story with a twist. In August 2018 a paper in Nature used deep learning to predict where aftershocks would strike after large earthquakes. It made headlines. One year later, in October 2019, another Nature paper (Mignan and Broccardo) carried a title that is also a verdict: “One neuron versus deep learning in aftershock prediction.” The slide’s summary is that a logistic regression, a model with one layer, performed as well as the deep network with six.
We do not want to lean on this too hard. It is one case, and the slide only reports it. But it shows the worry: when a model is too complex to inspect, you cannot tell whether its depth is doing any work.
Here is the symptom, the measurement and the fix. The symptom: you train the same network five times, changing only the random start, and the five runs end at five different losses. The measurement: write down the spread of the final losses. If the spread is large, the runs are landing in different valleys of a bumpy landscape. The usual fix is practical and costly: try many starts and keep the best.
“Hard to interpret” has a similar shape. A network with 30 neurons fitted to ten grade points holds about 90 numbers. You can print every one of them, and still not say which number explains the prediction at four hours. The numbers are all there, but their meaning is spread across them in a way no single one reveals.
The slides add a famous failure. Szegedy and colleagues (2014) and Goodfellow and colleagues (2015) showed adversarial examples: an input with a small, carefully chosen change that makes a network answer wrongly. In the lecture’s picture a panda, which the network calls “panda” with 57.7% confidence, gains a layer of faint noise. The picture looks the same to a person, and the network now says “gibbon” with 99.3% confidence. Evtimov and colleagues (2017) did the same in the physical world: a stop sign with a few stickers read as a speed limit sign.
Why do tiny changes work? Goodfellow’s answer is simple, and you can check it by hand. Take the plainest classifier, a weighted sum. The score is s = wTx, the sum of each input times its weight, and a positive score means “class A”.
Now nudge every input by the same small amount ε, each in the direction that helps the attacker: against the sign of its weight. Input i changes by −ε sign(wi). The score then changes by −ε times the sum of |wi|, written −ε‖w‖1.
A worked case. Three inputs, weights (0.5, −1, 2), and ε = 0.1. The sum of |wi| is 3.5, so the score drops by 0.35. Small. Now take an image with 150,528 numbers (224 × 224 pixels, three colours) and weights that average 0.04 in size. The same ε = 0.1 is far too big to hide, but ε = 0.01 already moves the score by 0.01 × 0.04 × 150,528, about 60. Each input barely changes. The effects add up across all the inputs.
So the number of inputs d is the real lever. The next device lets you pull it. The classifier is sure at the start: its score is +3. Choose a push size and add features.
The curve shows the classifier’s score after a push of size ε on every input, for more and more inputs. Above the line the answer holds. Below it the answer flips. Drag the number of inputs.
Illustrative linear classifier, the model Goodfellow used for his explanation. The weights are 30,000 seeded random numbers with a typical size of 0.04, and the clean score is set to +3 for every d. The push moves input i by −ε sign(wi), so the score falls by ε‖w‖1, computed exactly from those weights. The panda and stop sign figures (57.7% to 99.3%) are the lecture’s, from the cited papers.
With ε = 0.010, the label holds up to about 7,500 inputs and flips beyond that. Real images sit far past that point. This is not a quirk of one network. It is what a weighted sum of many inputs does.
The lecture closes the section with three questions. How can we understand what neural network models are learning? Are they automatically finding the best features? Can we make feature extraction differentiable and expect it to work, and can we replace domain knowledge with networks and data? These are the questions of a signal-processing course: for audio, images and sensor data, you used to design the features by hand.
The lecture answers by changing the kind of tool. Least squares, logistic regression and support vector machines are understood extremely well, and the reason is that their training problems are convex. If a neural network could be rewritten as a convex problem, the same understanding would carry over. That is the next chapter’s idea, and the whole lecture’s claim.
Chapter 2
Roll a marble in a bowl and in a bumpy field, and see why least squares is solved while neural networks are not
Drop a marble into a bowl. Wherever you let go, it rolls down and stops at the same lowest point. Now drop it into a field of hills and dips. Where it stops depends on where you let go.
That is the difference the lecture draws on its slide with two small parabolas, one labelled convex and one labelled non-convex. A convex function has one valley. Pick any two points on its graph and join them with a straight line: the line stays above the graph. A non-convex function breaks this rule, and may have many valleys.
For optimization, convexity is a gift. In a convex problem, every local minimum (a point lower than all its neighbours) is also the global minimum (the lowest point anywhere). Any method that keeps going downhill finishes at the answer. In a non-convex problem, a downhill method can stop in a shallow dip while a much deeper one waits elsewhere.
Choose a curve and a starting point, then press Roll. The ball follows gradient descent: at each step it moves a little way downhill, against the slope.
Toy curves, not the lecture’s. Convex: f(x) = 0.5(x − 0.3)². Non-convex: f(x) = (x² − 1)² + 0.3x, with one deep valley and one shallow valley. Gradient descent takes 400 steps of size 0.02, computed live.
Slide 13 states why this matters for the lecture. Least squares, logistic regression, support vector machines and their relatives are understood extremely well, because their training problems are convex. Insightful theorems for neural networks are rare, because their training problems are not.
You can test convexity with numbers. Take the curve f(x) = x2. Pick the points −1 and 3 and look at the middle point, x = 1. The curve there is f(1) = 1. The straight line between the two points is at (1 + 9)/2 = 5. The curve is below the line, and so it is for every pair of points: f is convex.
Now a network in miniature: one input of 1, one hidden weight w1, one output weight w2, and no ReLU, with target 1. The cost is (w1w2 − 1)2. At (w1, w2) = (1, 1) the cost is 0. At (−1, −1) the cost is also 0. The middle point is (0, 0), and its cost is 1, above the average of the two ends. So even this tiny product of two layers is not convex. The product of the layers is the culprit, and Chapter 6 removes it.
The lecture’s first example is the oldest one: least squares, min over x of ‖Ax − b‖22. Here A is a table of numbers with one column per unknown, x is the unknown weights, and b is the target. The double bars with a small 2 mean the length of a vector, and squaring it adds up the squared errors.
The slide draws a picture, and the picture is the whole idea. The columns of A span a flat sheet, the column space. Every possible output Ax lies on that sheet. The target b usually does not. So the best we can do is the point on the sheet closest to b, which is the projection of b onto the sheet. The leftover error sticks straight out of the sheet at a right angle.
A worked case with numbers. Let A have a single column (1, 1), and b = (1, 3). The sheet is the diagonal line through (1, 1). The projection of b onto it has x = (aTb)/(aTa) = (1 + 3)/(1 + 1) = 2, so Ax = (2, 2). The leftover is b − Ax = (−1, 1). Check the right angle: (1, 1) · (−1, 1) = 0. The squared error is 1 + 1 = 2.
For more columns the same right-angle rule gives the normal equations, ATA x = ATb. They are linear, so a computer solves them in one shot, with no search at all. No marble rolls anywhere. This is what “understood extremely well” means. The answer exists, it is unique when the columns are independent, and a formula finds it. Our regression lesson builds this in detail.
Now the network. In f(x) = ∑ w(2)j (xTw(1)j)+, the output is linear in the output weights w(2), which is a least-squares problem on its own. It is the input weights w(1) that sit inside the ReLU, and the product of the two layers that makes the whole thing non-convex. The lecture’s plan is to find a change of variables that turns that product into a plain sum.
Chapter 3
Watch a penalty pull an answer toward zero, see why one kind pulls it exactly to zero, and meet the group version
You measure a number y, and you know the measurement is noisy. You also believe the true value is probably small. How do you combine the two? You pay a price for missing the measurement, and a second price for being far from zero. Then you pick the value with the lowest total price.
That is regularization: adding a penalty to the fitting cost so the answer stays simple. The lecture shows it with the smallest example there is, one unknown x, and draws it as a physical machine.
Take the cost ½(x − y)2 + ½λx2. The first term is the energy stored in a spring of stiffness 1 that connects x to the measurement y. The second is the energy of a spring of stiffness λ that connects x to zero. The point x settles where the two pulls balance. Set the slope to zero: (x − y) + λx = 0, so
y = 3, λ = 1: x* = 3 / (1 + 1) = 1.5. And y = 0.8, λ = 1: x* = 0.8 / 2 = 0.4.
The answer shrinks toward zero by a fixed fraction, but it never reaches zero unless y is zero.
Now change the second term to λ|x|, the L1 penalty (the absolute value). The slide swaps the second spring for a ball of mass λ and calls its cost potential energy. Our reading of the picture: a ball of weight λ resting in a V-shaped track, whose height at x is λ|x|.
The V has a sharp tip at zero, and that tip is the whole story. Away from zero the V has a constant slope λ. The spring pulls the ball toward y with force y − x. At x = 0 that pull equals y. If y is smaller than λ the pull cannot lift the ball out of the tip, so it stays at exactly zero. If y is bigger, the ball moves until the spring force has dropped to λ. The result is called soft thresholding.
y = 3, λ = 1: x* = 3 − 1 = 2. And y = 0.8, λ = 1: x* = (0.8 − 1)+ = 0, exactly.
Same measurements, different penalties. L2 turned 0.8 into 0.4. L1 turned it into 0. Slide 17 shows this with a heavy ball (large λ): it sits in the tip and does not move. Try it below.
Each curve is the total cost for every possible x. The dot at the bottom of each is its best x. Drag the measurement y and the penalty λ.
The curves are ½(x − y)² + ½λx² (grey, the L2 spring) and ½(x − y)² + λ|x| (yellow, the L1 ball), the lecture’s two costs. The best x is found from the formulas above and checked against the curve. Heights above 6 are cut off.
Make λ larger than |y| and the yellow dot lands on zero and stays. The grey dot keeps sliding, but only toward zero. This is why L1 gives sparse answers (many entries exactly zero), and why it matters for us: a sparse answer means fewer neurons.
For a vector x, slide 18 uses the L1 norm ‖x‖1, the sum of |xi|. The problem min ‖Ax − y‖22 + λ‖x‖1 is called the lasso, and its answer x* is sparse. Our dictionary learning lesson uses the same idea.
Slide 19 goes one step further. Split x into k blocks x1 to xk, and penalize each block by its ordinary length ‖xi‖2 = √(xi12 + … + xid2). This is the group L1 penalty. The sum of lengths has a tip at every block’s origin, so whole blocks go to exactly zero together. The answer is group sparse: most blocks are zero. The slide draws it as two springs and a ball in a V, and adds that these methods are well understood.
When the data is clean, each block shrinks like this: xi* = (1 − λ/‖zi‖2)+ zi, where zi is the block before the penalty. Keep the block, scaled down, or kill it whole. A worked case: a block z = (2, 1.4) has length 2.44. With λ = 0.6 it keeps the fraction 1 − 0.6/2.44 = 0.754, so it becomes (1.51, 1.06). A block (0.5, 0.3) has length 0.58, below 0.6, so it becomes (0, 0).
Six numbers sit in three blocks of two. Grey outlines show the numbers before the penalty. Raise λ and compare which entries die under each penalty.
Illustrative numbers (2, 1.4 | 0.5, 0.3 | 0.9, −0.2), a clean-data case where the matrix A is the identity. L1 shrinks each entry by λ and clips at zero. Group L1 uses the block formula above.
The group version is the one that comes back. In the convex program of Chapter 5, each block is the weight vector of one neuron, and killing a block removes that neuron.
Chapter 4
Connect the dots in three ways, count the energy of each, and see why training a ReLU network picks the straight-line answer
A student studied two hours and scored 55. Another studied five hours and scored 66. A third studied four hours, and we have lost the score. What is your best guess? Most people draw a straight line between the two neighbours and read off the middle: 55 + (2/3) × 11 = 62.3.
That guess is the lecture’s first example, slides 20 to 22: a one-dimensional signal, the course grades, with a question mark at four hours. The lecture sets up the data as n scalar samples (d = 1), stacked in a column X = (x1, …, xn) with labels y = (y1, …, yn), and the network f(x) = W2 φ(W1x), with W1 ∈ Rd×m, W2 ∈ Rm×1 and φ the ReLU.
Slide 23 shows the trouble from Chapter 0. Many different curves pass through all the points, and each has zero training loss. Some are calm, some swing wildly between the points. Slide 24 gives the lecture’s first result, and it matches your instinct: training a ReLU network of depth 2 or more gives an interpolation that is piecewise linear, made of straight pieces that join at kinks. It adds two remarks. The result can be formally proven using convex duality, and for one-dimensional signals it is identical to the result of the Sobolev kernel, a classical way to interpolate. Let us see why the straight answer is special.
Measure how wild a curve is by its energy, the total of its squared slope: E(f) = ∫ f′(x)2 dx. A flat curve has zero energy. A curve that swings up and down has a large slope again and again, so a large energy. Now fix two neighbouring data points, with horizontal gap h and vertical rise Δ. Whatever the curve does between them, its slope must add up to the rise: ∫ f′ dx = Δ.
The Cauchy-Schwarz inequality, a standard fact, says (∫ f′)2 ≤ h ∫ f′2. Put in the rise: Δ2 ≤ h · E. So the energy on this stretch is at least Δ2/h. Equality holds only when f′ is constant, which is a straight line.
From (0, 40) to (2, 55): Δ = 15 and h = 2, so the least energy is 15²/2 = 112.5. From (2, 55) to (5, 66): 11²/3 = 40.3.
So among all curves through the points, connecting the dots with straight lines has the least energy. This energy is the squared norm of a Sobolev space (a family of functions whose slopes have finite energy), and interpolating with the matching kernel returns exactly this curve, which is the slide’s remark. Our RKHS lesson explains why a kernel and a norm go together.
One more link to ReLU. Each hinge is a straight piece that bends at one point, so a sum of hinges is piecewise linear automatically. The lecture’s claim is stronger: when training also keeps the weights small, the network chooses kinks at the data points and lands on this calmest curve.
Here is how a network builds the straight-line answer. Walk along the grade data and write down the slope on each stretch: 7.5 points per hour from 0 to 2 hours, 3.7 from 2 to 5, then −3.0 from 5 to 6, then 7.0. At each data point the slope changes: −3.8 at 2 hours, −6.7 at 5 hours, +10.0 at 6 hours. A hinge placed at a data point changes the slope there by exactly its output weight. So the network needs one hinge per data point, and each output weight is the change of slope at that point. The weights of the calm fit are just the bends of the connected dots.
All three curves pass through every blue point. Choose one and read its energy and its guess at four hours.
Made-up grade points, as in the hero. Straight lines: piecewise linear interpolation. Cubic spline: the natural cubic spline. Degree 9: the single polynomial through all ten points. Energy is ∫ (df/dh)² dh in grade² per hour, from a fine numerical sum of the actual curve. The straight lines give the exact minimum, as the inequality above proves.
The straight lines have the least energy. The cubic spline pays a little more for its smoothness. The degree 9 curve pays a lot, and it swings far outside the grade range near the ends. All three have zero training loss. Only one is the answer the lecture says a ReLU network finds.
This is the first real payoff. A fact about the network (piecewise linear, calmest fit) has become something you can draw and check. The convex program of the next chapters turns it into a general statement for any number of inputs, not only one.
Chapter 5
State the training problem, meet its convex twin, and watch neurons switch off as the penalty grows
Imagine training a network and, before you start, saying how much you dislike large weights. You add a price for every weight, and the price grows with its square. This is weight decay, and nearly every real training run uses some form of it. It is also the key that opens the whole lecture.
The slides write the training problem for a two-layer ReLU network in one line. Here is the same line, with every symbol named.
This is the problem we cannot solve with a guarantee. The ReLU sits between two tables of unknowns, so the cost is not convex in (W1, W2). Slide 26 then makes the surprising claim. Beside it, write a second problem:
The theorem on slide 27 says pnon-convex = pconvex, and that an optimal solution of the non-convex problem can be obtained from an optimal solution of the convex one. It comes from M. Pilanci and T. Ergen, Neural Networks are Convex Regularizers: Exact Polynomial-time Convex Optimization Formulations for Two-Layer Networks, ICML 2020. The title is the claim: the network is a convex regularizer in disguise.
Slide 28 gives the concrete case for squared loss. Take X with n rows, one per data point, and y the labels. The non-convex problem is
min over W1, W2: ‖ ∑j=1m φ(X W1j) W2j − y ‖22 + λ(‖W1‖F2 + ‖W2‖F2)
and the convex problem is
min over ui, vi in K: ‖ ∑i=1p Di X (ui − vi) − y ‖22 + λ ∑i=1p (‖ui‖2 + ‖vi‖2)
Look at the penalty. It is the group L1 penalty from Chapter 3: one length for each block ui or vi, added up. Each block is one candidate neuron. The matrices D1 to Dp are fixed diagonal tables of zeros and ones, and they are what turns the ReLU into something linear. Chapter 7 shows how. For now, read DiX ui as “neuron i’s output, with its on-off pattern frozen”. A constant such as ½ in front of the loss only rescales λ, so we do not track it.
The theorem also tells you how to get the network back. From an optimal non-zero block ui*, set the input weights to W1j = ui*/√‖ui*‖2 and the output weight to W2j = +√‖ui*‖2. From an optimal block vi*, use W1j = vi*/√‖vi*‖2 and W2j = −√‖vi*‖2. A worked case. If u* = (3, 4), its length is 5, so W1j = (3, 4)/√5 and W2j = √5 ≈ 2.24. The two parts are balanced: ‖W1j‖2 = 5 and W2j2 = 5. The neuron’s overall weight, the product of the sizes, is 5. Chapter 6 shows why balanced is the right choice. The u blocks make positive neurons, the v blocks make negative ones.
Slide 29 adds the most useful consequence. As λ grows from near zero to very large, the number of non-zero blocks in the convex solution decreases. And the second theorem on the slide: the optimal solutions of the convex program, over all λ, produce the entire set of optimal architectures f(x) = W2φ(W1x) with m neurons, for m = 1, 2, …. The slide ends with the line that gives the chapter its title: non-convex neural network models actually correspond to regularized convex models.
Read it as a dial. A small λ allows many neurons and a close fit. A large λ allows few and a loose fit. Each setting of the dial is a network with a definite number of neurons. Try it on the grades.
Top: the convex fit with its kept hinges marked in pink. Bottom: the staircase of neurons kept against λ. Drag λ along the staircase.
The same one-dimensional convex program as the hero, restricted to 38 candidate hinges (a kink at each of the ten data points and halfway between, in both directions), so each kept hinge is one neuron. The staircase is computed from 60 solves across the range. Made-up grade points; λ is in the 0 to 1 rescaled units. The error is the root mean square miss over the ten points, in grade points.
At the far left, about twenty hinges give a near-exact fit. Move right and the staircase falls, one step at a time, to a single hinge: a straight line. Each step is a network the non-convex problem could have found, and the convex program lists them all in order, with no random start.
The lecture says this is polynomial-time optimization. The catch is in how many blocks p there are. That is the next chapters’ work: why the penalty becomes a sum of lengths, and how large p can be.
Chapter 6
Rescale each neuron to turn weight decay into an L1 penalty, then use a dual bound to certify the answer
A neuron has two sets of weights that multiply: the input weights w1 inside the ReLU, and the output weight w2 outside. Now ask a strange question. If you make w1 twice as small and w2 twice as big, what changes?
The prediction does not change. A ReLU keeps the scale of what goes in: (xTw1/α)+ = (xTw1)+/α for any α > 0. Multiply by αw2 and the α cancels. This is slides 30 to 32, and it is the lecture’s key trick.
Slide 31 defines the rescaled weights: W̃1j = W1j/αj and W̃2j = W2jαj, one αj for each neuron. The network output does not change. The regularization term does, because weight decay charges for the squares of the weights. For one neuron the charge becomes ‖w1‖2/α2 + w22α2, which is the lecture’s expression on slide 32.
Since every α gives the same prediction, training is free to pick the α with the lowest charge. Write t = α2. The charge is ‖w1‖2/t + w22t. For two positive numbers a and b, a/t + bt is smallest when a/t = bt, and the smallest value is 2√(ab). Here that gives 2‖w1‖·|w2|.
w1 = (3, 4), w2 = 2. Charge now: 25 + 4 = 29. Balanced at α2 = 5/2: charge = 10 + 10 = 20 = 2 × 5 × 2.
The neuron has input weights (3, 4) and output weight 2. Slide α and watch its output stay fixed while its charge moves. Find the lowest point.
Exact arithmetic on one neuron, not the lecture’s picture. The test input is x = (1, −0.5), so xTw1 = 1 and the neuron outputs 2 · (1)+ = 2. The charge shown is ½(‖w1‖²/α² + w2²α²), the weight decay cost with λ = 1.
At the bottom, the charge in the plot is 10, which is the product of the sizes, ‖w1‖·|w2| = 5 × 2. Everything away from the bottom is wasted charge. So after the best rescaling, the penalty on a neuron is its input length times its output size. A product, not a sum of squares.
Now use the same freedom once more. Rescale so every input vector has length exactly one: ‖w1j‖2 = 1. The length moves into the output weight, and the penalty for the neuron is just |w2j|. Slide 30 states the result as a theorem: the weight decay problem equals
min over ‖w1j‖2 = 1, w2 : ‖ ∑j φ(X w1j) w2j − y ‖22 + λ ∑j=1m |w2j|
(The factor 2 from the balance step only rescales λ.) Look at what we gained. The penalty is the L1 penalty of Chapter 3, the one that switches things off. And once the input directions are fixed, the output weights w2 enter linearly: it is exactly a lasso. The only hard part left is choosing the directions w1j. Chapter 7 shows there are finitely many that matter.
Slide 33 writes the problem as p* = min over the directions uj (length at most one), then min over the output weights αj, of ½‖∑(Xuj)+αj − y‖22 + β∑|αj|. Slide 34 then replaces the inner lasso by its dual: a second problem whose answer is always a lower bound on the first. Here is that fact in three lines, for a lasso with feature table Φ (the columns are the neuron outputs).
Take any vector v with every entry of ΦTv between −β and β. Then β‖α‖1 ≥ vTΦα. So the lasso cost is at least ½‖Φα − y‖2 + vTΦα. Write r = Φα − y. The smallest of ½‖r‖2 + vTr + vTy is −½‖v‖2 + vTy, which equals ½‖y‖2 − ½‖v − y‖2.
Every legal v is a certificate. The dual value, the best certificate, equals the lasso’s own best cost (this is strong duality). When the cost you have found and the certificate you have found meet, you know you are done. The device below runs a lasso one sweep at a time and shows both numbers closing in.
Each sweep of coordinate descent lowers the cost (warm line) and raises a legal lower bound (blue line). Drag the number of sweeps.
The lasso over the same 38 candidate hinges on the ten made-up grade points, with β = 0.003. The lower bound uses the legal v = s · (y − Φα), the residual scaled by the largest s ≤ 1 that satisfies the condition. Both numbers are computed exactly from the current weights, in rescaled units.
At sweep 0 the lasso knows nothing, and its certificate is weak. As the sweeps continue the two lines squeeze together. When the gap is tiny, no other set of weights can do meaningfully better. That is what convexity buys: a stopping rule with a proof.
The slide ends with a warning in the notation. Moving the maximum outside, the lecture’s bound has n unknowns (the entries of v) but infinitely many constraints, one for each possible direction u. The lecture calls it a convex semi-infinite program. The way out of infinity is the next chapter.
Chapter 7
Turn each ReLU into a fixed on-off mask, list every mask a dataset allows, and see that the list is short
Stand a neuron in front of three data points. For each point it is either on (it passes the number through) or off (it outputs zero). Write the answer as a list of ones and zeros: (1, 1, 0) means on for the first two points and off for the third. That list is the neuron’s activation pattern.
Here is the idea that drives the whole lecture. Once the pattern is fixed, the ReLU is gone. A ReLU that is on for a point is the identity there. A ReLU that is off is zero there. So the neuron’s output on all the data is a plain matrix product, with the pattern as a diagonal table of zeros and ones.
This is why DiX ui appeared in Chapter 5’s convex program. Each block is a neuron with its mask frozen, a linear thing inside a cone. The remaining question is how many masks there are.
Slides 35 to 39 use three data points in the plane (n = 3, d = 2): x1 = (2, 2), x2 = (3, 3) and x3 = (1, 0). A neuron with weight w = (w1, w2) is on for a point when xTw ≥ 0. Compute each sum. Point 1 gives 2(w1 + w2). Point 2 gives 3(w1 + w2). Point 3 gives w1.
Points 1 and 2 have the same sign, always. Only the sign of w1 + w2 and the sign of w1 matter, and each can be positive or negative. That gives exactly four patterns:
These are the lecture’s four matrices. Find them yourself by turning the direction w in the plane below.
Top: three data points and the line where the neuron switches. Filled pink points are on. Bottom: every direction around the circle, split into the four patterns. Drag the angle.
The data is the lecture’s example: (2, 2), (3, 3), (1, 0). The weight w = (cos θ, sin θ) has length one; only its direction decides the pattern. A point is on when xTw is at least zero. The four wedges are exact: pattern D1 from −45° to 90°, D2 from 90° to 135°, D3 from 135° to 270°, D4 from 270° to 315°.
Slide 39 then writes the full convex program for this example. With D3 dropped, three patterns remain: minimize the squared miss of D1X(u1 − v1) + D2X(u2 − v2) + D4X(u3 − v3) against y, plus λ times the sum of all six block lengths, subject to the cone conditions on each block. The slide notes it is equivalent to the non-convex two-layer problem. Six blocks with two numbers each: twelve unknowns, a small convex problem for any labels y.
Slide 40 gives the general count. Take any data table X with n rows and rank r (the number of independent directions the rows span). The sign patterns {sign(Xw) : w in Rd} number at most 2 ∑k=0r−1 C(n−1, k), which is O((n/r)r). Why? Each data point xi gives one condition xiTw = 0, a flat sheet through the origin in w-space, a hyperplane. n such sheets cut the space into regions, and each region is one sign pattern. This cutting is a hyperplane arrangement.
Check it against the example. Here n = 3 and r = 2, so the bound is 2(C(2,0) + C(2,1)) = 2(1 + 2) = 6. We found four. The bound counts the best case, where no two points line up. Here points 1 and 2 lie on the same ray, so two of the sheets coincide, and the count drops to 4. For our one-dimensional grade data with a bias, r = 2 and n = 10, and the bound gives 2(1 + 9) = 20: one pattern for each threshold in each direction.
The count is polynomial in n for a fixed r, not exponential. Try it.
The warm curve is the largest number of patterns a dataset of n points can allow, written as a power of ten. The grey line is every on-off list, 2n. Choose the rank r and drag n.
Exact evaluation of the bound 2 ∑k=0r−1 C(n−1, k) on slide 40, which holds in the best case where no points line up. Real data can have fewer patterns, as in the three-point example.
With r = 5 and n = 100 points the list has about 8 million patterns (107), large but finite, against about 1030 for every on-off list. In the convex program, each pattern becomes one pair of blocks. That finite list is what removes the infinity from Chapter 6’s dual: the constraint for every direction u splits into one cone for each pattern. The paper’s theorem says the finite problem has the same value, and its dual is the program of Chapter 5.
Chapter 8
Share one small filter across a whole signal to shrink the pattern count, and see pooling turn into a penalty on frequencies
Look at a photograph through a small square window, three pixels wide. Slide the window across the picture. At every position you apply the same weights. This is a convolutional neuron: one short filter, reused everywhere. Audio works the same way, with a short filter sliding along time.
The reuse matters for counting. In Chapter 7, a fully connected neuron had its own weight for each of d inputs, so the data could be cut in as many ways as a d-dimensional arrangement allows. A convolutional neuron has only h weights, where h is the filter size (9 for a 3 × 3 filter), no matter how big the image is.
Slide 41 sets this up. Cut each of the n data points into patches. The patch table is X = [X1, …, XK], where each Xk has n rows and h columns: the k-th patch of every data point. One filter w, with h numbers, is applied to all K patches. The patterns to count are {sign(Xkw) : w in Rh} for k = 1 to K. Stack the K tables on top of each other and you have one table with nK rows and only h columns. Chapter 7’s count applies to it, with rank h:
A worked count. Take 28 × 28 images (d = 784) and a 3 × 3 filter (h = 9). A filter that fits inside the image has 26 × 26 = 676 positions, so K = 676. With n = 1,000 images there are nK = 676,000 patches. The bound is about 2 × C(675,999, 8), around 1042. A fully connected neuron on the same data has rank up to 784, and its bound is about 10300. Both are huge. The first is a power of 676,000 with exponent 9, and the second is nearly every on-off list.
Bars show the largest number of patterns, as a power of ten. Choose the number of images and the image width. The filter is 3 × 3.
The bound 2 ∑k<r C(N−1, k) from slide 40, evaluated exactly. Fully connected: N = n, r = min(n, width²). Convolutional: N = n · (width − 2)², r = 9 (a 3 × 3 filter, valid positions only, no padding). Both are best-case upper bounds on the number of patterns, not the size of an actual training run.
Slide 42 turns this into the headline. A two-layer convolutional network f(x) = W2φ(W1x), with m filters of size h, can be optimized in fully polynomial time. A typical example: 1,024 filters of size 3 × 3, so m = 1,024 and h = 9. The complexity of the convex program is polynomial in all the parameters, n, m and d.
Slide 43 adds pooling (combining the filter’s outputs from nearby positions into one number) and ends with a surprise. The two-layer convolutional network with pooling, in the order convolution, pooling, ReLU, fully connected layer, is equivalent to an L1 penalty. It is a constrained lasso: min over w in K of ‖Φw − y‖22 + λ‖w‖1.
The theorem on the slide states the convex problem in the frequency domain. Let X̃ = XF, where F is the DFT matrix (the table that turns a signal into its frequency coefficients; see our DFT lesson). The equivalent convex problem has the same shape as Chapter 5: a sum over patterns Si of diag(Si)X̃(w′i − wi), a squared miss against y, and a penalty (β/√d) times the sum of the L1 norms of all the wi and w′i, subject to the same cone conditions (2diag(Si) − I)X̃wi ≥ 0. The unknowns wi are complex, one entry per frequency.
Why does a Fourier matrix appear? A convolution that wraps around the end of the signal (a circular convolution) becomes a plain product of coefficients after the DFT: DFT(x ∗ w) = DFT(x) · DFT(w), one frequency at a time. In the frequency domain the filter is a list of gains, one per frequency, and the L1 penalty asks for as few non-zero gains as possible. The sparse thing here is the spectrum.
You can feel that kind of sparsity directly. With an orthonormal DFT, the L1 penalty on the coefficients acts by shrinking each coefficient’s size by λ and cutting it to zero if it is smaller. Use it on a noisy signal made of three tones.
Top: a noisy signal (blue), the clean signal (dashed) and the rebuilt signal (warm). Bottom: the size of each frequency coefficient and the cut-off λ. Raise λ.
Illustrative: 256 samples of three sine tones (bins 5, 12 and 20, amplitudes 1, 0.6 and 0.35) plus seeded noise of standard deviation 0.35; the plot shows the first 128 samples and the first 41 frequency bins. This is soft thresholding of each complex coefficient, the L1 step for an orthonormal DFT. It shows the effect of a penalty on frequencies, and is not the lecture’s full convolutional program.
At λ near 1.2 only three coefficients survive, and the rebuilt line sits close to the clean one. At λ = 0 nothing is removed, and the rebuilt signal is the noisy one. Push λ too high and the weak tone disappears too. That is the penalty dial from Chapter 5 again, now turned on a spectrum.
Chapter 9
Turn a signal into a table of sliding windows, train both ways, and compare what each trainer delivers
An electrocardiogram (ECG) records the electrical activity of the heart as a trace over time. Each beat leaves the same shape: a small bump, a sharp spike, then a slow wave. The spike is the part a predictor finds hardest, because it is tall, thin and arrives fast.
The lecture’s task is signal prediction. Given the last few samples, predict the next one. Slide 44 shows the ECG trace, a window size of 15 samples, and a split into a training part and a test part. The test part is held back: the model never sees it while training, so its error on it is an honest measure.
A neural network wants a table of examples, with inputs and labels. A single trace has neither, so we cut it into overlapping windows. With window size d, the first example uses samples x[1] to x[d] and its label is the next sample, x[d + 1]. The second slides one step: x[2] to x[d + 1], label x[d + 2]. Slide 45 writes the result.
This table is what Chapters 5 to 8 call X, with d columns and n rows. Everything we derived applies to it: patterns come from the rows, and the count depends on the rank r of X. For a window of d samples, r is at most d. The table below the device shows the real numbers.
One failure mode matters here: leaking the test set. Neighbouring windows overlap in d − 1 of their d samples, so a window near the end of the training part nearly equals a window near the start of the test part. The symptom is a test error that looks wonderful. The measurement is to compare a random split against a split in time order: the random one usually gives a lower error, because test windows have near-copies in training. The fix is the one we use: train on the first 60% of the trace and test on the rest, in time order.
The simplest baseline is the linear predictor: the next sample is a weighted sum of the d samples before it, the same weighted sum for every window. It is least squares, as in Chapter 2. It struggles with the spike for a plain reason. The samples just before a spike are almost flat, so no fixed weighted sum can know the spike is coming. A ReLU network can switch on only when the window looks a certain way, and that switching is what the masks of Chapter 7 describe.
Slides 46 and 47 compare the two ways to solve it. The first plot shows the training objective against time. Five runs of stochastic gradient descent on the non-convex problem (five different random starts, drawn in five colours) wobble down and flatten. The convex solution, marked with a cross, sits below where they level off. The second plot shows the test error and tells the same story. Slide 48 zooms into the ECG itself, comparing the true signal with SGD, the convex solution and a Linear predictor, a plain weighted sum of the window, with an inset on one stretch of the trace.
We cannot rerun the lecture’s experiment here. But we can run a small cousin of it live, and the result teaches something the slides cannot. Our convex program is the cheap version from Chapter 10: instead of listing every pattern, we sample 1,500 random neuron directions and solve the lasso over them exactly. The non-convex runs are real networks with 16 neurons, trained for 1,200 steps with Adam. Everything uses the same cost: the fit plus weight decay.
Choose a window size, then press Train both. The plot shows the held-out part of the signal. The bars show how low each trainer got the training cost.
A synthetic heartbeat (a bump, a spike with dips either side, and a slow wave every 80 samples, with seeded noise), not the lecture’s recording. The first 60% of windows train, the rest test. Convex: 1,500 random unit directions, the lasso over them solved to convergence. SGD: 16 neurons, 1,200 Adam steps, four seeds. Same cost for all: ½ squared miss + 0.01 weight penalty. The linear predictor is least squares on the window. Error is the root mean square miss on the test windows, in signal units.
Read the bars at a small window, say d = 3. The convex solve matches or beats every gradient run, and it does so in a single deterministic pass: run it twice and you get the same number. Now move to d = 5 or more. The gradient runs pull ahead. What happened? With more window columns, the space of neuron directions grows, and 1,500 random samples cover it only thinly. The convex program is exact only if it lists the patterns it needs. That is the lecture’s own caveat, and Chapter 10 explains it.
Two honest points follow. First, the lecture’s curves (slides 46 and 47) use the full convex program, which is a richer object than our sampled one, so our device does not reproduce its numbers. Second, our device does reproduce the shape of the trade: the convex route is repeatable and certifiable, while the gradient route varies from run to run and depends on its starting point.
Chapter 10
Open the network into its working pieces, then see how sampling masks makes the convex program cheap
A colleague points at a prediction and asks: why did the network say that? With a standard network, nobody has a good answer. The weights are a pile of numbers, and the training run that produced them was one path among many.
Slide 49 gives the lecture’s reply, in a title: neural networks are fully explainable. It puts the convex program next to a plot of an ECG with a red line drawn through it. The claim is literal, and you can check it by reading the program’s own terms.
The prediction in the convex program is a sum, over the patterns i, of DiX(ui − vi). Because of the group L1 penalty (Chapter 3), most blocks are exactly zero. Each block that survives is one piece, and each piece has two parts you can read off. The mask Di says which data points it covers: the ones in one wedge, on one side of a line. The vector ui says what linear function it applies there. So the network is a short list of rules of the form: “for inputs on this side of this line, add this much times a weighted sum.”
Take the grades again. In one dimension, a piece is a hinge. Its mask is the set of points past one kink. Its weight is a slope. At the device’s starting setting the fit has three kept pieces, and they read as three sentences: “after 0 hours, add 4.3 grade points per hour of slope; after 8 hours, add 0.6 more; before 8 hours, take away 0.3.” That is the full model, with nothing hidden. Choose λ and read it.
The warm curve is the whole network. Each thin pink line is one neuron’s own contribution. The list below says what each one does. Drag λ.
The one-dimensional convex program on the ten made-up grade points, restricted to 38 candidate hinges. Each neuron’s slope is converted to grade points per hour from its exact weights (grades 40 to 100 and hours 0 to 12 are rescaled to 0 to 1 inside). A slope of a left-pointing hinge is the slope on its left side.
At large λ the list is one or two lines and the model is nearly a straight line. At small λ the list grows and the fit follows every wiggle. At every setting you can read the model aloud, a property most neural networks lack. It also tells you what the trained network did not use: every neuron missing from the list was switched off by the penalty.
Going from a kept block back to a rule is a small calculation. Suppose a kept neuron has unit input weight (c, b) = (0.83, −0.55) in the rescaled units and output weight 0.05. Its kink sits where c x + b = 0, at x = 0.55/0.83 = 0.66, which is 8 hours. The slope it adds is a times c, 0.05 × 0.83 = 0.042 in rescaled units, which is 5 × 0.042 = 0.21 grade points per hour (rescaling grades by 60 and hours by 12). So the pair of numbers (c, b) names where the rule starts, and a names how strongly it acts.
This is also why the explanation is honest about its limits. A piece acts only inside its wedge: the mask Di multiplies it by zero everywhere else. So each sentence in the list carries its own range of validity. You never have to ask which neurons fire for which input: the mask answers it for the whole training set.
There is a cost. Chapter 7 counted the patterns: up to O((n/r)r), polynomial but large when r is big. Slide 50 offers a shortcut. Instead of listing every mask, sample them. Draw random directions u from a standard Gaussian (a bell-shaped random draw in every coordinate), and keep each mask D = diag(Xu ≥ 0) that appears. Solve the convex program over only those masks.
The slide states a guarantee: a (1 + σr+1/λ)-approximation in O((n/r)r) complexity. The slide does not define σ; in the paper it is a singular value of X, a measure of how far the data is from having rank r. We read it that way and rely on the slide for the statement. The slide ends with the sentence that connects everything: backpropagation (gradient descent) on the non-convex loss is a heuristic for the convex program.
Why would random directions find the right masks? A random direction lands in a wedge with a probability proportional to the wedge’s angle. Wide wedges are found fast. Narrow wedges hide. This is also what went wrong at large windows in Chapter 9. Play it out on the grades, where there are exactly 20 masks.
The ring is every direction of a neuron on the grade data. Each arc is one mask. Warm arcs have been found by your random draws, grey arcs are still hidden. Drag the number of draws.
Illustrative sampling on the ten made-up grade points with a bias, so each neuron has two weights and its direction is an angle. Patterns are counted exactly by sweeping the angle in steps of 0.1 degrees; a random Gaussian direction is uniform around the ring. Each press of Draw again uses a new seeded sequence of 200 draws.
The first few draws find the wide wedges. The last few masks take many more draws, because their arcs are thin. That is the price of sampling: cheaper, and incomplete in a way that is easy to measure.
Chapter 11
Walk the whole recipe once more, keep the numbers and terms, and carry the core into code
Here is the lecture in one paragraph. A two-layer ReLU network trained with weight decay looks like a hard, non-convex search with many zero-loss answers. Rescaling each neuron turns weight decay into an L1 penalty. Each ReLU becomes a fixed on-off mask, and a dataset allows only a polynomial number of masks. So the same problem, exactly, is a convex group-lasso over those masks. Its kept blocks are the network’s neurons, a short readable list. Sampling the masks makes it cheap, and gradient descent is a heuristic for it.
Six steps from data to network, with the numbers from this lesson’s grade example. Step through with the buttons.
Numbers come from the one-dimensional demo on ten made-up grade points: a table with a bias column, 20 masks (the bound 2(1 + 9) from Chapter 7), 38 candidate hinges, and the convex solution at λ = 0.01 in rescaled units, computed live.
| What | Number or form | Why it matters |
|---|---|---|
| The network | f(x) = ∑j=1m wj(2)(xTwj(1))+; W1 is d × m, W2 is m × 1 | The only model the theorem covers |
| The theorem | pnon-convex = pconvex (Pilanci and Ergen, ICML 2020) | A non-convex problem and a convex one with the same value |
| Soft threshold | x* = sign(y)(|y| − λ)+; y = 0.8, λ = 1 gives 0 | Why L1 gives exact zeros |
| Balanced neuron | min charge = 2‖w1‖·|w2|; (3, 4) and 2 give 20 | Weight decay becomes an L1 penalty |
| Convex program | ‖∑ DiX(ui − vi) − y‖2 + λ∑(‖ui‖ + ‖vi‖) | Group sparsity picks the neurons |
| Masks | at most 2∑k<r C(n−1, k) = O((n/r)r); n = 3, d = 2 gives 4 (bound 6) | Finite and polynomial for fixed rank |
| Convolutions | O((nK/h)h); 1,024 filters of 3 × 3 (m = 1,024, h = 9) | A small filter keeps the count low |
| Piecewise linear | depth 2 or more, one-dimensional signal: Sobolev kernel answer | The calm fit between data points |
| Adversarial example | panda 57.7% becomes gibbon 99.3% (Goodfellow and colleagues, 2015) | Small pushes add up over many inputs |
| Approximation | (1 + σr+1/λ) in O((n/r)r) (slide 50) | Sampling the masks is cheap and bounded |
| Term | Plain meaning |
|---|---|
| Convex | One valley. Every local minimum is the global one. |
| Weight decay | A price on the squared size of all weights. |
| L1 and group L1 | A price on size that sets numbers, or whole blocks, exactly to zero. |
| Activation pattern | The on-off list of one neuron across the data points. |
| Mask D | A diagonal table of that list. It turns a ReLU into a matrix product. |
| Cone | The set of weights that give one pattern. Closed under scaling. |
| Hyperplane arrangement | The cutting of weight space by one sheet per data point. |
| Dual | A second problem whose answer is always a lower bound on the first. |
| Regularization path | The solutions as the penalty grows: fewer and fewer neurons. |
This sketch is the restricted program of our devices: sample directions, keep unit-length input weights, solve one lasso, and unpack the kept neurons. It is not the lecture’s exact program, which also carries the cone constraints on each block.
pythonimport numpy as np from sklearn.linear_model import Lasso def convex_two_layer(X, y, lam, p=2000, seed=0): """Sampled convex program for a two-layer ReLU net.""" rng = np.random.default_rng(seed) X1 = np.hstack([X, np.ones((len(X), 1))]) # n x (d+1), the bias as a column U = rng.standard_normal((X1.shape[1], p)) # sampled neuron directions (Ch 10) U /= np.linalg.norm(U, axis=0) # unit input weights (Ch 6, step 2) F = np.maximum(X1 @ U, 0) # n x p, each column a masked neuron (Ch 7) a = Lasso(alpha=lam / len(y), fit_intercept=False, max_iter=50000).fit(F, y).coef_ # the L1 penalty (Ch 3, 6) keep = np.flatnonzero(a) # neurons the penalty left on W1 = U[:, keep] * np.sqrt(np.abs(a[keep])) # balanced split (Ch 5, 6) W2 = np.sign(a[keep]) * np.sqrt(np.abs(a[keep])) return W1, W2 # f(x) = relu([x, 1] @ W1) @ W2
This lecture joins two threads of EE269. One is optimization: convex duality, which gave us the dual bound of Chapter 6. The other is learning: neural networks and deep learning. The sibling lessons support vector machines, kernels and RKHS show the other convex models the lecture calls well understood.
Credit. The lecture is Lecture 16 of Stanford EE269, by Mert Pilanci (18 November 2020). The course site lists the full course and the slides page has the deck. Every device on this page is our own, and every toy number is labelled where it appears.
Now press Present or Teach and explain the recipe out loud, from memory: the two problems, the rescaling, the masks, the count, and the gap between the sampled program and the full one. Then go back to the grade fit at the top and ask why the convex answer never changes.