Perceptron Algorithm for Halfspaces
The Perceptron algorithm alternates between checking the training examples and updating its weight vector.
The Learner’s Main Loop
The Perceptron is a learner that repeatedly checks labeled training examples against its current weight vector. It starts with a zero vector. If an example fails the required positive condition, the Perceptron changes its weights using that example. If no example fails, it stops and outputs the current weight vector.
Checking the Update Condition
At iteration t, the Perceptron looks for a training example (xi, yi) satisfying yi〈w(t), xi〉 ≤ 0. Here, w(t) is the current weight vector, xi is the selected feature vector, and yi is its label. Finding such an index means the current vector has not achieved the required strictly positive condition for that example, so an update is performed.
The update condition is not checked on an arbitrary unlabelled input. The selected index i matters because the Perceptron adds the matching product yi xi.
yi〈w(t), xi〉 ≤ 0
Tracing One Update
Applying the update to a selected example
Suppose the current vector is w(t) = (1, 0), the selected input is xi = (1, 2), and its label is yi = -1. Determine whether the Perceptron updates and calculate w(t+1).
Check the signed inner product: The inner product is 〈(1, 0), (1, 2)〉 = 1. Multiplying by yi = -1 gives yi〈w(t), xi〉 = -1.
Test the condition: Because -1 ≤ 0, this example satisfies the update condition.
Add the labelled input: Compute yi xi = -1(1, 2) = (-1, -2).
Form the next vector: Use w(t+1) = w(t) + yi xi = (1, 0) + (-1, -2).
w(t+1) = (0, -2), so the Perceptron updates.
Online Prediction Rounds
The Perceptron can also be viewed as an online learner. On round t, it first receives one input vector xt from R^d. It uses the current weight vector w(t) to predict a label, and only afterward receives the true label yt. The true label is feedback after the prediction, not information used to produce that same prediction.
pt = sign(〈w(t), xt〉)After the prediction, the learner compares pt with the revealed true label yt. A prediction mistake occurs when the predicted label does not match the true label. The current weight vector and the incoming input therefore determine the prediction, while the later label reveals whether that prediction was correct.
When the Algorithm Converges
For separable data, the Perceptron converges within at most (RB)^2 iterations. The quantity R is the maximum norm of the feature vectors xi. The quantity B is the minimum norm of a vector w satisfying yi〈w, xi〉 ≥ 1 for every training example.
The stopping condition and the convergence statement describe the same successful outcome from two views. Algorithmically, the Perceptron stops when no example satisfies yi〈w(t), xi〉 ≤ 0. Equivalently, every training example then satisfies yi〈w(t), xi〉 > 0.
Mistakes to Catch
Updating when the condition is not satisfied.
The Perceptron updates only when some example satisfies yi〈w(t), xi〉 ≤ 0.
Fix:
Check the inequality first, and stop if no example satisfies it.Adding xi instead of yi xi.
The label determines the signed contribution of the selected example.
Fix:
Use w(t+1) = w(t) + yi xi for the same selected index i.Stopping immediately after an update.
An update changes the current vector but does not establish that all examples now satisfy the positive condition.
Fix:
Return to the checking step after every update.Using the true label before making an online prediction.
In the online sequence, xt arrives first, the learner predicts, and yt is revealed afterward.
Fix:
Compute pt from w(t) and xt, then use yt as feedback.
Limits of General Guarantees
The convergence guarantee for separable training data should not be confused with a finite mistake guarantee for every possible online sequence in the stated class. When the dimension d is at least 2, the Littlestone dimension is infinite, so few-mistake guarantees are unavailable for that class.
The source attributes this infinite Littlestone dimension to the density of the real numbers. It describes a shattered tree built from vectors including (1/2, 1, 0, ..., 0), (1/4, 1, 0, ..., 0), and (3/4, 1, 0, ..., 0). The hypotheses use parameter vectors of the form (-1, a, 0, ..., 0), where a ranges over [0, 1]. This construction supports the conclusion that no finite mistake bound applies generally when d is at least 2.
Practice Check
A Perceptron currently has w(t) = (2, 1). A selected example has xi = (1, -1) and yi = 1. Decide whether an update occurs. If it does, calculate w(t+1). Then state what the learner must do after this update.
Hints
- First calculate 〈w(t), xi〉.
- Multiply the result by yi and compare it with zero.
- If an update occurs, add yi xi to w(t).
- The learner checks again after updating.
What do you think happens?
On an online round, the learner has received xt but has not yet received yt. Can it determine whether its prediction is a mistake?
Reveal answer
Answer: No, because the true label is revealed only after the prediction.
The Perceptron predicts from w(t) and xt first. It can evaluate whether a mistake occurred only after yt is revealed.
Key Takeaways
- The Perceptron begins with a zero weight vector and checks whether any example satisfies yi〈w(t), xi〉 ≤ 0.
- When such an example is found, the update is w(t+1) = w(t) + yi xi using the selected example's label and input.
- The algorithm checks again after an update and stops only when every example satisfies yi〈w(t), xi〉 > 0.
- For separable data, convergence occurs within at most (RB)^2 iterations, with R defined from the feature-vector norms and B from the separating-vector condition.
- In online learning, the learner receives xt, predicts using sign(〈w(t), xt〉), then receives yt and checks for a mistake; when d is at least 2, infinite Littlestone dimension prevents a finite general mistake guarantee.
Key Takeaways
- The Perceptron alternates between checking examples and updating its weight vector.
- An update occurs exactly when some example satisfies yi〈w(t), xi〉 ≤ 0, and the update adds yi xi.
- Online prediction uses the current weights and input before the true label is revealed.
- For separable data, the algorithm converges within at most (RB)^2 iterations.
- When d is at least 2, infinite Littlestone dimension means that no finite mistake guarantee applies to every sequence in the stated class.