Welcome to Neural Network Demo using Matlab 6.

Prepared By: Y. Michael Jiang, City College of New York, Feb. 4, 2001, Comments/Questions are welcome, please email: michael212@onebox.com.

We have all agreed that XOR problem could NOT solved using Perceptron Method, and it requires one hidden layer & one output layer, since it’s NOT linearly separable. Please note that Input Signal does NOT counted as a layer, in Matlab implementation.

Step 1: Design Phrase:

      figure 1

Here, let’s begin our demo by type in Matlab in your Unix prompt, assuming you have login the workstation successfully:
Matlab Neural Network Toolbox has been installed and should be able to access, by type in nntool, Neural Network Tool - Graphical User Interface:
If all the links have been setup successfully, you should be able to see a screen as follows, which is the outlook of NN Network/Data Manager, which is quite user friendly, but please follow the explanation closely, at least for the first time:
figure 2
Now, let’s look at the truth table of XOR for a moment:
figure 3
With Matlab, the input P & target result T, have to be expressed in term of matrices:
P=[0 0 1 1; 0 1 0 1]
T=[0 1 1 0]
Those are guidelines of Matlab implementation, please follow the rule closely.
Now, let’s enter P, T to the NN Network Manager, by click New Data once, you should see a screen like following:

      figure 4

Please type in “P” (without double quote) on Name, and corresponding matrix [0 0 1 1; 0 1 0 1] as value, select Inputs, under DataType, if it’s not on, then confirm by click on Create.

Similarly, type in “T” (without double quote) on Name, and corresponding matrix =[0 1 1 0] as value, select Targets, under DataType, if it’s not on, then confirm by click on Create.

Now, it comes the fun part, let’s create a XORNet, by click on New Network, you should see a screen like following, please change all the parameters on the screen to the values as indicated on the following screen:

figure 5
Please Make Sure:
Network Type = Feedforword Backprop
Input Ranges   = [0 1; 0 1]
Train Function= TRAINLM
Adaption Learning Function = LEARNGDM

Performance Function = MSE

Numbers of Layer = 2

Here is one of the tricky parts:

Select Layer 1, type in “2” (without quote) for the number of neurons, & select TANSIG as Transfer Function.

Select Layer 2, type in “1” (without quote) for the number of neurons, & select TANSIG as Transfer Function.

Then, please confirm by hitting Create button, which concludes the XOR network implementation phrase.

Step 2:            Network Training:

Now, highlight XORNet with ONE click, then click on Train button, a screen will appear just like following:

      figure 6

On Training Info, please select P as Inputs, T as Targets.

On Training Parameters, please specify:

1000 for epochs, since we’d like to have longer duration for the train.

0.000000000000001 for goal, since we would like to see if the XORNet we just implemented is capable to produce high precise result.

50 for max_fail.

After, confirming all the parameters have been specified as indented, please hit on Train Network for live action of the training and performance plot, you should get a decaying plot similar to the following plot, but may NOT be exact shape, due to the randomness of the calculation:

      figure 7

Now, we could confirm the XORNet structure and values of various Weights and Bias of the trained network, by click of View on Network/Data Manager, see figure 8:

      figure 8
*** For any reason, if the show did not come up as expected, please save yourself valuable time, by delete and recreate XORNet and follow closely on the procedures.

Now, the XORNet has been trained successfully and ready for simulation if needed.

Step 3:             Network simulation:

With trained network, simulation is a way of testing on the network to see if it meets our expectation.

Now, create a new testing data S (with a matrix [1; 0] representing a set of two inputs) on the NN Network Manager, follow the same procedure just like what you did with Input P, on Step 1.
HighLight XORNet again with one click, then click on Simulate button on the Network Manager. Select S as Inputs, type in “XORNet_outputsSim” (without quote) as Outputs, then hit Simulate Network button and check the result of XORNet_outputSim on the NN Network Manager, by click View.

This concludes the whole process of XOR network design, training & simulation. 

We hope this demo has been helpful to each one of you, by introducing the nntool. Enjoy your journey on the road of computing. For more reference, please visit www.mathworks.com & www.mathtools.net.