%Multilayer Perceptron implementation Example
%XOR Function
%Neural Nets, Spring 00, S. Mandayam, ECE Dept., Rowan Univ.

clear;close all;

%Define a 2-3-1 MLP with Sigmoidal Neurons at the Hidden 
%and output layers; train using gradient descent backprop
net=newff([0 1; 0 1],[3,1],{'logsig','logsig'},'traingdm');

%Show training progress every 50 epochs
net.trainParam.show=50;

%Momentum constant
net.trainParam.mc=0.9;

%Set learning rate to 0.5
net.trainParam.lr=0.5;

%Set maximum epochs to 1000
net.trainParam.epochs=1000;

%Set error goal to 0.01
net.trainparam.goal=1e-2;

%Define training input and target data vectors
p=[[0;0],[0;1],[1;0],[1;1]];
t=[0 1 1 0];

%train the network
net=train(net,p,t);
figure; plotpv(p,t);

%Test network
a1=sim(net,[0;0])
a2=sim(net,[1;0])


