Module 9 — Perceptrons, Multilayer Networks and Backpropagation

Sources: Lec 21 — Perceptron Learning Algorithm; Lec 22 — Multilayer Perceptron Learning Algorithm; Lec 23 — Artificial Neural Network and Backpropagation Algorithm.

Notation. Perceptron: , ; augmented vector ; weights ( = bias). Network: layer index ; nodes in layer ; output of node in layer ; net input; weight from node of layer to node of layer .


C49. The Perceptron Model and Learning Rule

Intuition

A single artificial neuron: weigh the inputs, add them, fire "" if the total is positive, "" otherwise. Learning = whenever the neuron makes a mistake, nudge the weights so that this very example would be a bit more correct.

Formal definition

Linear discriminant (21.1): . Prediction: . A point is correctly classified iff . Online (incremental) rule: at iteration pick a training point that is misclassified, (we include , otherwise the all-zero start never moves), and set Stop when all training points are classified correctly.

Why the update helps (local error correction)

— the quantity for this point rises by . (It may spoil other points — Figure 21.2 in the lecture.)

Key insights

  • Single-layer perceptron = linear classifier (hyperplane ).
  • Converges only for linearly separable data (C50).
  • Starting from , merely scales (Example 4).

Worked examples

Example 1 — Very Easy

  • Problem: (). Classify and .
  • Asked: Labels.
  • Concept: .
  • Approach: Augment, dot.
  • Solution: : . : .
  • Final answer: and .
  • Key lesson: The bias is the weight on the constant .

Example 2 — Easy

  • Problem: , misclassified point with . Apply one update () and check the point.
  • Asked: New and new margin.
  • Concept: Update rule.
  • Approach: .
  • Solution: . Before: , ✗. New . Now , ✓ (increase ).
  • Final answer: .
  • Key lesson: One update can fix the offending point.

Example 3 — Moderate

  • Problem: Learn AND with labels for in that cyclic order, , . Run to convergence.
  • Asked: Final and number of updates.
  • Concept: Online perceptron.
  • Approach: Cycle through the data; update on every mistake ().
  • Solution: Epoch 1: : ⇒ update . : , ✓. ✓. : , ⇒ update . Epoch 2: : ⇒ ; : ⇒ ; : ✓; : ⇒ . Epoch 3: : ⇒ ; : ⇒ ; : ⇒ . Epoch 4: : ⇒ ; : ⇒ . Epoch 5: : ⇒ ; : ⇒ . Epoch 6: : ⇒ ; : ⇒ ; : ⇒ . Epoch 7: : ⇒ ; : ⇒ . Epoch 8: : ⇒ . Epoch 9: all correct: : ; : ; : ; : ✓. Total updates: .
  • Final answer: after updates; boundary .
  • Key lesson: The perceptron finds a separator, not the best one (the max-margin one is ).

Example 4 — Hard

  • Problem: Re-run Example 3 with and . What happens?
  • Asked: Final weights.
  • Concept: Scale invariance.
  • Approach: Track the trajectories.
  • Solution: Claim: with , the trajectory for step size is times the trajectory for . Induction: if , then the sign of equals that of () ⇒ the same points are mistakes in the same order, and ✓. Hence ⇒ ; ⇒ , each after updates (confirmed by running).
  • Final answer: ; identical classification.
  • Key lesson: Only the direction of matters, so with a zero start is irrelevant.

Example 5 — Very Hard

  • Problem: Run the same procedure on XOR ( for ). Describe the behaviour.
  • Asked: Trajectory.
  • Concept: Non-separable data.
  • Approach: Simulate.
  • Solution: Epoch 1: : ⇒ . : , ⇒ . : , ⇒ . : , ⇒ . We are back at after 4 updates — so the sequence repeats forever with period . The sum of the four updates is .
  • Final answer: The weights cycle ; no convergence.
  • Key lesson: On non-separable data the perceptron never stops; a cycle of weights is the typical symptom.

Common mistakes

  • Treating as correct (the all-zero start would never learn).
  • Forgetting to augment with the constant .

Exam traps

  • Labels are here (not ).
  • The update uses the misclassified point only (online version).

Connections

Logistic regression (C27), SVM (C30), convergence (C50), batch version (C51), MLP (C52).

Mastery checklist

  • Apply the update rule.
  • Show the rule helps the point it updates on.
  • Recognise non-convergence.

C50. Convergence Theorem for the Perceptron

Intuition

If a separator exists, the perceptron makes only a finite number of mistakes. Two competing facts: the weight vector keeps aligning with a true separator (grows linearly in the number of mistakes ), but its length grows only like . A vector can’t align faster than it can grow ⇒ is bounded.

Theorem (Rosenblatt) and proof

Assume separability: and with for all (take ). Let (the lecture’s ) and . If updates have occurred then Proof. (a) Length bound. At a mistake , so By induction (lecture 21.5–21.8). (b) Alignment. (lecture 21.10), so . (c) Cauchy–Schwarz. ⇒ . ∎

Salient points (lecture) and clarifications

  • If the data are not separable the algorithm does not converge.
  • The lecture says “no bound on the number of iterations can be found”: the bound above exists, but it depends on the unknown margin of the data, so it cannot be computed in advance without knowing a separator.
  • Any positive step size works (Example 4 of C49).
  • Online perceptron = one sample at a time; classification: .

Worked examples

Example 1 — Very Easy

  • Problem: AND data (augmented ): . Compute .
  • Asked: .
  • Concept: Radius.
  • Approach: .
  • Solution: ; ; ; .
  • Final answer: .
  • Key lesson: Include the constant in the norm.

Example 2 — Easy

  • Problem: Use for AND. Find , , and the bound on .
  • Asked: Bound.
  • Concept: Theorem.
  • Approach: Compute for the four points.
  • Solution: : ; : ; : ; : ⇒ . . Bound .
  • Final answer: (the run of C49 Ex. 3 used ).
  • Key lesson: The bound is conservative.

Example 3 — Moderate

  • Problem: Verify inequalities (a) and (b) numerically along the first three updates of the AND run: , , .
  • Asked: Check.
  • Concept: Proof ingredients.
  • Approach: Compute norms and dot products with .
  • Solution: ✓; ✓; ✓. Alignment: ✓; ✓; ✓.
  • Final answer: All inequalities hold.
  • Key lesson: grows at least linearly; at most linearly.

Example 4 — Hard

  • Problem: Express the bound with the geometric margin and show invariance to rescaling both and the data.
  • Asked: and invariance.
  • Concept: Scale invariance of the bound.
  • Approach: Substitute.
  • Solution: . Replace : , ⇒ ratio unchanged. Scale the data : , ⇒ unchanged. AND: ; ✓.
  • Final answer: , for AND.
  • Key lesson: The mistake bound depends only on the relative margin — the same quantity SVM maximises (C30).

Example 5 — Very Hard

  • Problem: Show that for XOR no exists, so the proof cannot apply, and explain how the cycle of C49 Ex. 5 is consistent with the proof’s failure.
  • Asked: Non-existence and relation to the cycle.
  • Concept: Separability is essential.
  • Approach: Contradictory inequalities.
  • Solution: Needs for all four: ,: . ,: . ,: . ,: . Adding the middle two: ; with this gives , contradicting the fourth. So no separator ⇒ cannot exist. In the proof, step (b) fails: needs a ; without it nothing forces to grow, and indeed the weights return to (the four updates sum to ).
  • Final answer: XOR is not separable; the weight vector cycles.
  • Key lesson: The linear-growth-vs-square-root-growth squeeze needs a true separator.

Common mistakes

  • Using without the bias coordinate.
  • Believing the bound is the actual number of updates.

Exam traps

  • Convergence ⇒ separable (the theorem is “if separable then finite updates”).
  • The bound involves and the margin only — not the dimension or the number of points.

Connections

C30 (margin), C49, C51.

Mastery checklist

  • State and prove the theorem.
  • Compute and the bound.
  • Explain why XOR fails.

C51. Batch Perceptron and the Gradient-Descent View

Intuition

Instead of reacting to one mistake at a time, sum the corrections from all currently misclassified points and apply them together — this is gradient descent on a cost that adds up how badly points are misclassified.

Formal definition

Misclassified index set at iteration : . Cost (“figure of merit”): Gradient (for the current ): . Gradient descent gives (the lecture’s 21.15 writes "" but with the stated result the sign is as above). If separates the data then and . Memory cost of the batch version is higher (all misclassified points are used per step).

Key insights

  • Online = stochastic gradient descent; batch = full gradient.
  • counts violation amount, not just the number of errors.
  • With the "" convention can be while (points exactly on the boundary).

Worked examples (AND data: , , , )

Example 1 — Very Easy

  • Problem: For find and .
  • Asked: .
  • Concept: Definition of .
  • Approach: Compute .
  • Solution: ; . (). .
  • Final answer: , .
  • Key lesson: sums the (negative) margins of the mistakes.

Example 2 — Easy

  • Problem: One batch step from , .
  • Asked: New .
  • Concept: Batch update.
  • Approach: .
  • Solution: . .
  • Final answer: .
  • Key lesson: Big jump — all three mistakes pushed at once.

Example 3 — Moderate

  • Problem: Continue the batch algorithm to convergence from ().
  • Asked: Trajectory.
  • Concept: Batch perceptron.
  • Approach: Repeat.
  • Solution: : , , ⇒ add ⇒ . : , , (tie), ⇒ . : , , , ⇒ add ⇒ . : , ⇒ . : , , (ties), ⇒ . : , ⇒ . : , all ⇒ stop.
  • Final answer: after 7 batch updates (this happens to be the maximum-margin separator).
  • Key lesson: Batch converged in fewer steps (7) than online updates (18), though each step uses more points.

Example 4 — Hard

  • Problem: Show that one batch step reduces the restricted cost: for fixed , decreases by where . Verify on Example 2.
  • Asked: Proof and numeric check.
  • Concept: Gradient descent decreases the cost.
  • Approach: Substitute the update.
  • Solution: . Example 2: , , ⇒ new restricted cost ; direct: gives on those three points ⇒ ✓.
  • Final answer: Decrease of .
  • Key lesson: The restricted cost can become negative: points become correctly classified; the next is recomputed (here became wrong), which is why matters.

Example 5 — Very Hard

  • Problem: Derive that the per-point online rule is stochastic gradient descent on , and compare the cost after the online and batch runs ended (both ) and the number of weight changes.
  • Asked: Equivalence and comparison.
  • Concept: SGD vs full gradient.
  • Approach: Per-point cost.
  • Solution: Per-point cost (perceptron loss); its sub-gradient at a mistake is ; descent step = online rule. ⇒ batch = sum of per-point sub-gradients. Final: online reached in weight changes; batch reached in weight changes; both have ().
  • Final answer: Online = SGD, batch = full gradient; vs updates.
  • Key lesson: Different update schedules reach different separators; none is guaranteed to be max-margin.

Common mistakes

  • Wrong sign in the update.
  • Re-using the old after the weights have changed.

Exam traps

  • ; for a separating hyperplane.
  • Batch needs all misclassified samples simultaneously (memory-hungry).

Connections

C49–C50, gradient descent in logistic regression (C27) and backpropagation (C54).

Mastery checklist

  • Compute , and the batch update.
  • Show online = SGD.
  • Compare online vs batch.

C52. The XOR Problem and the Multilayer Perceptron

Intuition

One neuron draws one line. XOR needs two lines. Let a first layer of neurons compute features (here OR and AND), and a second neuron combine them linearly. The hidden layer transforms a non-separable problem into a separable one.

Formal content (lecture)

Step activation if , else . With inputs :

  • OR: (classes: output only for ).
  • AND: (output only for ).
  • XOR = OR and not AND. Hidden layer , ; output layer .
(OR) (AND)
00000
01101
10101
11110
  • The hidden layer maps the four inputs to in space, where “class B” lies on one side of the line and class A on the other — linearly separable.
  • A multilayer feedforward network = input layer + one or more hidden layers + output layer; generalises to any input dimension and numbers of layers/nodes.

Key insights

  • Non-linearity is essential: if all activations were linear (identity), a stack of layers collapses to a single linear map (Example 5).
  • Hidden layers learn a representation in which a linear classifier works.

Worked examples

Example 1 — Very Easy

  • Problem: Verify that with the step activation computes OR on all four inputs.
  • Asked: Truth table.
  • Concept: Perceptron as OR.
  • Approach: Evaluate.
  • Solution: : ; : ; : ; : .
  • Final answer: OR ✓.
  • Key lesson: The threshold lets any single active input fire the neuron.

Example 2 — Easy

  • Problem: Same for AND with .
  • Asked: Truth table.
  • Concept: Perceptron as AND.
  • Approach: Evaluate.
  • Solution: : ; : ; : ; : .
  • Final answer: AND ✓.
  • Key lesson: Raising the threshold to demands both inputs.

Example 3 — Moderate

  • Problem: Prove no single perceptron computes XOR (classes: for ; for ).
  • Asked: Impossibility.
  • Concept: Linear inseparability.
  • Approach: Contradict the inequalities.
  • Solution: Need ; ; ; . Add the 2nd and 3rd: ⇒ , contradicting the 4th. (Geometrically, the hull of and the hull of both contain .)
  • Final answer: Impossible.
  • Key lesson: One linear threshold unit cannot realise XOR.

Example 4 — Hard

  • Problem: Design a two-layer network for XNOR (output iff ) re-using the OR/AND hidden units.
  • Asked: Output weights.
  • Concept: Reuse hidden features.
  • Approach: XNOR XOR; negate the output discriminant.
  • Solution: Use . : ✓. and : ✓. : ✓.
  • Final answer: Hidden OR & AND; output .
  • Key lesson: The same hidden layer supports different outputs.

Example 5 — Very Hard

  • Problem: (a) Show a 2-layer network with linear (identity) activations is equivalent to a single linear map. (b) Show the XOR network’s decision regions in the original plane: the output is iff — describe this region.
  • Asked: Collapse proof and region.
  • Concept: Need for non-linearity; composite regions.
  • Approach: Matrix product; two parallel lines.
  • Solution: (a) Hidden ; output — affine in ; adding layers only multiplies matrices ⇒ no new expressive power. (b) iff iff : a diagonal band between two parallel lines, containing and () but not () or ().
  • Final answer: Linear nets collapse; the XOR region is the strip .
  • Key lesson: A hidden layer of threshold units can carve out a band, a union of half-space intersections — the building block of arbitrary regions.

Common mistakes

  • Believing deeper linear networks are more powerful.
  • Forgetting the thresholds ().

Exam traps

  • Two-layer ≠ two hidden layers (the lecture’s figure has 1 hidden + 1 output layer).
  • The XOR problem is the standard example of a non-linearly-separable problem.

Connections

C49 (single unit), C53–C54 (general networks and training), SVM kernels (C33: another way to make XOR separable).

Mastery checklist

  • Realise OR and AND with threshold units.
  • Prove XOR is not linearly separable.
  • Build XOR/XNOR with two layers.

C53. Architecture and Forward Computation of a Multilayer Feedforward Network

Intuition

Signals flow forward: each node takes a weighted sum of the previous layer’s outputs (plus a bias), passes it through a squashing function, and sends the result on. The whole network is a composition of summations and sigmoids — a flexible, differentiable family of non-linear functions.

Formal definition (lecture 23.1–23.2)

  • layers; layer 1 = input (it just fans out the inputs , ), layer = output ( nodes = number of classes), layers hidden with arbitrary sizes .
  • Net input of node in layer and its output:
  • Activation: logistic (differentiable), with and .
  • Parameters: ; count .

Key insights

  • Training samples : = desired output (one-hot for classification).
  • Test-time use needs only the forward pass.

Worked examples

Example 1 — Very Easy

  • Problem: Network with layer sizes . Count the weights including biases.
  • Asked: Parameter count.
  • Concept: .
  • Approach: Per layer pair.
  • Solution: ; ; total .
  • Final answer: .
  • Key lesson: Each node in the next layer has one bias.

Example 2 — Easy

  • Problem: Count parameters for (a small digit classifier).
  • Asked: Parameters.
  • Concept: Same.
  • Approach: .
  • Solution: .
  • Final answer: .
  • Key lesson: Most weights sit between the large input layer and the first hidden layer.

Example 3 — Moderate

  • Problem: A sigmoid network: hidden node 1: ; hidden node 2: ; output: , weights (from hidden 1) and (from hidden 2). Compute the output for and the squared error with target .
  • Asked: and .
  • Concept: Forward pass.
  • Approach: Layer by layer.
  • Solution: . . . .
  • Final answer: , .
  • Key lesson: Keep the bias input at every layer.

Example 4 — Hard

  • Problem: For the same network, write the output as a single composite formula and compute the output for .
  • Asked: Composite function and value.
  • Concept: Composition of sigmoids.
  • Approach: Substitute.
  • Solution: . At : ; ; inner ; .
  • Final answer: .
  • Key lesson: A network is just a nested function — differentiable by the chain rule.

Example 5 — Very Hard

  • Problem: Show that a network with logistic units and arbitrarily many hidden layers still produces outputs strictly in , and compute the largest possible value of and what it implies for a chain of layers.
  • Asked: Range and bound.
  • Concept: Properties of the logistic function.
  • Approach: Calculus.
  • Solution: for all finite ⇒ every hidden and output value lies in . ; maximised at (): . In a chain the derivative is at most in magnitude: with it shrinks by a factor per layer (e.g. for ).
  • Final answer: Outputs in ; ⇒ gradients can vanish in deep networks.
  • Key lesson: The sigmoid derivative’s bound explains why deep sigmoid nets are hard to train (vanishing gradients).

Common mistakes

  • Omitting bias weights from the count.
  • Indexing weights backwards ( goes from in layer to in layer ).

Exam traps

  • Input nodes do no computation (fan-out).
  • Output layer size classes.

Connections

C52, C54, softmax output (C28).

Mastery checklist

  • Do a forward pass by hand.
  • Count parameters.
  • State and its maximum.

C54. The Backpropagation Algorithm

Intuition

To adjust a weight deep inside the network you need to know how the final error changes when that weight changes. The chain rule lets you compute this for every weight by sweeping once forward (to get outputs) and once backward (to get “error signals” node by node), re-using shared factors instead of re-differentiating from scratch.

Formal derivation (lecture 23.3)

Training pairs , . Squared-error criterion per sample and total: Gradient descent: (per sample) or (batch). Weight gradient. influences only through with . Define the error (delta) . Then Output layer: . Hidden layers (recursion): affects only via the net inputs of layer : Algorithm: (1) initialise weights randomly; (2) feed a sample; (3) forward pass computing all ; (4) backward pass: then ; (5) update ; (6) repeat until convergence. Test time: forward pass only. Remarks (lecture): no convergence proof exists for backpropagation; there is no sharp stopping rule — in practice stop when the Euclidean norm of the gradient falls below a threshold.

Key insights

  • Cost of the gradient cost of two passes, independent of the number of weights.
  • With logistic units so .

Worked examples

Example 1 — Very Easy

  • Problem: for logistic outputs and .
  • Asked: Derivatives.
  • Concept: .
  • Approach: Direct.
  • Solution: ; .
  • Final answer: .
  • Key lesson: Saturated units ( near or ) learn slowly.

Example 2 — Easy

  • Problem: A single logistic neuron, input , weights , target , , . One gradient step.
  • Asked: New weights and .
  • Concept: Output-layer rule.
  • Approach: .
  • Solution: . . ; . (both). New , ; from to .
  • Final answer: , .
  • Key lesson: Negative gradient ⇒ weights increase ⇒ output moves toward the target.

Example 3 — Moderate

  • Problem: Network of C53 Ex. 3 (input , target ). Compute all ‘s, all weight gradients and perform one update with ; recompute .
  • Asked: Full backprop step.
  • Concept: Algorithm.
  • Approach: Forward values: .
  • Solution: Output: . Hidden: ; . Gradients: output weights : . Hidden 1 weights : ; hidden 2: . Update (): output ; hidden 1: ; hidden 2: . New forward pass: ; ; ⇒ . .
  • Final answer: , ; .
  • Key lesson: One backprop step lowers the error; hidden-layer deltas are the output delta times the connecting weight times .

Example 4 — Hard

  • Problem: Verify the analytic gradient of the output weight from hidden node 1 and of the hidden weight (input hidden 1) by finite differences.
  • Asked: Gradient check.
  • Concept: Correctness of backprop.
  • Approach: with .
  • Solution: Analytic: output weight: ; hidden weight: . Numerical: perturb the output weight : changes by ⇒ slope ✓. Perturb hidden weight : slope ✓.
  • Final answer: Analytic and numerical gradients agree to digits.
  • Key lesson: Gradient checking is the standard way to debug a backprop implementation.

Example 5 — Very Hard

  • Problem: (a) Derive the hidden-layer recursion for a node that feeds two next-layer nodes. (b) For a chain of single logistic neurons with all weights and every unit at , find and comment. (c) Why are there no convergence guarantees?
  • Asked: Derivation, magnitude, comment.
  • Concept: Chain rule; vanishing gradient.
  • Approach: Apply the formula repeatedly.
  • Solution: (a) depends on through , which enters with weight and with weight : ✓ (sum over all paths). (b) With and at every layer: ⇒ ; : — the first layers receive of the output error signal ⇒ they learn extremely slowly. (c) is a non-convex function of the weights (products of weights through non-linearities) so gradient descent may reach local minima or plateaus; the lecture states no convergence proof exists and uses a gradient-norm threshold as a practical stop rule.
  • Final answer: ; attenuation ; no guarantee of global convergence.
  • Key lesson: Backprop is exact differentiation, not an optimiser with guarantees — depth and activation choice affect trainability.

Common mistakes

  • Using the output-layer formula for hidden layers.
  • Forgetting in the recursion.
  • Updating weights during the backward pass before all ‘s are computed (the ‘s use the old weights).

Exam traps

  • requires squared error; for softmax + cross-entropy it becomes (C28).
  • Per-sample (online) updates (23.6) vs summed batch updates (23.7).

Connections

C27–C28 (gradient of logistic/softmax is the same shape), C51 (gradient descent), C53.

Mastery checklist

  • Derive and the recursion.
  • Execute a full backprop step by hand.
  • Verify a gradient numerically.