Perceptron learning rule
Perceptron learning rule: how a single-layer linear classifier learns weights from labeled data, its update formula, convergence theorem and a step-by-step numerical example.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
A perceptron is a simple, fast linear classifier used by engineers for binary decisions (accept/reject, fault/no-fault). The Perceptron learning rule is the basic supervised learning algorithm that adjusts weights from examples; it is a building block for neural networks and helps understand linear separability before studying multilayer networks (see Linear separability and multilayer perceptrons, Backpropagation training).
Key ideas
Step activation: define the step function f(net) for binary classification in two common ways; here we define the bipolar form used in proofs: f(net) = +1 if net ≥ 0, f(net) = −1 if net < 0. (Some texts use 0/1 outputs; formulas differ by a linear transform.)
Perceptron learning rule (update): for an input x with target t ∈ {+1, −1}, if the perceptron output y = f(w·x) is correct, no change. If y ≠ t, update weights by w ← w + η·t·x where η > 0 is the learning rate. This moves w toward class t along x.
Intuition: t·x points in a direction that increases the signed margin for the correctly labelled class. The update is additive and local (depends only on x and t and current w), so it can be implemented online.
Perceptron decision boundary: the set {x | w·x = 0}. In 2D (two features plus bias) this is a straight line. To draw: in plane (x1,x2) draw the line w1·x1 + w2·x2 + b = 0; label the side where w·x > 0 as class +1 and the other as class −1. Mark training points and show how updates move the line.
Linear separability: a dataset {(xi, ti)} is linearly separable if there exists a weight vector w* such that ti (w* · xi) > 0 for every example i. The perceptron can only learn exactly when the data are linearly separable (in the space used by the perceptron). If the data are not linearly separable, the vanilla perceptron need not converge; in practice one uses variants such as the pocket algorithm or averaged perceptron, or maps inputs to a higher-dimensional feature space (e.g., via kernels) or uses multilayer networks.
Perceptron convergence theorem (exact statement): If a finite training set is linearly separable, then the perceptron learning algorithm with fixed learning rate η > 0 produces a weight vector that correctly classifies all training examples after a finite number of updates. Under the standard proof assumptions, the number of updates (mistakes) M is bounded by (R/γ)^2 where R = max_i ||xi|| and γ is the maximum margin defined by γ = max_{||u||=1} min_i ti (u · xi) (equivalently, margin of best separating unit vector). The bound assumes inputs xi are finite and we use bipolar targets ±1; it also assumes initialization w0 = 0 (if w0 ≠ 0, a standard derivation yields M ≤ (R/γ)^2 + 2||w0||/(ηγ)).
Assumptions behind the theorem: finite training set; there exists w* with ||w*|| = 1 such that for all i, ti (w* · xi) ≥ γ > 0; fixed η > 0 (η may be absorbed into xi or w* in the bound); the update rule is w ← w + η ti xi applied when mistake occurs.
Common exam derivation sketch (step-by-step):
- Let w_k be weight after k updates. Show w_{k+1} · w* ≥ w_k · w* + η γ using ti (w*·xi) ≥ γ.
- Hence w_k · w* ≥ k η γ (starting from w_0 = 0 or general initial value adjusted). This gives linear growth of projection onto w*.
- Show ||w_{k+1}||^2 = ||w_k||^2 + 2 η ti (w_k·xi) + η^2 ||xi||^2. Because update occurs when mistake, ti (w_k·xi) ≤ 0, so ||w_{k+1}||^2 ≤ ||w_k||^2 + η^2 R^2.
- By induction ||w_k||^2 ≤ k η^2 R^2 (plus initial norm term). Combine with projection lower bound to get k^2 η^2 γ^2 ≤ ||w_k||^2 ≤ k η^2 R^2, rearrange to k ≤ (R/γ)^2.
- Therefore a finite number of mistakes only.
This proof (and bound) is often required in exams; state the exact inequalities and where each assumption is used.
Formulas
net = w · x — net input to perceptron; w and x are dimension n+1 including bias; unitless; applies for any input vector.
y = f(net) — activation output; with bipolar step: y = +1 if net ≥ 0, otherwise y = −1.
w ← w + η·t·x — perceptron update when t ≠ y; η is learning rate (unitless), t ∈ {+1, −1}, x augmented with bias.
Decision boundary: {x | w · x = 0} — hyperplane separating classes; in 2D draw line w1·x1 + w2·x2 + b = 0.
Perceptron mistake bound: M ≤ (R / γ)^2 — R = max_i ||xi|| (Euclidean norm, unitless), γ = margin > 0 (unitless); applies under the convergence theorem assumptions and assumes initialization w0 = 0 (for arbitrary w0, a standard bound is M ≤ (R/γ)^2 + 2||w0||/(ηγ)).
Worked examples
Example 1 — small bipolar numeric training (step-by-step, exam standard) Problem: Train a perceptron with augmented input x = [1, x1, x2] on three examples: A: xA = [1, 2, 1], tA = +1 B: xB = [1, −1, −1], tB = −1 C: xC = [1, 1, −2], tC = −1 Use initial w = [0, 0, 0], learning rate η = 1. Activation f(net) = sign(net) with sign(0) = +1. Steps:
- Start w0 = [0,0,0]. Present A: net = w0 · xA = 0 → y = +1 = tA, so no update.
- Present B: net = 0 → y = +1 ≠ tB (mistake). Update: w1 = w0 + η·tB·xB = [0,0,0] + 1·(−1)·[1,−1,−1] = [−1, +1, +1].
- Present C: net = w1·xC = (−1)1 + 11 + 1*(−2) = −2 → y = −1 = tC, no update.
- Second epoch: Present A: net = w1·xA = (−1)1 + 12 + 11 = 2 → y = +1 OK. B: net = (−1)1 + 1(−1) + 1(−1) = −3 → y = −1 OK. C: net = −2 → OK. All correct: algorithm converged after 1 update. Final answer: w = [−1, 1, 1]. Decision boundary: −1 + 1·x1 + 1·x2 = 0 → x2 = 1 − x1.
Example 2 — draw decision boundary (theory answer expected in exams) Question: Given w = [b, w1, w2] = [−2, 1, 0.5], describe and draw the decision boundary in x1-x2 plane. Answer steps: Write equation w·x = 0 ⇒ −2 + 1·x1 + 0.5·x2 = 0 ⇒ 0.5·x2 = 2 − x1 ⇒ x2 = 4 − 2·x1. Draw Cartesian plane: plot intercepts (x1 = 0 ⇒ x2 = 4; x2 = 0 ⇒ x1 = 2). Label half-plane where w·x > 0 as +1 and where w·x < 0 as −1. (Sketch line through points (0,4) and (2,0).) Note: Be careful in algebra steps—show both intercepts and label class sides.
Common mistakes
- Not stating activation at net = 0 (tie). Examiners expect you to state whether sign(0) = +1 or treat step(net) = 1 if net ≥ 0; ambiguity changes first few updates.
- Wrong direction of update sign. Remember when t = +1 and y = −1, you add +η x; when t = −1 and y = +1 you subtract η x.
- Improper use of norms and margin in convergence proof (forgetting to normalize w* or use correct inequalities).
- Algebra errors when converting w·x = 0 to slope-intercept form; always compute intercepts and provide two points to draw line.
For your exam
Kinds of questions:
- Definitions: define perceptron, linear separability, bias, learning rate, decision boundary, margin.
- Short notes: explain perceptron learning rule, advantages/limitations, relation to linear separability.
- Derivations: full step-by-step proof of the perceptron convergence theorem and the mistake bound (R/γ)^2; examiners expect explicit inequalities and clear use of assumptions.
- Numericals: train a perceptron on a small dataset step-by-step (show all updates); or compute decision boundary given weights.
- Diagrams: draw the decision line in 2D with labelled points and show how updates shift the line.
What full-marks answers include:
- Precise definitions (bold or clearly marked), statement of assumptions, and the exact learning update used.
- For proofs: clear statement of theorem, definitions of R and γ, normalization of w* if used, exact inequalities with explanations at each step.
- For numericals: augmented inputs, initial weights, learning rate, every net and update calculation, final weights and decision boundary.
Quick check
- What is the perceptron update for bipolar targets +1/−1? 2) Define linear separability in one sentence. 3) State the perceptron mistake bound symbolically. Answers: 1) w ← w + η·t·x. 2) A dataset is linearly separable if there exists a weight vector w* such that for every example ti (w*·xi) > 0. 3) M ≤ (R / γ)^2.
Where I am unsure / notes for reviewer: I used the bipolar activation sign(0) = +1 in examples and proof statements — verify this convention matches the course expected one. Check the algebra in Example 2 where I converted the line equation to intercepts (line form given as x2 = 4 − 2·x1); ensure the arithmetic is consistent with the weight vector chosen. Verify constants and inequality directions in the convergence bound section and the exact form of the update variants (I gave both bipolar and 0/1 variants).
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?