XOR, from the perceptron to one step of training
numeric▲▲△Exact values where possible; six decimal places otherwise.
STATEMENT
Show that no perceptron computes XOR, that a two-unit ReLU network does, and then backpropagate through that network after one of its weights has been disturbed and take a gradient step.
GIVEN
The four XOR examples: , , , . The network, with :
The loss is the mean squared error over the four examples. For the second part, and the step size is .
FIND
Why no threshold unit fits the data; the network’s outputs; after disturbing , the loss and the gradients with respect to , the bias of and the bias of ; the new .
STRATEGY
Write the perceptron’s four conditions as inequalities (I.2). For the network, only the example has an error after the disturbance, so the backward pass of I.6 runs through one example.
SOLUTION
No perceptron. The examples require for , and for the two positives, and for . Adding the middle two gives , so , contradicting the last. The positives and negatives are not linearly separable (I.2.P04), and no learning rule changes that.
The network. At the hidden units are , , and , so
The ReLU’s kink at is what a linear map cannot supply (I.3.P01): the network bends the line once and folds the fourth example back to zero.
Disturbed. With the last output is and the others are unchanged. The loss is . The output error is at and zero elsewhere, so
One step. Gradient descent moves to , back towards . The gradient supplied the direction and the step size of was a choice (I.7.P01). Repeating the step halves the remaining error each time: , then , approaching without reaching it.
Answer
The four perceptron inequalities contradict each other. The network outputs . Disturbed: loss , gradients , and ; after one step .
Check — sanity
The gradient with respect to is positive because raising makes the wrong output larger. The script confirms it with a central finite difference.
Check — numeric · i-book-checks.py
The complete reproduction script uses only the Python standard library. From a checkout of the repository, run:
python3 scripts/snippets/i-book-checks.pyIt checks all eight problems of the Book I set. For this one it also searches perceptrons on a grid and confirms none fits XOR.
Executed in CI. The digits above are the digits it printed.
Where this breaks
The network computes a function of alone, so it cannot represent the other three Boolean functions of two inputs that need and separately. Two hidden units suffice for XOR because XOR is symmetric.
Variation
With every error is zero and so is every gradient: XOR is a global minimum. Disturbing the bias of instead moves the kink, and then several examples err at once.