Exercises — The perceptron model and history
This is a self-testing workout for the perceptron. Every problem states its level (L1 Recognition → L5 Mastery). Try it first, then open the collapsible solution. Numbers are all machine-checked.
Fixed convention everywhere: , and when , when . So a tie () means class 1.
Level 1 — Recognition
You just read a formula; can you plug numbers into it?
Exercise 1.1 — Forward pass
A perceptron has weights and bias . What does it predict for the input ?
Recall Solution
WHY form : each weight says "how strongly does feature vote for class 1?" The dot product tallies all those weighted votes into one number, and shifts the whole tally up or down (the built-in threshold). So is the neuron's single "how excited am I?" score. WHAT we do: compute that score, then apply the step rule. Since , the rule gives . Answer: .
Exercise 1.2 — The tie case
Same perceptron , . Predict for .
Recall Solution
WHY the step at zero is the boundary: the equation is exactly the dividing line between the two classes — one side has (votes for 1), the other has (votes for 0). The step function turns "which side of the line am I on?" into a crisp 0/1 label, and points sitting on the line () are the tie our convention sends to class 1. is a tie — this input lands exactly on the boundary. Our convention resolves ties to class 1. Answer: .
Exercise 1.3 — Read the boundary
For , , the decision boundary is the line . Write it in slope–intercept form .
Recall Solution
WHY slope–intercept: it lets us draw the line — is steepness, is where it crosses the vertical axis. Answer: slope , intercept .
Level 2 — Application
Now design or run the algorithm, not just evaluate it.
Exercise 2.1 — Build a NOT gate
A NOT gate has one input: and . Find weights and bias for a single-input perceptron that computes it.
Recall Solution
WHAT we need: when , when . Since output falls as input rises, the weight must be negative. Try , :
- : ✓
- : ✓ Answer: (any with works — e.g. also works).
Exercise 2.2 — One update step
Start with , , learning rate . The example is , true label . Perform one perceptron update and report the new .
Recall Solution
Predict: . Error: (a false positive). Update : WHY these moved down: we said "spam" wrongly, so we push down for this point next time. Answer: .
Exercise 2.3 — NAND gate weights
Verify that , computes NAND (output is 1 unless both inputs are 1).
Recall Solution
NAND truth: .
- : ✓
- : ✓
- : ✓
- : ✓ All four match. NAND is confirmed. (Notice it is the AND weights, negated with a flipped bias.)
Level 3 — Analysis
Reason about why boundaries and separability behave as they do.
The figure below has two panels, both drawn on a chalkboard grid.
- Left panel: the boundary line for , (the equation ), drawn in chalk white. A blue arrow starts on the line and points in the direction of — notice it meets the line at a right angle. The yellow dot is (labeled "class 1"), sitting on the side the blue arrow points toward; the pink dot is (labeled "class 0"), on the side it points away from. Axes are (horizontal) and (vertical).
- Right panel: the four XOR points on the unit square. Yellow dots are the class-1 corners and ; pink dots are the class-0 corners and . A dashed blue line shows one attempted separator — trace it and you will see it always leaves one wrong-coloured dot on each side.

Exercise 3.1 — Which side of the line?
A perceptron has , . The weight vector points perpendicular to the boundary (this is the blue arrow in the left panel above). For each point, say the predicted class and confirm it sits on the side the arrow points to (class 1) or away from it (class 0): , .
Recall Solution
WHY perpendicular: grows fastest along ; the boundary is the level set , always at right angles to that direction of steepest increase. That is the right angle you see between the blue arrow and the white line.
- : . Positive = same side the arrow points (the yellow dot). ✓
- : . Negative = opposite side (the pink dot). ✓ Answer: , .
Exercise 3.2 — Why XOR is impossible
XOR is . Prove no perceptron can compute it. (Use the right panel of the figure to picture the four points.)
Recall Solution
WHAT we must find: a line putting the two "1" points on one side and the two "0" points on the other. Picture first (intuition, not proof): in the right panel the two yellow (class-1) corners and the two pink (class-0) corners alternate around the square. A single straight cut can certainly slice through a diagonal — that is why the picture alone is not a proof. To be rigorous we turn to algebra. Algebraic proof. Suppose weights exist. The perceptron's four required inequalities are:
- : — call this (A)
- : — call this (B)
- : — call this (C)
- : — call this (D)
Add (C) and (D): . Add (A) and (B): . The same quantity is required to be both and — impossible. So no such weights exist. This is exactly the Linear Separability limit Minsky & Papert publicized — solved later by the Multi-Layer Perceptron.
Exercise 3.3 — Distance from boundary
For , , how far is the point from the decision boundary? (The signed distance is .)
Recall Solution
WHY divide by : alone scales if we double the weights, but the geometry of the line doesn't change. Dividing by the length cancels that scaling, giving true perpendicular distance. Answer: units, on the class-1 side (positive).
Level 4 — Synthesis
Combine the pieces: run learning to convergence, connect to neighbouring ideas.
Exercise 4.1 — Train OR from scratch
Start , , . Train on OR: , presenting rows in order and cycling until all four are correct. Report the first weight set that classifies every row.
Recall Solution
Degenerate start — read this first. At initialization , , so for every input . Since is a tie, the fresh perceptron always predicts class 1 — regardless of the input! That is why the very first row with true label must produce an error and trigger an update. Don't be surprised the machine starts by getting every "class 0" example wrong: it literally has no opinion yet and defaults to 1.
Now track , prediction, error, update each step.
Epoch 1
- : (the degenerate all-ones prediction), err . Update: (times 0), . → .
- : , err . Update: , . → .
- : , err . No change. → .
- : , err . No change.
Epoch 2 — check all rows with :
- : , but . Still wrong! err . Update: . → .
- : ✓
- : , but . Wrong. err . Update: , . → .
- : ✓
Epoch 3 — check all with :
- : , but . Wrong. err . Update: . → .
- : ✓
- : ✓
- : ✓
Epoch 4 — verify on all rows:
- : ✓
- : ✓ · : ✓ · : ✓
Answer: classifies all four. This matches the hand-picked OR weights from the parent note (up to the boundary passing exactly through the two mid-points). The Perceptron Convergence Theorem guarantees this: OR is linearly separable, so learning terminates in finite passes.
Exercise 4.2 — Step vs. sigmoid
The perceptron uses a hard step. Logistic Regression replaces it with the sigmoid . Compute and explain why this smooth version enables Gradient Descent where the step function cannot.
Recall Solution
WHY it matters: the step function is flat everywhere except an infinite jump at — its slope (derivative) is almost everywhere and undefined at the jump. Gradient Descent needs a nonzero slope to know which way to nudge weights. The sigmoid slopes smoothly (), so every point gives a usable gradient. This smoothing is what makes Backpropagation possible in deep networks. See Activation Functions. Answer: .
Level 5 — Mastery
Prove, generalize, or expose a subtlety.
Exercise 5.1 — Bias as an extra weight
Show that the bias can be absorbed as a weight on a constant "dummy" input , so that becomes a single dot product .
Recall Solution
Define augmented vectors and with . Identical to the original. WHY this is useful: the update rule for , namely , is now just the ordinary weight update on a feature that is always . One formula handles everything — this is the "add a 1s column" trick every ML library uses.
Exercise 5.2 — Scaling doesn't change the classifier
Take any solution . Prove that produces the exact same predictions on every input, yet the perceptron update treats them differently. Verify on , point .
Recall Solution
Same predictions: . Since , . Every sign is preserved, so is identical for all inputs. Check: original . Scaled . Same class. ✓ The subtlety: although the decision boundary is unchanged, the raw magnitude doubled — so the confidence-like value and the step size effect differ. This is precisely why the honest margin uses (Ex 3.3): , identical to from the original. Normalized margin is invariant; raw is not.
Exercise 5.3 — A non-separable trap
Consider one-dimensional data: , , . Show no single perceptron can classify all three, and state what the algorithm does forever.
Recall Solution
A 1-D perceptron splits the line at one threshold . With : points right of are class 1, left are class 0 (or the mirror if ). Either way, one threshold gives one contiguous class-1 region. But here the class-1 points sit on both sides of the class-0 point — the labels go , an alternating pattern (the same structure that kills XOR). No single cut separates them. What the algorithm does: it never converges. It keeps making a mistake on some point every epoch and updating forever, weights oscillating. The Perceptron Convergence Theorem guarantees termination only for linearly separable data — this data is not. Practical fix: cap the epochs (the "pocket" variant keeps the best-so-far weights), or move to a Multi-Layer Perceptron.
Recall Self-check ledger (answers only)
1.1 ::: 1.2 ::: (tie → class 1) 1.3 ::: slope , intercept 2.1 ::: 2.2 ::: 2.3 ::: NAND confirmed 3.1 ::: 3.2 ::: impossible (contradiction from the four inequalities) 3.3 ::: distance 4.1 ::: 4.2 ::: 5.1 ::: 5.2 ::: same class both times; margin invariant 5.3 ::: non-separable, never converges