COGS Q350 - Making Neural Networks Learn

In order to train neural networks, we will extract a random row of a truth table, let the network calculate the truth value for that row of the truth table. If the network has made a mistake, we will modify the weights. If no error is made, the weights stay the same. Then we randomly choose another row and repeat the process.

x1 x2 Desired Output OutputoutError What We Will Do outError * (x1,x2)
1 1 1 -1   Raise both weights (1,1)
1 1 -1 1   Lower both weights (-1,-1)
1 -1 1 -1   Raise w1, lower w2 (1,-1)
1 -1 -1 1   Lower w1, raise w2 (-1,1)
-1 1 1 -1   Lower w1, raise w2 (-1,1)
-1 1 -1 1   Raise w1, lower w2 (1,-1)
-1 -1 1 -1   Lower both weights (-1,-1)
-1 -1 -1 1   Raise both weights (1,1)


Start with randomly generated weights, w1 and w2, in the range [-1, 1].
Start with a threshold value and a learnrate.
outError = (desiredOutput - output) / 2

Repeat the following:

Randomly choose a row in the truth table.
Calculate net = (w1,w2) * (x1,x2)
If net is greater than the threshold value, then output 1, otherwise output -1. That is, output = If[net > threshold, 1, -1].
If output is not = desiredOutput, calculate new weights:
The formula for the new weights is:
(w1,w2) += learnrate*outError*(x1,x2)

where outError = (desiredOutput - output) / 2. So
(w1,w2) += learnrate * [(desiredOutput - output) / 2] * (x1,x2)

We continue iterations until the output equals the desired output for all 4 rows of the truth table

Example: Teach a neural network to output truth values for disjunction.

Let w1 and w2 be randomly chosen weights such that w1=-0.1 and w2=0.4
Let the threshold value = 0.4
Let the learnrate = 0.2