Joone logo

the Joone site
SourceForge
 
   

A GUI Example

PDF
PDF

The XOR example

Here we'll illustrate an example of how to build a neural net with the GUI editor. Suppose we must build a net to teach on the classical XOR problem. In this example, the net must learn the following XOR truth table:

The XOR truth table
Input 1Input 2Output
000
011
101
110

So, we must create a file containing this values:

    0.0;0.0;0.0
    0.0;1.0;1.0
    1.0;0.0;1.0
    1.0;1.0;0.0

Each column must be separated by a semicolon; the decimal point is not mandatory if the numbers are integer. Write this file with a text editor and save it on the file system (for instance c:\joone\xor.txt in a Windows environment). Now we'll build a neural net like this:

sample XOR network

Run the editor, and execute these following steps:

  1. Add a new sigmoid layer sigmoid layer icon and set its layerName to 'Input' and the rows parameter to 2
  2. Add a new sigmoid layer, and set its layerName to 'Hidden' and the rows parameter to 3
  3. Add a new sigmoid layer, and set its layerName to 'Output', living the rows parameter to 1
  4. Connect the input layer to the hidden layer dragging a line from the little circle on the right hand side of the input layer, releasing the mouse button when the arrow is on the hidden layer
  5. Repeat the above step connecting the hidden layer to the output layer

    At this stage the screen should look similar to this:

    Three XOR layers

  6. Insert a File Input layer sigmoid layer icon to the left of the input layer, then click on it to display the properties window:
    • Set the AdvancedColumnSelector parameter to "1,2"
    • Enter c:\joone\xor.txt in the fileName parameter
    • Leave the firstRow as 1 and the lastRow as 0 so that the input layer will read all the rows in the file
  7. Connect the File Input to the input layer
  8. Insert a Teacher layer sigmoid layer icon to the right of the output layer
  9. Connect the output layer to the Teacher layer

    Now we must provide to the teacher the desired data (the last column of the file xor.txt) to train the net:

  10. Insert a File Input layer sigmoid layer icon on top of the Teacher layer, then click on it to display the properties window:
    • Set the AdvancedColumnSelector parameter to 3
    • Enter c:\joone\xor.txt in the fileName parameter
    • Leave the firstRow as 1 and the lastRow as 0 so that the input layer will read all the rows in the file
  11. Connect the Teacher layer to that last File Input layer dragging a line from the little red box on the top side of the Teacher layer, releasing the mouse button when the yellow arrow is on the last inserted File Input layer.

    At this stage the screen should look similar to this:

    Three XOR layers

  12. Click on the 'Net->Control Panel' menu item to display the control panel. Insert the following:
    • Set the epochs parameter to 10,000. This will process the file 10,000 times
    • Set the training patterns parameter to 4. This sets the number of example rows to read
    • Set the learningRate parameter to 0.8 and the momentum parameter to 0.3
    • Set the learning parameter to TRUE, as the net must be trained
  13. Click the START button, and you'll see the training process starting

The Control Panel shows the cycles remaining and the current error of the net. At the end of the last cycle, the error would be very small (less than 0.1), otherwise click on the 'Net->Randomize' menu item (to add a noise to the weights of the net) and click again on the START button.

If you want, you can save the net with the 'File->Save as' menu item, so you can use again the net later loading it from the file system.

Testing the XOR example

To test the trained net:

  1. Add an Output File layer on the right of the output layer, click on it and insert into the properties window:
    • "#topofpage" on the fileName parameter.
  2. Connect the output layer to the File Output layer
  3. Select the line that connects the output layer to the Teacher layer and click on the 'Edit->Delete' to disconnect the Teacher from the neural net
  4. On the Control Panel change the following:
    • Set the epochs parameter to 1. This will process the input file once
    • Set the learning parameter to FALSE, as the net is not being trained
  5. Click on the START button
  6. Open the xorout.txt file with an editor, and you'll see a result like this (the values can change from a run to another, depending on the initial random values of the weights):
          0.02592995527027603
          0.9664584492704527
          0.9648193164739925
          0.03994103766843536

This result shows that the neural net has learned the XOR problem, providing the correct results:

  • a value near zero when the input columns are equal to [0, 0] and [1, 1]
  • a value near one when the input columns are equal to [0, 1] and [1, 0]

Resources