Main Menu

Training the Neural Network using Back Propagation

Back Propagation is the standard way of training neural networks, although there are other ways (which I shall consider in a later chapter). It works basically like this:

  • The input pattern on which the network is to be trained is presented at the input layer of the net and the net is run normally to see what output it actually does produce.
  • The actual output is compared to the desired output for that input pattern. The differences between actual and desired form an error pattern.
  • The error pattern is used to adjust the weights on the output layer so that the error pattern would be reduced the next time if the same pattern were presented at the inputs.
  • Then the weights of the hidden layer are adjusted similarly, this time comparing what they actually produce with the neurons in the output layer to form an error pattern for the hidden layer.

  • Finally, if there is an input layer (as opposed to simply a set of points where the input is passed into the network), then the weights for that layer are trained similarly. Indeed, the error can be propagated as far back as you like, over as many layers as you like.

    Back propagation always reminds me of waves on a beach - the input signal moves forward through the network and the errors trickle backwards (they "propagate backwards", hence the name), followed by the next signal.

    The network is trained by presenting each input pattern in turn at the inputs and propagating forwards and backward, followed by the next input pattern. Then this cycle is repeated several (many?) times. For instance, if you were training a net to recognise the digits 0 to 9, you would propagate it once on digit 0, followed by one go on digit 1 etc. until you reached 9. Then you would repeat the process many times more, the network getting closer and closer to the required weight values each time.

    The reason for not putting input pattern 0 at the inputs and propagating many times over before moving to pattern 1 and doing that many times, is that the network would develop weights that would only reflect the pattern on which it was being trained at the time. By the time it had undergone 1000 cycles of training on pattern 1, it would have lost all the weight values it had for recognising pattern 0. By cycling the patterns repeatedly it is to be hoped that the net develops average weight values that are sufficient for every pattern in the "vocabulary" it has to learn.

    Remember

    NUM_HID is the number of nodes in the hidden layer (we start counting at 1).

    NUM_OUT is the number of nodes in the output layer.

    The Back Propagation formulae

    Right, brace yourself! I'm going to throw lots of mathematical gibberish at you in quick succession. Ready? Right, now read on ....

    A Java Simulation of all this

    Having given you the code in Pascal, I am about to do a complete volte face (Oooh!) and give you a Java version of a neural network that is trained by back propagation. Here it is:

    If you want the Java source code for this, then click here. Feel free to alter it as much as you like, of course.

    If you want the Java class file, which you can include on your web site of course, then click here.

    The network, as it stands has a fixed number of inputs (6) and a fixed number of outputs (5). The hidden nodes in the middle are represented by the blue blobs.

    The training patterns are represented on the left side of the screen. To set a training pattern, both the input and the desired output, click the mouse on the column of 6 input squares or the column of 5 output squares. Each mouse click darkens the square, where white represents 0, light gray represents 0.3, dark gray represents 0.7 and black represents 1. The sequence cycles, so clicking on a black square sets it to white again.
    This combination of inputs and outputs represents the training pattern with the input set to (1, 0, 0, 0.3, 0, 0.7) and the desired output set to (0, 0, 0.7, 0.7, 0). Click on the + symbol or the - symbol next to the word "Training patterns" to increase or decrease the number of training patterns.

    To train the network on the input patterns that you have set up, click on the Train icon. To test the neural network you need to enter figures into the slots by the input nodes in the middle of the screen. You do this by entering figures into the slot at the top, then clicking on the input value that you want to change. When you want to run the test pattern, just click on the Run icon.


    Go back
    Top
    Go on