Why the perceptron works
Last updated
Lesson 5.2's perceptron stopped after a few updates on one pair of species and never stopped on another. Is that luck? In 1962 Albert Novikoff proved it isn't: if a line separates the data with some room to spare, the perceptron will find a separating line after a limited number of mistakes, and the limit depends only on how much room there is. This lesson states the theorem, proves it in four lines, and counts mistakes against it.
By the end of this lesson you can
- Define linearly separable data and its margin
- State Novikoff's bound, and say what it needs and what it doesn't depend on
- Follow the four-line proof
- Compare the bound with real mistake counts as the margin shrinks
Linearly separable data
Data with two classes is linearly separable if some line (in more dimensions, some hyperplane) has every example of one class on one side and every example of the other class on the other. Adelie and Gentoo penguins, by bill depth and flipper length, are; Adelie and Chinstrap, by bill length and depth, aren't (lesson 5.2). XOR's four points aren't either (lesson 5.1).
To keep the maths short, this lesson leaves out the bias, so every line passes through the origin. That costs nothing: add a feature that's always 1, and its weight does the bias's job. A line through the origin is then described by a vector at right angles to it, and says which side is on.
The margin
Suppose a unit vector (length 1) separates the data. For a unit vector, is the distance from to the line. The margin (gamma) is the smallest of those distances: how close the nearest example comes to the line. In symbols, every example satisfies
which says it's on its correct side, at least away. A big margin means an empty street between the classes, like the SVM's in lesson 4.7; a small margin means some examples almost touch the line.
The other number is , the distance from the origin to the farthest example: for every . It measures how spread out the data is.
200 points in a disc of radius 1, kept only if they're at least 0.2 from the true line, with half of them just outside that distance. and .
Novikoff's bound
Novikoff's theorem (1962). If every example has , and some unit vector separates the data with margin , then the perceptron, started at with any learning rate and visiting the examples in any order, makes at most
mistakes. After that many, it can't make another, so every pass is clean and it stops.
For the data above, the bound is . The perceptron made 2.
Look at what the bound doesn't depend on: the number of examples, the number of features, the order of the examples, or the learning rate. A million examples in a thousand dimensions are no harder than 200 in two, if the ratio is the same. Only the shape of the data matters: how wide the gap is, compared with how spread out the points are.
And what it needs: a margin greater than 0, which means linearly separable data. On Adelie against Chinstrap there's no at all, so the theorem says nothing, and lesson 5.2 found the mistakes never stop.
Why it's true, in four lines
This step is optional. The idea: every mistake makes point more along , quickly, but makes longer only slowly. Since a vector can't point along by more than its own length, there can only be so many mistakes.
Let be the weights after mistakes, with and . The -th mistake is on some example , so , and the rule sets .
- It turns towards . . Each mistake adds at least , so .
- It grows slowly. , because the middle term is on a mistake. So .
- Put them together. For a unit vector, (lesson 1.3: a dot product is at most the product of the lengths). So .
- Solve for . Divide by : , so .
With a learning rate , every is just times as big, and the same four lines go through. That's why the bound doesn't care about .
Counting mistakes
The bound is a guarantee for the worst case. How close does a real run come? Shrink the margin and count:
The shaded band is the margin: no point is closer than 0.2 to the true boundary. R = 0.996. The perceptron made 3 mistakes before a clean pass; the theorem promises at most 25. Make the margin smaller and watch both numbers.
The same in NumPy, for five margins:
As the margin shrinks from 0.4 to 0.02, the mistakes grow from 1 to 25, and the bound from 6 to 2,485. Two things to see:
- The bound holds, every time, as the proof says it must.
- It's very loose. It's the worst case over every possible order of examples, and a shuffled order is nowhere near the worst. Real counts are usually far smaller. The bound's real value is what it says about why: a wide margin makes learning easy, and a thin one makes it hard.
That idea outlived the perceptron. The SVM (lesson 4.7) chooses the widest margin on purpose, and margins are still one of the main ways of explaining why a classifier does well on new data (Freund and Schapire, 1999).
Check what you learned
Sources
Every example on this page was run with Python 3.14, and its output and error messages are copied from it. These pages cover the same ground in more depth.
- Block, The perceptron: a model for brain functioning. I, Reviews of Modern Physics 34, 1962: one of the first convergence proofs, published the same year as Novikoff's
- Freund and Schapire, Large margin classification using the perceptron algorithm, Machine Learning 37, 1999: Novikoff's theorem restated and proved, and what margins say about new data
- Rosenblatt, The perceptron: a probabilistic model for information storage and organization in the brain, Psychological Review 65(6), 1958: the rule the theorem is about