Where One Perceptron Fails

XOR cannot be computed by a single perceptron, and real-world data often has the same problem.

Deep Learning- Fundamentals to Advanced Concepts

We have seen that a perceptron draws a straight line. So what kind of function can it never compute?

XOR

XOR (exclusive or) outputs 1 when exactly one input is 1:

x1x_1x2x_2XOR
000
011
101
110

Plot the four points. The two 1-outputs are at opposite corners of the square, and so are the two 0-outputs. There is no straight line with both 1-corners on one side and both 0-corners on the other.

Four points on a square with opposite corners sharing a class, so no single line separates them
Opposite corners share a class. No single line works.
Try it yourself
XOR problem simulator →

Try to find a line that classifies all four points. Then see what changes when a second layer is added.

The algebra agrees

Suppose some w0,w1,w2w_0, w_1, w_2 did compute XOR. The four rows would require:

  1. w0<0w_0 < 0
  2. w0+w2≥0w_0 + w_2 \ge 0
  3. w0+w1≥0w_0 + w_1 \ge 0
  4. w0+w1+w2<0w_0 + w_1 + w_2 < 0

Add rows 2 and 3: 2w0+w1+w2≥02w_0 + w_1 + w_2 \ge 0, so w1+w2≥−2w0w_1 + w_2 \ge -2w_0. Row 4 says w1+w2<−w0w_1 + w_2 < -w_0.

Together, −2w0≤w1+w2<−w0-2w_0 \le w_1 + w_2 < -w_0, which forces −2w0<−w0-2w_0 < -w_0, that is, w0>0w_0 > 0. But row 1 says w0<0w_0 < 0. Contradiction, so no such weights exist. No learning algorithm can find them either.

How common is this?

Two binary inputs give 24=162^4 = 16 possible Boolean functions. Of these, 14 are linearly separable, and only XOR and its opposite XNOR are not. So the failure is rare among two-input functions. It becomes far more common as inputs grow.

In general, nn binary inputs give 2n2^n possible input rows, and each row can output 0 or 1, so there are 22n2^{2^n} Boolean functions. That is 16 for n=2n = 2, 256 for n=3n = 3, and over 4 billion for n=5n = 5. How many of them are linearly separable has no simple formula. Counting them is a hard problem that researchers have worked out only for small nn. What we can say is that some are not separable, and that is enough to need something more than one perceptron.

Real data rarely separates cleanly

The film example has the same flavour. Real preferences are messy: you might like a thriller only when it is by a particular director, or a comedy only when a certain actor is in it. Interactions like this are exactly what a single straight line cannot capture. A dataset of past films will usually not be linearly separable.

Two common reasons:

  • Outliers. Among people who fit the profile of someone who enjoys machine learning, a few still do not. Among the people of one neighbourhood who mostly speak one language, a few speak another.
  • Genuinely curved boundaries. Picture one group forming an inner ring and another an outer ring around it. There are no outliers at all, yet no straight line separates them.
What this means for the algorithm

On non-separable data, the perceptron learning algorithm never reaches a clean pass. It keeps correcting forever. A single perceptron is simply too weak for such problems.

A way out

The problem was not perceptrons. It was using one. Stacking several perceptrons, where some feed into another, changes what can be computed. The next lesson shows a network that solves XOR and, in fact, any Boolean function.

HardXORPerceptron

Show with inequalities that one perceptron cannot compute XOR.

MediumXOR

Which two-input Boolean functions are not linearly separable?