The first artificial neurons · lesson 4 of 7
Parts in this lesson
Az = X[i] @ w + bthe weighted sum, with no step
Bw = w + lr * (y[i] - z) * X[i]the Widrow–Hoff rule: move by the error, every time
Cnp.linalg.lstsq(A, y, rcond=None)3.5: the least-squares answer it heads for

Adaline

Last updated

Two years after the perceptron, Bernard Widrow and Ted Hoff at Stanford made one small change to it: learn from the weighted sum itself, before the step. That turns learning into gradient descent on a squared error, the method of Stage 3, and it fixes the perceptron's worst habit: Adaline settles down even when the classes overlap. This lesson trains it, compares it with the perceptron, and breaks it the way Stage 3 broke linear regression.

By the end of this lesson you can

  • Write Adaline's update rule, and say how it differs from the perceptron's
  • Show that the Widrow–Hoff (LMS) rule is stochastic gradient descent on squared error
  • Train Adaline in NumPy and compare its weights with the least-squares answer
  • Explain why unscaled inputs and a big learning rate make it diverge

Widrow and Hoff (1960)

In 1960, Bernard Widrow, a young professor of electrical engineering at Stanford, and his graduate student Ted Hoff built Adaline, the ADAptive LINear Element. Like the perceptron it was a single unit with a weighted sum and a step, built as a machine; Widrow soon invented a new kind of adjustable resistor for its weights, the memistor.

What was new was how it learned. The Widrow–Hoff rule, also called LMS (least mean squares) or the delta rule, was so practical that it spread far beyond neural networks: it's still used in adaptive filters, which cancel echoes on phone lines and noise in headphones. (Hoff went on to Intel, where he helped design the first microprocessor.)

Learn from the weighted sum, not the step

Adaline predicts exactly like the perceptron: the sign of the weighted sum, yˆ=sign⁡(z), with z=w⊤x+b. The difference is what it learns from:

  • The perceptron compares the label with the step's output, yˆ. The difference is 0 when it's right and ±2 when it's wrong: it only knows whether it was wrong.
  • Adaline compares the label with z, the weighted sum before the step. The difference y−z says how far off it was.

So Adaline moves on every example, by an amount that depends on its error:

w←w+η(yi−zi)xib←b+η(yi−zi)

An example far on the wrong side moves the weights a lot. An example on the right side, but with z=0.3 when the label is +1, still moves them a little, to push z towards 1. And as the weights get better, the errors shrink, and so do the steps. That's why Adaline settles where the perceptron jumps.

The squared-error loss

The rule comes from a loss. For one example, Adaline's is the squared error between the label and the weighted sum:

L=12(y−z)2z=w⊤x+b

That's exactly linear regression's loss (lesson 3.1), with the labels −1 and +1 as the numbers to predict. The 12 is there to cancel the 2 that the derivative brings down. So Adaline is a linear regression, fitted to the labels, with a step put on the end to turn its number into a class.

adaline.ipynb

Adelie against Gentoo again, scaled. The mean loss falls from 0.228 after the first epoch to 0.117, 0.071, 0.052, and is 0.038 after 20. Every penguin is classified correctly.

LMS is gradient descent

Take the derivative of L with respect to one weight, with the chain rule (lesson 1.7): z depends on wj through xj, so

∂L∂wj=−(y−z)xj∂L∂b=−(y−z)

A step of gradient descent moves against the gradient: wj←wj−η∂L/∂wj=wj+η(y−z)xj. That's the Widrow–Hoff rule. Applied one example at a time, it's stochastic gradient descent (lesson 3.6) on the squared error.

So Adaline should end up near the least-squares answer, the weights that make the mean squared error smallest, which lesson 3.5 computed exactly:

adaline.ipynb

Least squares gives weights −0.430 and 0.622 and a bias of −0.102; Adaline, after 20 epochs, −0.443, 0.608 and −0.101. Close, and closer with more epochs or a smaller learning rate at the end. Everything Stage 3 said about gradient descent, learning rates, batches and scaling now applies to a neuron.

Perceptron against Adaline

The difference shows best where the classes overlap. Both trained on Adelie and Chinstrap bills, one point at a time, in the same order:

Perceptron against AdalineAdelie and Chinstrap bills, epoch 1
bill length →, bill depth ↑ (scaled)points wrong, from epoch 1Adaline's lossepochs 0 to 20

Solid: the perceptron, 11 wrong. Dashed pink: Adaline, 9 wrong, with loss 0.276. Move the slider: the perceptron's line jumps every epoch and its count of wrong points goes up and down; Adaline's line glides and its loss only falls.

The perceptron's line jumps every epoch, and how many points it gets wrong goes up and down. Adaline's line glides into place, and its loss falls and levels off. On the separable penguins both finish happily:

adaline.ipynb

The perceptron stops after 2 epochs, its job done the moment nothing is wrong. Adaline keeps going after every point is right, because its loss isn't 0: it's still pulling each z towards its label. Its line ends up where the squared error over all the penguins is smallest, decided by every point, while the perceptron's line is wherever it happened to stop.

Adaline has a weakness of its own, though. Its loss punishes an example for being too right: a Gentoo with z=3 is "wrong" by 2, and pulls the line towards itself. Far-off examples on the correct side can drag the boundary into the wrong place. Logistic regression fixes that (lesson 5.5).

Wrong way: unscaled inputs and a big learning rate

Lesson 3.7 warned that gradient descent struggles when features are on very different scales. Adaline inherits the problem. Bill depth in millimetres (13 to 22) and flipper length in millimetres (172 to 231), not scaled, with full-batch gradient descent and a learning rate of 0.0001:

adaline.ipynb

The loss starts at 0.5, then goes 0.505, 0.563, 1.14, 6.79, 62.5, 611, 6,010: about nine times bigger every step. It's diverging. Flipper lengths around 200 make the gradient in the flipper weight's direction huge, so each step overshoots the bottom of the valley by more than it started, back and forth, further each time. A learning rate that would be tiny for scaled inputs is far too big for these.

Scale the inputs (lesson 3.7) and the same method, with a learning rate 1,000 times bigger, settles smoothly:

adaline.ipynb

0.5, 0.362, 0.266, 0.198 and down. The perceptron never had this problem, since its steps don't depend on the size of the error, but Adaline's do. The cure is lesson 3.7's: scale the features, and if the loss grows, lower the learning rate.

Check what you learned

An Adaline has w = (0.5, 0.5) and b = 0. For x = (1, 1) with y = +1, η = 0.1, what are the new weights?
An example is on the correct side of Adaline’s line. Does the Widrow–Hoff rule change the weights?
Adaline’s loss grows every epoch: 0.5, 2, 30, 900. What should you try first?

Sources

Every example on this page was run with Python 3.14, and its output and error messages are copied from it. These pages cover the same ground in more depth.

All sources for Simple Machine Learning