School/✦ Research Engineer/Elective · AIP-520
The perceptron: one neuron draws one line
The first learning machine, built in 1958, could tell shapes apart by nudging a few numbers. What exactly was it nudging, and what could it never learn?
About 40 min · 3 goals · Checked by automated tests
1.Why should I care?
Every neural network, from a keyword spotter on a microcontroller to a large language model, is built from units that compute a weighted sum and pass it through a simple function. The perceptron is that unit at its plainest. Understanding what one neuron can and cannot separate tells you why networks need layers, and how few multiplications a tiny on-device classifier really needs.
- ◇ Compute a perceptron's weighted sum and output from weights, bias and inputs.
- ◇ Interpret w·x + b = 0 as a decision boundary and say what the weights and bias do to it.
- ◇ Apply the perceptron learning rule and explain why it cannot learn XOR.
2.Predict
A perceptron classifies points on a flat 2-D plot. What shape is the border between the region it labels 1 and the region it labels 0?
Guess first. Being wrong here is how the surprise works.
3.Discover
Use the separable dataset with η = 0.5 and press “Show next example” repeatedly. Watch the line jump only when a point is misclassified. Then switch to the XOR pattern and run several full passes: does it ever settle?
Loading the interactive…
Can't use the interactive? Read a description instead
The perceptron diagram plots six points on a 0–5 grid: class 0 (circles) at (1, 1), (2, 1) and (1, 3); class 1 (squares) at (3, 4), (4, 2) and (4, 4). Weights start at zero. Each step shows one example; if it is misclassified the weights and bias change by η(t − y)x and the decision line moves. The readout gives the weights, the bias and how many points are misclassified; on this set it reaches zero. On the XOR set ((1, 1) and (4, 4) class 0; (1, 4) and (4, 1) class 1) at least one point is always wrong.
4.Checkpoint: guided practice
Check what you just discovered before going on. Hints appear after a wrong answer.
Practice 1 · a fresh version every time
A perceptron has weights w₁ = 1 and w₂ = −5 and bias b = 0. For the input (x₁, x₂) = (4, 4), what is the weighted sum z = w₁x₁ + w₂x₂ + b?
Practice 4
Why can a single perceptron never classify all four XOR points correctly?
5.Watch
→ Watch for each neuron as “weighted sum, add a bias, squash”: the same three steps a perceptron does, repeated across layers.
What a neural network actually computes, drawn as layers of numbers.
18 min 40 s · captions on YouTube · source
Nothing loads from YouTube until you press play.
The video is optional: everything you need is also in the lesson text and the interactive.
6.Understand
Weighted sum, bias, step
A perceptron takes inputs x₁, x₂, … and computes z = w₁x₁ + w₂x₂ + … + b. The weights say how much each input matters (and in which direction); the bias b shifts the result. A step function then decides: output 1 if z ≥ 0, else 0. With w = (2, 1) and b = −6, the input (3, 1) gives z = 6 + 1 − 6 = 1, so output 1; the input (1, 2) gives z = −2, so output 0.
The decision boundary is a line
The output switches where z = 0: for two inputs, w₁x₁ + w₂x₂ + b = 0 is a straight line. With w = (2, 1), b = −6 it is 2x₁ + x₂ = 6, through (3, 0) and (0, 6). The weight vector points across the line towards the class-1 side; scaling all weights and bias together changes nothing about the line. Changing b slides the line without turning it.
Learning by fixing mistakes
The perceptron rule looks at one example at a time. If it is right, nothing changes. If it is wrong, each weight moves by η(t − y)xᵢ and the bias by η(t − y), where t is the target, y the output and η the learning rate. A missed 1 (t − y = +1) adds the input to the weights, raising z for that input next time; a false 1 subtracts it. If a separating line exists, this is guaranteed to find one.
The XOR wall
XOR labels (0, 0) and (1, 1) as one class and (0, 1) and (1, 0) as the other. No straight line separates them, so a single perceptron keeps getting at least one point wrong forever. Adding a hidden layer of neurons fixes this: two lines combined can carve out the diagonal pair. That insight, and a way to train hidden layers, is what turned perceptrons into neural networks.
Explain it another way
Think of a referee with a ruler laid across a pitch: everything on one side is “in”, everything on the other is “out”. Each time the referee gets a call wrong, the ruler is nudged towards that point. A ruler can turn and slide, but it can never bend round a corner.
A perceptron is a linear classifier: y = H(wᵀx + b) with H the Heaviside step. The rule is stochastic gradient descent on the perceptron criterion and converges in a finite number of updates when the data are linearly separable (Novikoff's theorem bounds the number of mistakes by (R/γ)², where R is the data radius and γ the margin). On non-separable data it never stops changing.
z = w·x + b. Boundary: {x : w·x + b = 0}, a hyperplane with normal w at signed distance −b/‖w‖ from the origin. Update on a mistake: w ← w + η(t − y)x, b ← b + η(t − y). Example: w₁ = 0.5, η = 0.5, x₁ = 3, t = 1, y = 0 gives w₁ = 0.5 + 0.5 × 1 × 3 = 2.0.
A microcontroller can run a perceptron on three accelerometer features with three multiplications, two additions and a comparison per reading: microseconds and a few bytes of weights. Many on-device “is the machine vibrating abnormally?” detectors start as exactly this before anyone reaches for a deep network.
Worked example 1
w = (1, −2), b = 3. Classify the input (4, 1).
z = 1×4 + (−2)×1 + 3 = 4 − 2 + 3 = 5 ≥ 0, so the output is 1.
Worked example 2
The perceptron above wrongly outputs 1 for (4, 1), whose target is 0. Apply one update with η = 0.5.
t − y = 0 − 1 = −1. w₁ = 1 + 0.5×(−1)×4 = −1; w₂ = −2 + 0.5×(−1)×1 = −2.5; b = 3 + 0.5×(−1) = 2.5. Now z = −4 − 2.5 + 2.5 = −4: output 0, correct.
Common mix-ups
- A perceptron can learn any pattern if you train it long enough.
✓ It can only learn patterns a straight line (a hyperplane) separates. XOR needs a hidden layer. - The perceptron rule changes the weights after every example.
✓ It changes them only when the example is misclassified; correct answers leave the weights alone. - Bigger weights mean a better classifier.
✓ Multiplying all weights and the bias by the same positive number leaves the boundary exactly where it was.
7.Practice on your own
Practice, not a test. Wrong answers get a hint and another try.
Practice 2
A perceptron has w₁ = 1, w₂ = −2 and b = 3. What is z for the input (x₁, x₂) = (4, 1)?
Practice 3
You increase a perceptron's bias b and leave the weights alone. What happens to its decision line?
Practice 5 · a fresh version every time
A perceptron misclassifies an example. Its weight is w₁ = 0.7, the learning rate is η = 0.2, the input is x₁ = −4, the target is t = 0 and the perceptron output y = 1. Using w₁ ← w₁ + η(t − y)x₁, what is the new w₁? (2 decimal places)
8.Apply it
Find, by hand, weights and a bias that make a perceptron compute logical AND on inputs 0 and 1 (output 1 only for (1, 1)). Then do OR. Explain in two sentences why no choice works for XOR, and sketch how two perceptrons feeding a third could.
9.Reflect
Concepts: Embedded machine learning · Thresholding and simple classification