The update rule was stated without a reason. Let us get one, using a little linear algebra.
The weighted sum is a dot product
With weights and an example , the weighted sum is the dot product
So the perceptron rule is just: output 1 if , output 0 if .
Angles decide the side
The dot product is also , where is the angle between the two vectors. Since lengths are positive, the sign of is the sign of . Therefore:
- means : the example is on the positive side,
- means : the example is on the negative side,
- means : the example lies on the boundary.
The last line says something about the boundary : every point on it is perpendicular to . So the weight vector is orthogonal to the decision boundary, pointing into the positive side.
So learning has a clear target: make every positive example within of and every negative example beyond .
What the update does
Missed positive (, but it should be at least 0). We set . Then
The score for this example rises by , which is always positive. The example has moved toward the correct side. Geometrically, adding tilts toward , so the angle between them shrinks.
Accepted negative (, but it should be negative). We set , so
and the score falls by , pushing the example toward the negative side.
A single step need not fully fix the example, because the score may still be on the wrong side. It only moves it in the right direction. The algorithm keeps cycling through the data, so later steps finish the job.
There is a catch. Fixing one example can hurt another that was already correct, since the same serves them all. Nothing so far says the algorithm cannot go round in circles. The next lesson shows that it cannot, when the data is separable.
A full run on AND
Let us run the algorithm by hand. Write each example with its leading 1, so AND has the points , , with label 0 and with label 1. Start from and go through the examples in this order every pass. Note that with , every score is , which counts as 1.
Pass 1
| Example | Label | Score | Action | New |
|---|---|---|---|---|
| (1,0,0) | 0 | 0 (predicts 1) | subtract | (−1, 0, 0) |
| (1,0,1) | 0 | −1 (predicts 0) | none | (−1, 0, 0) |
| (1,1,0) | 0 | −1 (predicts 0) | none | (−1, 0, 0) |
| (1,1,1) | 1 | −1 (predicts 0) | add | (0, 1, 1) |
Pass 2
| Example | Label | Score | Action | New |
|---|---|---|---|---|
| (1,0,0) | 0 | 0 (predicts 1) | subtract | (−1, 1, 1) |
| (1,0,1) | 0 | 0 (predicts 1) | subtract | (−2, 1, 0) |
| (1,1,0) | 0 | −1 (predicts 0) | none | (−2, 1, 0) |
| (1,1,1) | 1 | −1 (predicts 0) | add | (−1, 2, 1) |
Passes 3, 4 and 5 continue the same way. After pass 5 the weights are , and pass 6 makes no corrections, so the algorithm has converged. Check it:
| Input | Score with | Output | AND |
|---|---|---|---|
| (0,0) | −3 | 0 | 0 |
| (0,1) | −2 | 0 | 0 |
| (1,0) | −1 | 0 | 0 |
| (1,1) | 0 | 1 | 1 |
All four are right. The boundary is a different line from the textbook one, but it separates the classes just as well. There are many valid answers, and the algorithm stops at the first one it finds.
Watch the weight vector turn after each mistake, and check that the angles end up on the correct sides.