AI & machine learning / The perceptron

The perceptron

One artificial neuron, worked by hand: a weighted sum, a threshold, the rule that lets it learn OR in four updates, and the XOR problem that a single unit can never solve.

Beginner7 steps~6 min
Input — a number fed into the unit
Unit — adds weighted inputs, answers 0 or 1
Examples — filled should be 1, hollow should be 0
Boundary — the line where the weighted sum is 0
// THE SHORT VERSION

In 30 seconds

A perceptron multiplies each input by a weight, adds them up with a bias, and outputs 1 if the total is above zero, otherwise 0. Seen on a graph, it draws one straight line and answers by side.

It learns from mistakes: each wrong answer nudges the weights towards the right one, and the line shifts.

That only works when a single line can separate the two answers. XOR cannot be split that way, so one unit fails, but several units stacked in layers succeed. That stack is a neural network.

The perceptron, step by step

STEPS01 / 07

The learning rate is fixed at 1 and the examples are visited in the order (0,0), (0,1), (1,0), (1,1). Another order or starting point can end on a different, equally valid line.

STEP 01 / 07 One unit, one decision
THE MATH
inputs: x1, x2 weights: w1, w2 bias: b output: y = 0 or 1
  1. Step 1: One unit, one decision. A perceptron is one artificial neuron. Numbers come in, each is multiplied by a weight that says how much it matters, a bias is added, and the unit answers yes (1) or no (0). Frank Rosenblatt described it in 1958 as a machine that could learn its own weights.
  2. Step 2: Weighted sum, then threshold. Take weights 1 and −1, bias −0.5, and feed in x1 = 0, x2 = 1. The weighted sum is −1.5. The threshold rule is blunt: above zero the unit outputs 1, otherwise 0. So here it says 0. A negative weight makes an input count against firing.
  3. Step 3: The unit draws a line. Plot every possible input as a point. The inputs where z is exactly 0 form a straight line, and the unit says 1 on one side of it and 0 on the other. Our task is OR: answer 1 when at least one input is 1. With these starting weights two of the four points are on the wrong side.
  4. Step 4: Learn from one mistake. The learning rule only acts on mistakes. Point (0,1) should give 1 but gave 0, so the error is +1: add the input to the weights and 1 to the bias. Had the unit said 1 when it should say 0, it would subtract instead. The line swings: (0,1) and (1,1) are now right, but (0,0) has become wrong.
  5. Step 5: Repeat until no mistakes. Go through the four examples again and again, applying the same rule to each mistake. Here four updates are enough: with weights 1 and 1 and bias −0.5 a full pass produces no errors and learning stops. If a separating line exists, the rule is guaranteed to find one after a finite number of updates.
  6. Step 6: What one line cannot do. A task is linearly separable when one straight line puts every 1 on one side and every 0 on the other. OR and AND are. XOR, which is 1 when exactly one input is 1, is not: its 1s sit on opposite corners, so any line gets at most three of four right. Minsky and Papert’s 1969 book made this limit famous.
  7. Step 7: Stack units into a network. Feed the inputs to two units, one acting as OR and one as AND, and let a third combine them: OR but not AND, which is XOR. Units stacked in layers can draw boundaries no single line can, and that is the building block of neural networks. These weights were set by hand; training hidden layers took a later method, backpropagation.
VALUES SO FAR
w1, w2····start
b····start
wrong····start
w1, w2····update 1
b····update 1
w1, w2····final
b····final
XOR····limit
layers····result

Spotted a mistake on this page?