TL;DR

  1. Linear classifier without offset: . A point is classified correctly iff .
  2. Perceptron: start at ; whenever (a mistake), update . This is SGD with step size 1 on the linear loss .
  3. The distance of to the hyperplane is (signed with the label); the margin is the smallest distance of a training point: .
  4. Theorem 1 (Novikoff 1962): if and some separates the data with margin , the perceptron makes at most mistakes. The bound does not depend on the dimension.
  5. Theorem 2: trained until 0 training errors, the perceptron’s test error is at most : a fast rate , again dimension-free. The proof uses the leave-one-out principle, an early form of stability.
  6. Without separability there is no convergence; with the hinge-type slack one gets (Freund and Schapire 1999).

Exam relevance

  • Mock exam, task 1 (2 P): run the perceptron by hand on three points in without offset, starting at , sweeping until a full sweep makes no update, counting as a mistake, and filling in a worksheet. Train it with the task below and the widget.
  • Computations: distance to a hyperplane, margin of a given , the mistake bound , the generalization bound for given , , .
  • Multiple choice: what the bound depends on (not on ), which loss the perceptron minimizes, rate , the role of the learning rate.
  • Sheet 4, Exercise 1: margin perceptron (updates while , bound ).

Overview: 1. The perceptron algorithm, 2. The perceptron minimizes the linear loss by SGD, 3. Margin and the mistake bound, 4. Generalization error of the perceptron, 5. Outlook: the non-separable case.

The perceptron algorithm

Linear classification

Slides 3-5

(Literature: Hardt and Recht Sec. 3, Mohri Sec. 7.1, Shalev-Shwartz and Ben-David Sec. 21.4.) This lecture is a warmup: a first, simple example of how one can prove that a learning algorithm works.

Linear classifier without offset

Training points with labels . We study

without an offset parameter : the separating hyperplane passes through the origin.

Correct classification

A point is classified correctly .

A line through the origin with normal vector w; on the side w points to, the inner product with w is positive, on the other side negative
Slide 5: w is the normal vector of the hyperplane; ⟨w, x⟩ > 0 on the side it points to.

The perceptron algorithm

Slide 6

Require: (x_1, y_1), ..., (x_n, y_n)
 1: w_0 ← 0
 2: t ← 1
 3: N ← n
 4: while t ≀ N do
 5:     if y_t ⟨w_{t-1}, x_t⟩ ≀ 0 then     β–· x_t is wrongly classified
 6:         w_t ← w_{t-1} + y_t x_t          β–· update w
 7:     else                                  β–· x_t is correctly classified
 8:         w_t ← w_{t-1}                     β–· keep current w
 9:     end if
10:     t ← t + 1
11: end while

As written, the algorithm makes one pass through the points. To reach 0 training errors, one cycles through the data again and again until a full pass (a β€œsweep”) makes no update. This is the version used in the mistake bound and in the exam.

Ties count as mistakes

The condition is , with "". At the start , so : the first point always triggers an update. With "" the algorithm would never leave .

Run the perceptron step by step, one sweep at a time or until convergence. The log on the right is the worksheet of the exam task. Click in the plane to add your own points. The cards show R, the best margin ρ of any line through the origin and the bound R²/ρ².

Task: the perceptron by hand

Exam-style task: the perceptron by hand (4 P)

Points in , no offset: with , with , with . Start with , sweep in the order and repeat until a full sweep makes no update. Count as a mistake; on a mistake set .

(a) (2 P, easy) Carry out the run: for each step give , whether it is a mistake, and afterwards.

(b) (1 P, harder) separates the data. Compute , the margin of and the mistake bound. Is your run consistent with it?

(c) (1 P, transfer) Run the update with instead. How many mistakes are made, and what is the final ?

Perceptron performs linear loss minimization

The linear loss

Slides 7-9

0-1 loss and linear loss

The β€œnatural” loss for classification is the 0-1 loss: if and 1 otherwise. To quantify β€œhow wrong” the function is, one can use the linear loss

Loss over the margin y times inner product: the 0-1 loss is 1 for negative margins and 0 for positive ones; the linear loss is 0 for positive margins and grows linearly for negative margins
Slide 9: the linear loss is 0 on correctly classified points and grows linearly with how far a point is on the wrong side.

Linear loss minimization by SGD

Slides 10-12

Goal: find the linear classifier that minimizes the empirical risk

with the linear loss. How would we solve this, and how is it related to the perceptron?

Gradient descent and stochastic gradient descent

Minimize over (loss differentiable in ).

  • Gradient descent: start with some , compute , update with step size (learning rate) .
  • Stochastic gradient descent (SGD): start with some , pick a random , compute only and update .

Perceptron runs SGD with the linear loss

Slides 13-14

Gradient of the linear loss

An SGD step with is on a mistake and no change otherwise: exactly the perceptron update.

So the perceptron performs a simplified version of SGD (step size , one pass through the training points, in order). At the loss has a kink; the case β€œotherwise” takes there, which is why ties trigger an update.

By itself this doesn’t mean a lot. Two questions remain: (1) does it really converge to an ERM classifier that minimizes the training loss? (2) what about the test error?

Mistake bound for the perceptron

Distance of a point to a hyperplane

Slides 15-17

We want to prove: if the training points are β€œwell separable”, the number of updates needed to find a classifier with 0 training error is bounded. First we make β€œwell separable” precise.

Distance to the hyperplane

Let be the hyperplane with normal vector , a point with , the closest point to and the distance. Then , and since :

If , then . For a correctly classified labeled point both cases are

Point x on the positive side, its projection h onto the hyperplane H, and the step r times w over norm w from h to x
Slide 17: x = h + r Β· w/β€–wβ€–.

The margin of a separating hyperplane

Slide 18

Margin

For training points and a linear classifier that separates them, the margin is the smallest distance of a training point to the hyperplane :

Mini example

, . The point with has distance . The point with has distance . The margin of on these two points is . Scaling does not change distances or the margin.

Theorem 1: the perceptron mistake bound

Slides 19-23

Theorem 1 (perceptron mistake bound, Novikoff 1962)

Let with for all . Assume there is a separating hyperplane induced by with margin on the training points. Then the number of mistakes of the perceptron is at most

In particular, after at most updates the perceptron has found a linear classifier with 0 training errors.

Intuition

Every mistake pushes a bit towards (the projection onto grows by at least ), but the length of grows slowly (its square by at most ). After mistakes the projection is while the length is . A projection can never be longer than the vector, so , i.e. .

Trap

On slide 20 the condition used in step 1 is written as "". What the proof needs is the mistake condition , which makes the cross term non-positive.

Discussing the bound

Slide 24

  • The bound does not depend on the dimension .
  • Implicit in the proof: SGD does not pick just any ERM minimizer, it picks a special one with nice guarantees. This is implicit regularization of SGD, which comes back in Lecture 8.
  • The bound only holds under the assumption on the data (a margin). Margins pop up in many places in ML: SVMs, boosting (Lecture 6).
  • The theorem only covers the separable case. In the non-separable case (or with margin 0) no bound exists.
  • Learning rate in : see the assignment (and part (c) of the task above).
  • The bound only considers training errors. What about generalization?

Task: margin and mistake bound

Exam-style task: margin and mistake bound (4 P)

Training data: and with label , and with label . Two candidate normal vectors: and .

(a) (1 P, easy) Compute the margin of and of on the data.

(b) (1.5 P, harder) Compute and the best mistake bound you can derive from or .

(c) (1.5 P, transfer) A new point with label is added. Is the data still separated by ? What happens to the bound, and why can a single point make it much worse?

Generalization error of the perceptron

Assumption: the distribution is linearly separable

Slides 25-26

To prove a generalization bound we make a strong assumption:

  1. A deterministic function produces the true labels, .
  2. The sets and are linearly separable: some hyperplane with parameters has them on different sides.
Two regions X plus and X minus separated by a line
Slide 26: the positive and negative regions of the input space are linearly separable.

Theorem 2: bounding the test error

Slide 27

Theorem 2 (generalization error of the perceptron)

Let on be perfectly separable by a hyperplane and i.i.d. from . Let be the perceptron trained on until it makes no mistakes on . Let be the radius of the ball containing all points of , and the largest margin any hyperplane achieves on . Then the probability that the classifier trained on errs on the new point is

Discussion: scaling with and

Slides 28-29

  • The generalization error does not depend on the dimension of the space. That is cool.
  • Suppose the distribution lives in a ball of radius and a hyperplane separates all points of with margin . Then for all sets : and , so

Fast rate

The generalization error (0-1 loss) decreases with rate . In learning theory this is called a fast rate. (Typical rates in Lecture 3 are .)

Trap

Slide 29 writes the ratio without squares, . Theorem 2 has ; the squares matter in computations (halving the margin quadruples the bound).

Proof: the leave-one-out argument

Slides 30-33

The leave-one-out principle and stability

Slides 34-35

Leave-one-out principle

The average leave-one-out error on a sample of size is an unbiased estimate of the average generalization error for samples of size . (Proof: Holin p. 69/70, Lemma 4.1.)

The proof technique also hints at a principle we discuss in detail later: stability (Lecture 4). Stability asks how much the result of a learning algorithm changes if we remove one training point or replace it by a different one. With this technique one can prove very strong generalization bounds.

Task: the generalization bound

Exam-style task: generalization bound (4 P)

The data lies in a ball of radius , and a hyperplane separates the whole input space with margin . The perceptron is trained on points until it makes no training errors.

(a) (1 P, easy) Bound the test error for .

(b) (1.5 P, harder) How many training points guarantee a test error of at most ?

(c) (1.5 P, transfer) The same problem is embedded in instead of (extra coordinates are 0), and separately the margin is halved. How do the answers of (b) change?

Outlook: what if the data is not linearly separable?

Slide 36

Then one can prove more general versions of the theorem.

Mistake bound in the non-separable case (Freund and Schapire 1999)

Given a margin , define the hinge-type loss of a point and the total slack

Then the number of updates of the perceptron is bounded by

(proof in the Mohri book). The generalization bound in this case is more complicated and only scales as .

For separable data with margin under , all , so and the bound is Theorem 1 again.

Summary

ResultStatementDepends on
Perceptron updateon : SGD, , linear loss
Distance, margin, invariant to scaling
Theorem 1 (mistake bound) and , not or
Theorem 2 (test error)rate , dimension-free
Non-separableslack ; test error only

Self-Test

Multiple Choice

References