Linear Models & the Perceptron
The simplest learners (linear regression, logistic regression, the perceptron) already contain the whole template: a weighted sum, a loss, a gradient step. They also fail on the XOR problem, which no linear model can solve — the limitation that motivates deep learning.
╌╌╌╌
The shortest path into deep learning is to start with the shallowest model and watch exactly where it breaks. A linear model computes a weighted sum of its inputs plus a bias,
and reads a prediction off . Three classic learners differ only in how they turn into an answer and how they measure error, but all three share the template every network inherits: score, compare, descend. Folding the bias into via the convention , they line up term-for-term:
| model | prediction | output range | per-example loss | gradient | use-case |
|---|---|---|---|---|---|
| linear regression | real-valued targets | ||||
| logistic regression | class probabilities | ||||
| perceptron | on a mistake, else | hard separation |
The middle column is the activation; the loss column is the only place the three truly diverge. Yet the gradient column nearly collapses: every entry is the same prediction-minus-target-times-input residual, which is why one descent loop trains all three.1
Linear regression
For real-valued targets, take the prediction to be itself, , and measure error by squared distance. Over the training set that is the mean squared error
This one is special: it is convex and quadratic, so it has a closed-form minimizer. Stack the examples as rows of and targets as (bias absorbed via ); the objective and its gradient are
Setting the gradient to zero and dropping the scalar gives the normal equations and, when is invertible, the closed-form optimum:
We will almost never have that luxury again — but the residual gradient , one row of which is , is the object every later model descends.
For example, take data and fit a line . With the bias column of ones, and , so
Inverting the system (determinant ) gives
the best-fit line . Its residuals are , which sum to zero — the signature of a least-squares fit, where the residual vector is orthogonal to every column of , including the all-ones bias column. That orthogonality restates the normal equation as a geometric fact.
Logistic regression
For binary classification we want a probability, not an unbounded score. Squash through the logistic sigmoid
The right loss is again maximum likelihood: the binary cross-entropy with , . Its gradient follows from the chain rule and the identity :
The two factors cancel the awkward denominator, and a final delivers the same clean residual as least squares:
That identical gradient across both models is no coincidence; it is a property of the whole exponential family, and it is the reason a single optimization loop trains them all.2
One gradient step, worked end to end, shows how the residual drives the update. Take a single example with label , current weights . The score is , so : the model is maximally unsure. The residual is , and the gradient is
Descending with learning rate gives . Re-scoring the same point, , so — the prediction has moved decisively toward the correct label . The step magnitude scaled with the residual: a confident correct prediction () would have produced almost no update, which is why cross-entropy training slows as the model gets the answer right.
Geometrically, the model splits the input space with a flat decision boundary, the hyperplane . The weight vector points perpendicular to it, toward the positive class; the signed distance of a point from the boundary is , and the sigmoid turns that distance into a probability: far on the positive side , far on the negative side , on the boundary .
Three models, then, and one shared skeleton: linear regression reads directly, logistic regression squashes it to a probability, and, historically first, the perceptron simply thresholds it.
The perceptron
Historically first (Rosenblatt, 1958), the perceptron is the hard-threshold
version: predict if , else , and on each misclassified example
nudge the weights toward getting it right.3 Drawn as a unit, it is the template
every later neuron
copies — inputs scaled by weights, summed, thresholded:
The update is not ad hoc: it is stochastic (sub)gradient descent on the perceptron loss , which is zero when (correct, off the boundary) and grows linearly into the misclassified region. Its subgradient is piecewise:
so the descent step with is exactly on a mistake and a no-op otherwise, the algorithm below.
- 1initialize
- 2repeat
- 3for each example with do
- 4if thenmisclassified
- 5
- 6
- 7until no mistakes on a full pass
- 8return
Tracing the loop on four points shows it converge. Take , and start from , . Each row below checks , updates on a mistake (), and carries the new weights forward:
| step | example | action | new | ||
|---|---|---|---|---|---|
| 1 | mistake: | ||||
| 2 | correct: no change | ||||
| 3 | mistake: | ||||
| 4 | correct: no change |
A second pass over all four points now finds every product (for instance the first point gives , the third ), so the loop halts with the separator , — the vertical line , which cleanly divides the two positive points on the right from the two negatives on the left. Each update moved the boundary exactly toward the point it had misclassified, and because the four points are separable, the mistake bound below guarantees this could not go on forever.
Geometrically the update rotates the boundary toward the missed point. With but , the point sits on the wrong side; adding to swings the weight vector toward , and since the boundary is the hyperplane normal to , it rotates with it until falls on the correct side.
If the data is linearly separable this rotation cannot continue forever: the number of updates is bounded independently of the data's size.4
The bound is worth reading as a rate, not just a finiteness guarantee. For the four-point run above, the points have radius (from or ), and the separator places every point at horizontal distance or , so the margin is with the unit normal giving . The bound predicts at most updates; the run made just , comfortably inside it. The ratio shows that thin margins (small ) are expensive: halving the margin quadruples the worst-case number of updates, which is why the maximum-margin classifiers discussed below deliberately maximize .
The hypothesis is the catch: the data must be linearly separable, and often it is not.
The wall: XOR
Consider four points and the exclusive-or labelling: output when exactly one input is on.
This is not a quirk of XOR; it is the generic situation. Real data — pixels, phonemes, words — is shot through with such interactions, regions where the useful boundary is curved, folded, disconnected. A single linear layer can never bend.5
The fix is composition
The fix is to map the inputs through a nonlinear intermediate layer first, then apply a linear model to that. With one hidden layer of two ReLU units, XOR becomes linearly separable in the new representation — the network learns coordinates in which a straight line does work.
Concretely, take hidden units and . Pushing all four inputs through gives the hidden coordinates in full:
| input | label | readout | ||
|---|---|---|---|---|
Both -labelled corners and land at , while the two -labelled corners collapse onto . The readout weights with a threshold at now split the classes perfectly. In the plane a single line separates them, so the linear readout that failed on the raw inputs succeeds on the learned ones — the nonlinear ReLU folded the plane so that the two diagonals no longer interleave.
That single move, stacked and scaled, is the multilayer perceptron — and the rest of deep learning.6
The XOR wall and the kernel escape
The XOR limitation shaped the field's
history. Minsky and Papert's Perceptrons (1969) proved exactly the claim above —
that a single-layer perceptron cannot represent XOR (or any function that is not
linearly separable) — and their book is often blamed for the funding collapse that
became the first AI winter.
The escape they doubted, a trainable multi-layer
network, waited until back-propagation was popularized by Rumelhart, Hinton, and
Williams (1986), which supplied the gradient that the perceptron's discrete update
could not.
A second, parallel fix for the same limitation is worth knowing. Instead of learning a nonlinear feature map , the kernel trick fixes a map into a very high-dimensional space and works with inner products there without ever computing explicitly. The support vector machine (Cortes and Vapnik, 1995) pairs this with a maximum-margin objective — a principled version of the perceptron's separator that chooses the boundary of largest margin rather than any separator at all. XOR becomes trivially separable under a quadratic kernel. For two decades SVMs were the dominant method precisely because they, too, broke linear separability; deep learning won out because it learns the representation rather than fixing it in advance, exactly the automation of that the opening lesson frames as the whole point.78
Footnotes
- Goodfellow, Deep Learning, §5.1.4 — linear regression as the worked example of a learning algorithm: the squared-error objective, its closed-form normal-equations solution, and the residual gradient every later model inherits. ↩
- Goodfellow, Deep Learning, §5.7.2; §6.2.2.2 — logistic regression and sigmoid output units: binary cross-entropy as the maximum-likelihood loss and the gradient shared across the exponential family. ↩
- Goodfellow, Deep Learning, §1.2.1; §6.1 — the perceptron in historical context: Rosenblatt's threshold unit as the ancestor of the modern artificial neuron, and the mistake-driven update rule. ↩
- Goodfellow, Deep Learning, §5.9 — linear separability and convergence: a margin and radius bound the perceptron's mistakes by , independent of sample size, when the data is separable. ↩
- Goodfellow, Deep Learning, §6.1 — Example: Learning XOR: the canonical proof that no linear model computes XOR, and the motivation for a nonlinear hidden layer. ↩
- Chollet, Deep Learning with Python, §2.3; §3.1 — stacking a nonlinear hidden layer to learn a representation in which the problem becomes linearly separable, the move that defines the multilayer perceptron. ↩
- Minsky and Papert (1969), Perceptrons, MIT Press — the proof that a single-layer perceptron cannot compute non-linearly-separable functions such as XOR; and Rumelhart, Hinton, Williams (1986), Learning representations by back-propagating errors, Nature 323, which supplied the gradient training the multi-layer network the critique had ruled out. ↩
- Cortes and Vapnik (1995), Support-Vector Networks, Machine Learning 20 — the maximum-margin classifier and the kernel trick, the pre-deep-learning route to non-linear separation by a fixed high-dimensional feature map rather than a learned one. ↩
╌╌ END ╌╌