Perceptron: (Xi,yi), yi∈{−1,+1}; augmented vector Xi′=[1,xi1,…,xim]T; weights W=[w0,w1,…,wm]T (w0 = bias). Network: layer index l=1..L; nl nodes in layer l; yil output of node i in layer l; Sjl net input; wijl weight from node i of layer l to node j of layer l+1.
Python helpers — run once, the checks below reuse them
import numpy as npnp.set_printoptions(precision=4, suppress=True)X = np.array([[0,0], [0,1], [1,0], [1,1]], float); Xa = np.c_[np.ones(4), X] # augmented inputsy_and = np.array([-1, -1, -1, 1]); y_xor = np.array([-1, 1, 1, -1])def perceptron(y, eta=1.0, max_epochs=200): """Online perceptron, cyclic order, update when y·f <= 0. Returns (W, #updates, trajectory).""" W = np.zeros(3); traj = [W.copy()] for _ in range(max_epochs): changed = False for i in range(4): if y[i] * (W @ Xa[i]) <= 0: W = W + eta * y[i] * Xa[i]; traj.append(W.copy()); changed = True if not changed: break return W, len(traj) - 1, trajsigmoid = lambda z: 1 / (1 + np.exp(-z))
C49. The Perceptron Model and Learning Rule
Intuition
A single artificial neuron: weigh the inputs, add them, fire "+1" if the total is positive, "−1" otherwise. Learning = whenever the neuron makes a mistake, nudge the weights so that this very example would be a bit more correct — like a bouncer who adjusts the guest-list rule each time they let in the wrong person.
flowchart LR
x0["1 (bias)"] -- w0 --> S(("Σ"))
x1[x₁] -- w1 --> S
x2[x₂] -- w2 --> S
S --> A{"sign"}
A --> O["±1"]
Formal definition
Linear discriminant (21.1): f(Xi,W)=w0+∑j=1mwjxij=WTXi′. Prediction: sign(f). A point is correctly classified iff yif(Xi,W)>0.
Online (incremental) rule: at iteration k pick a training point (X(k),y(k)) that is misclassified, y(k)WT(k)X′(k)≤0 (we include =0, otherwise the all-zero start never moves), and set
W(k+1)=W(k)+ηy(k)X′(k),η>0(η=1 in the lecture).
Stop when all training points are classified correctly.
Why the update helps (local error correction)
yW(k+1)TX′=yW(k)TX′+ηy2X′TX′=yW(k)TX′+η∥X′∥2 — the quantity yWTX′ for this point rises by η∥X′∥2>0. (It may spoil other points — Figure 21.2 in the lecture.)
Key insights
A single-layer perceptron = a linear classifier (hyperplane WTX′=0).
Converges only for linearly separable data (C50).
Starting from W(0)=0, η merely scales W (Example 4).
Worked examples
Example 1 — Very Easy · Classify with given weights
Problem:W=(−1,2,1) (w0=−1). Classify X=(1,0) and X=(0,0.5).
The perceptron finds a separator, not the best one (the max-margin one is (−3,2,2)).
Example 4 — Hard · Step size does not matter
Problem: Re-run Example 3 with η=0.5 and η=3. What happens?
Asked: Final weights.
Concept: Scale invariance.
Approach: Track the trajectories.
Solution: Claim: with W(0)=0, the trajectory for step size η is η times the trajectory for η=1. Induction: if Wη(k)=ηW1(k), then the sign of yWηTX′=ηyW1TX′ equals that of yW1TX′ ⇒ the same points are mistakes in the same order, and Wη(k+1)=ηW1(k)+ηyX′=ηW1(k+1) ✓. Hence η=0.5 ⇒ (−2,1.5,1); η=3 ⇒ (−12,9,6), each after 18 updates.
Final answer:η×(−4,3,2); identical classification.
Only the direction of W matters, so with a zero start η is irrelevant.
Example 5 — Very Hard · The XOR cycle
Problem: Run the same procedure on XOR (y=−1,+1,+1,−1 for (0,0),(0,1),(1,0),(1,1)). Describe the behaviour.
Asked: Trajectory.
Concept: Non-separable data.
Approach: Simulate.
Solution:(0,0): f=0 ⇒ (−1,0,0). (0,1): f=−1, y=+1 ⇒ (0,0,1). (1,0): f=0, y=+1 ⇒ (1,1,1). (1,1): f=3, y=−1 ⇒ (0,0,0). Back at W=0 after 4 updates — the sequence repeats forever with period 4. The four updates sum to (−1)(1,0,0)+(1,0,1)+(1,1,0)−(1,1,1)=0.
Final answer: The weights cycle 0→(−1,0,0)→(0,0,1)→(1,1,1)→0; no convergence.
Python check
W = np.zeros(3)for k in range(8): i = k % 4 if y_xor[i] * (W @ Xa[i]) <= 0: W = W + y_xor[i] * Xa[i] print(k, W) # returns to [0 0 0] every 4 steps
Key lesson
On non-separable data the perceptron never stops; a cycle of weights is the typical symptom.
Common mistakes
Treating yf=0 as correct (the all-zero start would never learn).
Forgetting to augment with the constant 1.
Exam traps
Labels are ±1 here (not 0/1).
The update uses the misclassified point only (online version).
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 (alignment grows linearly in the number of mistakes k), but its length grows only like k. A vector can’t align faster than it can grow ⇒ k is bounded.
Theorem (Rosenblatt) and proof
Assume separability: ∃W∗ and γ>0 with yiW∗TXi′≥γ for all i (take γ=miniyiW∗TXi′). Let R2=maxi∥Xi′∥2 (the lecture’s M) and W(0)=0. If k updates have occurred then
k≤γ2R2∥W∗∥2.Proof. (a) Length bound. At a mistake yWTX′≤0, so
∥W(k+1)∥2=∥W(k)∥2+2yW(k)TX′+∥X′∥2≤∥W(k)∥2+R2.
By induction ∥W(k)∥2≤kR2 (lecture 21.5–21.8).
(b) Alignment.W(k)=∑j<ky(j)X′(j) (lecture 21.10), so W(k)TW∗=∑j<ky(j)W∗TX′(j)≥kγ.
(c) Cauchy–Schwarz.(kγ)2≤(W(k)TW∗)2≤∥W(k)∥2∥W∗∥2≤kR2∥W∗∥2 ⇒ k≤R2∥W∗∥2/γ2. ∎
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 (C49 Example 4).
Online perceptron = one sample at a time; classification: sign(WTX0′).
Worked examples
Example 1 — Very Easy · The radius R
Problem: AND data (augmented X′). Compute R2.
Asked:R2.
Concept: Radius.
Approach:∥X′∥2=1+x12+x22.
Solution:(0,0)→1; (0,1)→2; (1,0)→2; (1,1)→3.
Final answer:R2=3.
Key lesson
Include the constant 1 in the norm.
Example 2 — Easy · The bound for AND
Problem: Use W∗=(−3,2,2) for AND. Find γ, ∥W∗∥2, and the bound on k.
for k, Wk in enumerate(perceptron(y_and)[2][1:4], 1): print(k, Wk @ Wk, k * R2, Wk @ Ws, k * gam) # 1 1 3 3 1 | 2 2 6 4 2 | 3 3 9 7 3
Key lesson
W(k)TW∗ grows at least linearly; ∥W(k)∥2 at most linearly.
Example 4 — Hard · A scale-free bound
Problem: Express the bound with the geometric margin γg=γ/∥W∗∥ and show invariance to rescaling both W∗ and the data.
Asked:(R/γg)2 and invariance.
Concept: Scale invariance of the bound.
Approach: Substitute.
Solution:k≤γ2R2∥W∗∥2=(γgR)2. Replace W∗→cW∗: γ→cγ, ∥W∗∥→c∥W∗∥ ⇒ ratio unchanged. Scale the data X′→sX′: R→sR, γg→sγg ⇒ unchanged. AND: γg=171=0.2425; (R/γg)2=3⋅17=51 ✓.
Final answer:k≤(R/γg)2, =51 for AND.
Key lesson
The mistake bound depends only on the relative margin γg/R — the same quantity SVM maximises (C30).
Example 5 — Very Hard · XOR has no separator
Problem: Show that for XOR no W∗ 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 yWTX′>0 for all four: (0,0), y=−1: w0<0. (0,1), y=+1: w0+w2>0. (1,0), y=+1: w0+w1>0. (1,1), y=−1: w0+w1+w2<0. Adding the middle two: 2w0+w1+w2>0; with w0<0 this gives w0+w1+w2>−w0>0, contradicting the fourth. So no separator ⇒ γ>0 cannot exist. In the proof, step (b) fails: W(k)TW∗≥kγ needs a W∗; without it nothing forces ∥W(k)∥ to grow, and indeed the weights return to 0 (the four updates sum to 0).
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 R2 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 R 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 R,γ,∥W∗∥ 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 k: Sk={j:yjW(k)TXj′≤0}. Cost (“figure of merit”):
J(W)=−∑j∈SkyjWTXj′(≥0).
Gradient (for the current Sk): ∇WJ=−∑j∈SkyjXj′. Gradient descentW(k+1)=W(k)−η∇J gives
W(k+1)=W(k)+η∑j∈SkyjXj′,η>0
(the lecture’s 21.15 writes "+η∂J/∂W", but with the stated result the sign is as above).
If W0 separates the data then S=∅ and J=0. Memory cost of the batch version is higher (all misclassified points are used per step).
Key insights
Online = stochastic gradient descent; batch = full gradient.
J counts violation amount, not just the number of errors.
With the "≤0" convention J can be 0 while Sk=∅ (points exactly on the boundary).
Worked examples (AND data: (0,0)−, (0,1)−, (1,0)−, (1,1)+)
Problem: Continue the batch algorithm to convergence from (0,1,1) (η=1).
Asked: Trajectory.
Concept: Batch perceptron.
Approach: Repeat.
Solution:
step
W
mistakes S
J
next W
1
(0, 1, 1)
(0,0),(0,1),(1,0)
2
(−3, 0, 0)
2
(−3, 0, 0)
(1,1)
3
(−2, 1, 1)
3
(−2, 1, 1)
(1,1) (tie)
0
(−1, 2, 2)
4
(−1, 2, 2)
(0,1),(1,0)
2
(−3, 1, 1)
5
(−3, 1, 1)
(1,1)
1
(−2, 2, 2)
6
(−2, 2, 2)
(0,1),(1,0) (ties)
0
(−4, 1, 1)
7
(−4, 1, 1)
(1,1)
2
(−3, 2, 2)
—
(−3, 2, 2)
none (yf=3,1,1,1)
—
stop
Final answer:W=(−3,2,2) after 7 batch updates (this happens to be the maximum-margin separator).
Python check
W = np.array([0, 1, 1.]); steps = 0while True: S = [j for j in range(4) if y_and[j] * (W @ Xa[j]) <= 0] if not S: break W = W + sum(y_and[j] * Xa[j] for j in S); steps += 1; print(steps, W)# ends at [-3. 2. 2.] after 7 steps
Key lesson
Batch converged in fewer steps (7) than online updates (18), though each step uses more points.
Example 4 — Hard · A batch step lowers the restricted cost
Problem: Show that one batch step reduces the restricted cost: for fixed S, JS(W)=−∑j∈SyjWTXj′ decreases by η∥g∥2 where g=∑j∈SyjXj′. Verify on Example 2.
Asked: Proof and numeric check.
Concept: Gradient descent decreases the cost.
Approach: Substitute the update.
Solution:JS(W+ηg)=JS(W)−ηgT∑j∈SyjXj′=JS(W)−η∥g∥2. Example 2: JS=2, g=(−3,−1,−1), ∥g∥2=11 ⇒ new restricted cost 2−11=−9; direct: W=(−3,0,0) gives yf=(3,3,3) on those three points ⇒ −9 ✓.
Final answer: Decrease of η∥g∥2=11.
Key lesson
The restricted cost can become negative: points become correctly classified; the next S is recomputed (here (1,1) became wrong), which is why η matters.
Example 5 — Very Hard · Online = SGD
Problem: Derive that the per-point online rule is stochastic gradient descent on J, and compare the cost J after the online and batch runs ended (both 0) and the number of weight changes.
Asked: Equivalence and comparison.
Concept: SGD vs full gradient.
Approach: Per-point cost.
Solution: Per-point cost Jj(W)=max(0,−yjWTXj′) (perceptron loss); its sub-gradient at a mistake is −yjXj′; descent step W←W+ηyjXj′ = the online rule. J=∑jJj ⇒ batch = sum of per-point sub-gradients. Final: online reached W=(−4,3,2) in 18 weight changes; batch reached (−3,2,2) in 7; both have J=0.
Final answer: Online = SGD, batch = full gradient; 18 vs 7 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 Sk after the weights have changed.
Exam traps
J≥0; J=0 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 Sk, J 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.
flowchart LR
x1((x₁)) --> OR["h₁ = OR<br/>x₁+x₂−½ > 0"]
x2((x₂)) --> OR
x1 --> AND["h₂ = AND<br/>x₁+x₂−3/2 > 0"]
x2 --> AND
OR -- "+1" --> Y["y = h₁ − h₂ − ½ > 0"]
AND -- "−1" --> Y
Formal content (lecture)
Step activation f(g)=1 if g>0, else 0. With inputs x1,x2∈{0,1}:
OR: g1(X)=x1+x2−21 (output 0 only for (0,0)).
AND: g2(X)=x1+x2−23 (output 1 only for (1,1)).
XOR = OR and not AND. Hidden layer Y1=f(g1), Y2=f(g2); output layer Y=f(Y1−Y2−21).
x1x2
Y1 (OR)
Y2 (AND)
Y1−Y2−21
Y
00
0
0
−0.5
0
01
1
0
0.5
1
10
1
0
0.5
1
11
1
1
−0.5
0
The hidden layer maps the four inputs to (0,0),(1,0),(1,0),(1,1) in (Y1,Y2) space, where “class B” ={(1,0)} lies on one side of the line Y1−Y2=21 and class A ={(0,0),(1,1)} on the other — linearly separable.
A multilayer feedforward network = input layer + one or more hidden layers + output layer; it generalises to any input dimension and any numbers of layers and 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.
Raising the threshold to −23 demands both inputs.
Example 3 — Moderate · A single neuron cannot do XOR
Problem: Prove no single perceptron computes XOR (class 0 for (0,0),(1,1); class 1 for (0,1),(1,0)).
Asked: Impossibility.
Concept: Linear inseparability.
Approach: Contradict the inequalities.
Solution: Need b<0; w2+b>0; w1+b>0; w1+w2+b<0. Add the 2nd and 3rd: w1+w2+2b>0 ⇒ w1+w2+b>−b>0, contradicting the 4th. (Geometrically, the hulls of {(0,1),(1,0)} and {(0,0),(1,1)} both contain (0.5,0.5).)
Final answer: Impossible.
Key lesson
One linear threshold unit cannot realise XOR.
Example 4 — Hard · XNOR from the same hidden units
Problem: Design a two-layer network for XNOR (output 1 iff x1=x2) re-using the OR / AND hidden units.
Asked: Output weights.
Concept: Reuse hidden features.
Approach: XNOR =1−XOR; negate the output discriminant.
Solution: Use fout=f(−Y1+Y2+21). 00: (0,0)→0.5>0→1 ✓. 01 and 10: (1,0)→−0.5→0 ✓. 11: (1,1)→0.5→1 ✓.
Final answer: Hidden OR & AND; output f(−Y1+Y2+0.5).
Example 5 — Very Hard · Why non-linearity is essential
Problem: (a) Show a 2-layer network with linear (identity) activations is equivalent to a single linear map. (b) Describe the decision region of the XOR network in the original plane: output 1 iff 0<x1+x2−21∧x1+x2−23≤0.
Asked: Collapse proof and region.
Concept: Need for non-linearity; composite regions.
Approach: Matrix product; two parallel lines.
Solution: (a) Hidden h=W1x+b1; output y=W2h+b2=(W2W1)x+(W2b1+b2) — affine in x; extra layers only multiply matrices ⇒ no new expressive power. (b) Y=1 iff Y1=1,Y2=0 iff 21<x1+x2≤23: a diagonal band between two parallel lines, containing (0,1) and (1,0) (x1+x2=1) but not (0,0) (0) or (1,1) (2).
Final answer: Linear nets collapse; the XOR region is the strip 21<x1+x2≤23.
x2
1 + (0,1)=1 ╲ ╲ (1,1)=0
| ╲ band ╲ output = 1 only inside the band
0 + (0,0)=0 ╲ ╲ (1,0)=1
+---------------------→ x1
x1+x2 = ½ x1+x2 = 3/2
Key lesson
A hidden layer of threshold units can carve out a band, a union of intersections of half-spaces — the building block of arbitrary regions.
Common mistakes
Believing deeper linear networks are more powerful.
Forgetting the thresholds (−21,−23).
Exam traps
“Two-layer” ≠ two hidden layers (the lecture’s figure has 1 hidden + 1 output layer).
XOR 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)
L layers; layer 1 = input (it just fans out the inputs yi1=xi, n1=m), layer L = output (nL=C nodes = number of classes), layers 2..L−1 hidden with arbitrary sizes nl.
Net input of node j in layer l+1 and its output:
Sjl+1=∑r=0nlwrjlyrl(with y0l≡1,w0jl=bias),yjl+1=f(Sjl+1).
Activation: logistic f(S)=1+e−S1 (differentiable), with f′(S)=f(S)(1−f(S))=y(1−y) and f′≤41.
Problem: For the same network, write the output as a single composite formula and compute the output for x=(0,0).
Asked: Composite function and value.
Concept: Composition of sigmoids.
Approach: Substitute.
Solution:y=σ(0.1+2σ(−0.5+x1+x2)−σ(0.3−x1+0.5x2)). At (0,0): σ(−0.5)=0.3775; σ(0.3)=0.5744; inner =0.1+0.7550−0.5744=0.2806; y=σ(0.2806)=0.5697.
Final answer:y(0,0)=0.570.
Python check
print(forward(W1, W2, [0, 0])[1]) # 0.5697
Key lesson
A network is just a nested function — differentiable by the chain rule.
Example 5 — Very Hard · Bounded outputs, bounded slopes
Problem: Show that a network with logistic units and arbitrarily many hidden layers still produces outputs strictly in (0,1), and compute the largest possible value of f′ and what it implies for a chain of L layers.
Asked: Range and bound.
Concept: Properties of the logistic function.
Approach: Calculus.
Solution:0<σ(S)<1 for all finite S ⇒ every hidden and output value lies in (0,1). f′(S)=y(1−y); maximised at y=21 (S=0): fmax′=41. In a chain x→y2→⋯→yL the derivative ∂yL/∂x=∏lwlf′(Sl+1) is at most ∏l∣wl∣⋅(41)L−1 in magnitude: with ∣w∣≤1 it shrinks by a factor ≥4 per layer (e.g. 4−4=0.0039 for L=5).
Final answer: Outputs in (0,1); f′≤41 ⇒ 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 (wijl goes fromi in layer ltoj in layer l+1).
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.
flowchart LR
X[input] -->|forward| H[hidden y¹] -->|forward| O[output y]
O --> E["error J = ½(y−z)²"]
E -->|"γᴸ = (y−z)f′"| GO["γ output"]
GO -->|"γˡ = f′ Σ γˡ⁺¹ w"| GH["γ hidden"]
GH -->|"∂J/∂w = γ·y"| U["update weights"]
Formal derivation (lecture 23.3)
Training pairs (Xr,Zr), r=1..N. Squared-error criterion per sample and total:
Jr(w)=21∑j=1C(yjL(w,Xr)−zrj)2,J(w)=∑r=1NJr(w)(empirical risk RN=N2J).
Gradient descent: w(k+1)=w(k)−η∇Jr(w(k)) (per sample) or −η∑r∇Jr (batch).
Weight gradient.wijl influences J only through Sjl+1 with ∂wijl∂Sjl+1=yil. Define the error (delta) γjl=∂J/∂Sjl. Then
∂wijl∂J=γjl+1yil.Output layer:γjL=∂yjL∂J∂SjL∂yjL=(yjL−zj)f′(SjL).
Hidden layers (recursion):Sjl affects J only via the net inputs of layer l+1:
γjl=∑r=1nl+1∂Srl+1∂J∂yjl∂Srl+1∂Sjl∂yjl=f′(Sjl)r=1∑nl+1γrl+1wjrl.Algorithm: (1) initialise weights randomly; (2) feed a sample; (3) forward pass computing all yjl; (4) backward pass: γL then γL−1,…,γ2; (5) update wijl←wijl−ηγjl+1yil; (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
The cost of the gradient ≈ cost of two passes, independent of the number of weights.
With logistic units f′(S)=y(1−y), so γjL=(yj−zj)yj(1−yj).
Worked examples
Example 1 — Very Easy · Sigmoid slopes
Problem:f′(S) for logistic outputs y=0.5 and y=0.9.
Asked: Derivatives.
Concept:f′=y(1−y).
Approach: Direct.
Solution:0.5(0.5)=0.25; 0.9(0.1)=0.09.
Final answer:0.25,0.09.
Key lesson
Saturated units (y near 0 or 1) learn slowly.
Example 2 — Easy · One neuron, one step
Problem: A single logistic neuron, input x=1, weights w0=w1=0, target z=1, J=21(y−z)2, η=1. One gradient step.
Asked: New weights and J.
Concept: Output-layer rule.
Approach:γ=(y−z)y(1−y).
Solution:S=0⇒y=0.5. γ=(0.5−1)(0.25)=−0.125. ∂J/∂w0=−0.125; ∂J/∂w1=−0.125. w←0+0.125=0.125 (both). New S=0.25, y=0.5622; J from 0.125 to 21(0.4378)2=0.0958.
Gradient checking is the standard way to debug a backprop implementation.
Example 5 — Very Hard · Deltas, vanishing gradients, no guarantees
Problem: (a) Derive the hidden-layer recursion for a node that feeds two next-layer nodes. (b) For a chain of L single logistic neurons with all weights 1 and every unit at S=0, find γ2/γL 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) J depends on Sjl through yjl=f(Sjl), which enters Sal+1 with weight wja and Sbl+1 with weight wjb: γjl=f′(Sjl)[wjaγal+1+wjbγbl+1] ✓ (sum over all paths). (b) With w=1 and f′=41 at every layer: γl=41γl+1 ⇒ γ2=(41)L−2γL; L=6: (41)4=0.0039 — the first layers receive ≈0.4% of the output error signal ⇒ they learn extremely slowly. (c) J(w) 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:γjl=f′(Sjl)∑rγrl+1wjrl; attenuation (41)L−2; no guarantee of global convergence.
Python check
print([0.25**(L - 2) for L in (3, 4, 5, 6, 10)]) # 0.25 0.0625 0.0156 0.0039 1.5e-05
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 f′(S) in the recursion.
Updating weights during the backward pass before all γ‘s are computed (the γ‘s use the old weights).
Exam traps
γjL=(yjL−zj)f′(SjL) requires squared error; for softmax + cross-entropy it becomes y^−z (C28).
Per-sample (online) updates (23.6) vs summed batch updates (23.7).
Connections:C27–C28 (the gradient of logistic / softmax has the same shape), C51 (gradient descent), C53.