The simplest neural network is a single neuron that learns by a simple rule. Deeper networks need a more powerful method.
The Perceptron
The perceptron, by Rosenblatt in 1958, is a single neuron with a step activation. It computes y = 1 if the weighted sum plus the bias is above 0, otherwise 0. It can learn to separate two classes if they are linearly separable, that is, if a straight line can divide them. The perceptron learning rule adjusts each weight after every example: w = w + η × (t - y) × x, where η is the learning rate, t is the target, and y is the actual output. If the output is right, nothing changes. Perceptrons learn the AND and OR functions, but they cannot learn XOR, since XOR is not linearly separable. This limit, shown by Minsky and Papert in 1969, slowed the field until multi-layer networks were trained.
Definition: Perceptron. A single artificial neuron with a threshold activation that classifies inputs into two classes, learning by adjusting its weights according to the error on each example.
Multi-Layer Networks
Adding one or more hidden layers lets a network learn non-linear functions, including XOR. A feed-forward network passes values from input to output without loops. With enough hidden units, such a network can approximate any continuous function, a result called the universal approximation theorem.
Back Propagation
Back propagation is the method that trains multi-layer networks. It repeats the following steps. In the forward pass, the input is passed through the layers to give an output. The error is found by comparing the output with the target, often as the squared difference. In the backward pass, the error is sent back from the output layer, and each weight's share in the error is found by the chain rule of calculus. Each weight is then changed in the direction that reduces the error: w = w - η × ∂E/∂w. This is gradient descent. The process is repeated for all examples over many epochs until the error is small. Problems are local minima, slow training and over-fitting, when the network learns the training data too well and fails on new data, which is reduced by more data, early stopping and regularisation.
Applications
Neural networks are used in image and speech recognition, handwriting recognition, medical diagnosis, prediction of sales and stock trends, language translation, control of robots and vehicles, and fraud detection.
Table 4.3: Perceptron and back propagation
| Feature | Perceptron | Multi-layer network |
|---|---|---|
| Layers | One | Input, hidden, output |
| Learns | Linearly separable functions | Non-linear functions |
| XOR | Cannot learn | Can learn |
| Training rule | Perceptron rule | Back propagation |
Example 4.3: Training a perceptron on AND
Problem: Train a perceptron for AND with inputs (0,0), (0,1), (1,0), (1,1), targets 0, 0, 0, 1. Start with w1 = 0, w2 = 0, b = 0, and learning rate 1. Show the first pass.
Solution:
- (0,0): sum 0, output 0, target 0, no change.
- (0,1): sum 0, output 0, target 0, no change.
- (1,0): sum 0, output 0, target 0, no change.
- (1,1): sum 0, output 0, target 1, error 1. Update w1 = 1, w2 = 1, b = 1.
- Further passes bring the weights to values such as w1 = 1, w2 = 1, b = -1, which give the right output for all four inputs.
Result: The perceptron learns AND with weights near (1, 1) and bias -1.
data = [((0,0),0), ((0,1),0), ((1,0),0), ((1,1),1)]
w, b = [0, 0], 0
for _ in range(10):
for (x1, x2), t in data:
y = 1 if w[0]*x1 + w[1]*x2 + b > 0 else 0
e = t - y
w[0] += e * x1
w[1] += e * x2
b += e
print(w, b)
Output
[2, 1] -2
Common mistakes
- Trying to learn XOR with a single perceptron.
- Using too high a learning rate, so that the weights jump around the minimum.
- Training too long and over-fitting the training data.
Key takeaways
- A perceptron is a single threshold neuron, and it learns only linearly separable functions.
- The rule is w = w + η(t - y)x.
- Back propagation sends the error backward and uses gradient descent.
- Over-fitting is learning the training data too closely.
Practice questions
- Why can a perceptron not learn XOR?
- Write the perceptron learning rule.
- What does back propagation do?
Answers to the practice questions
- XOR is not linearly separable, and a single perceptron can only draw a straight dividing line.
- w = w + η(t - y)x.
- It sends the output error backward through the layers and adjusts the weights by gradient descent.
Sources
- Official BCA syllabus Artificial Intelligence and Expert Systems, course code 25BCA405DS02, Unit IV
