Perceptron applet
What is a perceptron?
A perceptron is a neuron that learns to separate input vectors
into two classes, using a linear function of the inputs. The applet
below classifies 2-dimensional input data. The other input is held at
1.0. Each input x[i] is weighted with a weight w[i]. The perceptron
computes its output value by taking the sum w[0]*x[0] + w[1]*x[1] + w[2]*x[2].
If this sum is positive, the input is classified as belonging to class 1,
otherwise to class 0.
Clearly two classes can be separated by a perceptron only if they are
linearly separable - that is, there is a linear function that separates
the two classes.
The algorithm
In general, there will be many linear functions separating the two
classes. The perceptron learns one using the following algorithm:
Randomly choose a weight vector w0;
k := 1;
while there are misclassified input vectors do
for each input vector inputi do
if inputi is in class 1 but is misclassified into class 0
update the weights so that wk := wk-1 + eta*inputi;
increment k;
else if inputi is in class 0 but is misclassified by the perceptron then
update the weights so that wk := wk-1 - eta*inputi;
increment k;
end if;
end for;
end while
Applet controls
This algorithm will converge to a solution, and you can try it out
in the applet below. When checkbox 1 is checked, you can click on the graph
to select points in class 1; likewise, when checkbox 0 is checked, you can pick points in class 0.
The command button will let you end input. When its label is "Train", pressing it
will make the program run one training round. When no points are misclassified,
the button's label will be "Restart". You can clear away the current point set
at any time by pressing the Clear button. You can select the learning rate
eta at any time to be any value 0.0 < eta <= 1.0 by entering the new value
in the text box.
Source code