2.3 A human separation
How does a neural “network” consisting of one neuron with two inputs and one output learn to make decisions?
In the example with the digital bouncer, a neuron with a single input could be used to make a decision such as YES / NO. In the following, this will be extended to two inputs. Instead of the age of a person, the width and length of animals (measured in mm) will now be used as inputs. Here too, the neuron should make a binary decision with two options: whereas in the previous example 0 stood for no and 1 for yes, now 0 will stand for ladybird and 1 for caterpillar.
But why does this have to be encoded this way? The idea is as follows: Some ladybirds (red in the linked interactive figure below) are measured. These are listed in the table and already entered in the interactive figure. For these ladybirds, you now specify that the neuron should, at the end of its training process, output values that are as close to 0 as possible so that they can be identified as ladybirds. The so-called class of ladybirds is therefore labelled with 0, which is entered in the table accordingly. We proceed in the same way with the caterpillars (green in the figure below) but assign them the class with the number 1. Once the neuron is trained with this data and is able to make correct decisions, it can also correctly classify indeterminate animals: If you measure an animal that you cannot identify and enter, say, the input values (5.0 / 5.5), an output value close to 0 will correctly predict that it is a ladybird rather than a caterpillar. This works even if you have never measured an animal with exactly these dimensions before. The measured data is given in the table below.
x1 (width) and x2 (length) are the input values and y is the desired output value (0 = ladybird / 1 = caterpillar):
x1 (width) | x2 (length) | y (class) |
---|---|---|
5.0 | 5.0 | 0 |
6.0 | 5.5 | 0 |
5.5 | 6.0 | 0 |
6.5 | 6.0 | 0 |
6.0 | 6.5 | 0 |
7.0 | 7.5 | 0 |
3.0 | 7.5 | 1 |
2.5 | 8.0 | 1 |
3.5 | 8.5 | 1 |
2.0 | 9.0 | 1 |
3.5 | 9.5 | 1 |
2.0 | 9.5 | 1 |
Now you just have to get the neuron to calculate the correct output data for the respective input data. This task can be carried out below by changing the weights and the threshold value of the neuron in the interactive figure until the neuron finds a correct separating line between the two classes of ladybirds and caterpillars, thus enabling a decision such as “all caterpillars are on the left above the separating line and all ladybirds are on the right below the separating line”. To verify, two unknown animals (marked in brown) were integrated into the figure; the left one should of course be identified as a caterpillar and the right one as a ladybird. The colouring in the background of the figure helps with this, as it displays the neuron's current prediction when you hover the mouse over the two brown dots. Since the neuron is equipped with random starting values, it is unlikely to make correct predictions in the beginning without manual training.
Instructions
- Click on the minus or plus signs to change the values for the weights w1 and w2 or the threshold value b.
- Hover the mouse over ladybirds or caterpillars in the figure: The box below the coordinate system will display which animal it is and what its measures are. Under the neuron, on the other hand, you will see which animal the neuron considers it to be. In addition, the complete calculation of the output is displayed (the animal is considered to be a ladybird when the output value is below 0.5 and a caterpillar when it is above 0.5).
- Click in the coordinate system to add new animals.
- Hover the mouse over the brown dots in the figure representing unknown animals: A prediction of which animal it could be and what its measures are is displayed below the coordinate system. Under the neuron you will see the complete calculation of the respective output.
- In the figure, red stands for ladybirds and green stands for caterpillars. The colouring in the background of the figure also indicates whether the respective values for width and length are more likely to be identified as ladybirds (red) or as caterpillars (green).
Tasks
- Change the neuron’s weights and threshold until the unknown animal on the left is correctly identified as a caterpillar and the unknown animal on the right is correctly identified as a ladybird. Check the calculation of the neuron for each animal.
- Add a few new animals and check whether they are identified correctly.
- Add an unknown ladybird and an unknown caterpillar, each far in its own half. Change the weights and the threshold so that both animals are correctly identified (i.e. predicted) with an accuracy of at least 90%.
If you have been successful, you have managed to do what a neuron manages to do with the so-called learning algorithm, which is to adjust weights and thresholds until all (or enough) training data (the rows in the table shown above) are correct, i.e. the correct class is output for each width and length.
Share this page