Skip to content
Tactiverge

School/✦ Research Engineer/Elective · AIP-520

Gradient descent on a one-neuron network

A network with millions of weights learns by asking one question of each weight: “if I nudge you, does the error go up or down?” How is that question answered?

About 45 min · 3 goals · Checked by automated tests

Review status: Technically checked (automated tests)Content file last checked 2026-11-29.How independent review works

1.Why should I care?

Training is just repeated small corrections. The perceptron's rule only works for a hard step; real networks use smooth activations so that calculus can say exactly how much each weight is to blame. Do it once by hand for one neuron and backpropagation stops being magic: it is the chain rule, applied layer by layer.

  • ◇ Write the squared-error loss for one sigmoid neuron and derive ∂L/∂w with the chain rule.
  • ◇ Carry out one gradient-descent update by hand and check that the loss falls.
  • ◇ Explain what happens when the learning rate is too small or too large.

2.Predict

You double the learning rate of a model that was training slowly but steadily. What is the risk?

Guess first. Being wrong here is how the surprise works.

3.Discover

Start at w₀ = −1. Take steps with η = 0.1, then 0.5, then 0.9, then 1.05. For each, count steps until the readout says converged, or note when it never does.

Loading the interactive…

Can't use the interactive? Read a description instead

The gradient-descent diagram plots the loss L(w) = (w − 3)² + 1 as a U-shaped curve with its lowest point at w = 3. Each press of Take one step moves w by −η × 2(w − 3) and marks the new point. From w₀ = −1: with η = 0.1 the points creep towards 3; with η = 0.5 the first step lands exactly on 3; with η = 0.9 they zig-zag across the minimum but settle; with η = 1.05 each zig-zag is wider and the readout warns that training is diverging.

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 model's loss as a function of one weight is L(w) = 2(w − (−5))². Starting at w = 0 with learning rate η = 0.25, what is w after one gradient-descent step w ← w − η·dL/dw? (2 decimal places)

5.Watch

→ Watch for the cost as a landscape and the gradient as the direction of steepest climb; training walks the other way.

The clearest picture of rolling downhill on a cost surface, and of why a step can land you in a local valley.

Length: see YouTube · 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

A smooth neuron and its loss

Replace the hard step with the sigmoid σ(z) = 1/(1 + e^(−z)), which glides from 0 to 1. One neuron computes y = σ(wx + b). To measure how wrong it is on an example with target t, use the squared-error loss L = ½(y − t)². The ½ is only there to cancel a 2 when we differentiate. Training means choosing w and b to make L small across the data.

Blame by the chain rule

L depends on w only through z and y, so ∂L/∂w = (∂L/∂y)(∂y/∂z)(∂z/∂w) = (y − t) · y(1 − y) · x. Each factor has a meaning: how wrong the output is, how sensitive the sigmoid is at this point (at most 0.25, at z = 0), and how big the input was. A zero input gets no blame. The same idea, repeated backwards through layers, is backpropagation.

One step downhill

Gradient descent updates w ← w − η·∂L/∂w: move against the gradient, scaled by the learning rate η. Take w = 0.5, b = 0, x = 2, t = 1. Then z = 1, y ≈ 0.7311, ∂L/∂w ≈ (−0.2689)(0.1966)(2) ≈ −0.1058. With η = 1, w becomes ≈ 0.6058 and the loss falls from ≈ 0.0362 to ≈ 0.0263. Negative gradient, so w went up.

Choosing the learning rate

For the bowl L(w) = (w − 3)², each step multiplies the distance from the minimum by (1 − 2η). With η = 0.1 the distance shrinks by 0.8 per step: safe but slow. η = 0.5 lands exactly on the minimum. Between 0.5 and 1 it overshoots but still settles; above 1 the distance grows every step and training diverges. Real loss surfaces are not perfect bowls, which is why η is tuned and often decreased over time.

Explain it another way

You are on a foggy hillside and want the valley floor. You can only feel the slope under your feet, so you step downhill, a distance proportional to how steep it is. Tiny steps take forever; giant leaps can carry you clean over the valley and up the other side.

Derivation: ∂L/∂w for one sigmoid neuron
  1. Define z = wx + b, y = σ(z) = 1/(1 + e^(−z)), and L = ½(y − t)².

  2. Outer link: ∂L/∂y = (y − t), because the ½ cancels the 2 from differentiating a square.

  3. Middle link: dσ/dz = e^(−z)/(1 + e^(−z))² = σ(z)·(1 − σ(z)) = y(1 − y).

  4. Inner link: ∂z/∂w = x (and ∂z/∂b = 1).

  5. Multiply the links (chain rule): ∂L/∂w = (y − t) · y(1 − y) · x, and ∂L/∂b = (y − t) · y(1 − y).

  6. Update: w ← w − η(y − t)y(1 − y)x. Check with numbers: w = 0.5, b = 0, x = 2, t = 1 gives ∂L/∂w ≈ −0.1058; η = 1 gives w ≈ 0.6058, and the loss drops from ≈ 0.0362 to ≈ 0.0263.

Worked example 1

For L(w) = (w − 3)², start at w = 5 with η = 0.25. Take one step.

dL/dw = 2(5 − 3) = 4. New w = 5 − 0.25 × 4 = 4. The distance to the minimum halved, from 2 to 1, because 1 − 2η = 0.5.

Worked example 2

A sigmoid neuron has z = 0. What is σ'(z), and why does it matter?

σ(0) = 0.5, so σ'(0) = 0.5 × 0.5 = 0.25: the largest slope the sigmoid ever has. Far from z = 0 the slope tends to 0, so a saturated neuron barely learns (the vanishing-gradient problem).

Common mix-ups

  • The gradient points towards the minimum.
    ✓ It points uphill, in the direction of steepest increase. Gradient descent steps the opposite way.
  • A larger learning rate always trains faster.
    ✓ Beyond a limit set by the curvature (η > 1 for (w − 3)²) the steps overshoot and training diverges.
  • Backpropagation is a different algorithm from the chain rule.
    ✓ It is the chain rule applied layer by layer, reusing each layer's partial results.

7.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 2

What is the slope σ'(z) = σ(z)(1 − σ(z)) of the sigmoid at z = 0?

Practice 3

For L(w) = (w − 3)², start at w = 5 with learning rate η = 0.25. What is w after one gradient-descent step?

Practice 4

During training the loss jumps around and then grows larger every epoch. What is the most likely cause?

Practice 5

For one neuron, ∂L/∂w = (y − t)·y(1 − y)·x. An example has input x = 0. How much does it change w?

Practice 6 · a fresh version every time

One neuron computes y = σ(wx + b) with the sigmoid σ(z) = 1/(1 + e^(−z)). Here w = 1.4, b = 0.3, the input x = 1 and the target t = 1. The loss is L = ½(y − t)². What is ∂L/∂w? (4 decimal places)

8.Apply it

Train the one-neuron example by hand for three steps (w = 0.5, b = 0, x = 2, t = 1, η = 1), updating both w and b with ∂L/∂b = (y − t)y(1 − y). Tabulate w, b, y and L after each step and confirm the loss falls every time. Then repeat the first step with η = 20 and describe what happens to y.

9.Reflect

Concepts: Optimisation and gradient descent · Embedded machine learning