NN=10000;
Offset1=0.0;Offset2=0.0;
X=2*rand(NN,2)-1;
Class=xor(X(:,1)>0+Offset1,X(:,2)>0+Offset2);
X1=X(Class,:); X2=X(~Class,:);
figure(1)
plot(X1(:,1),X1(:,2),'ro',X2(:,1),X2(:,2),'bx')
xlabel('Dimension1'); ylabel('Dimension2');
title('Random XOR data');
legend('True','False', 'Location','NorthEastOutside')
pause
%
figure(2)
w = inv(cov(X1)+cov(X2))*(mean(X1)-mean(X2))';
histogram(X*w);
title("Histogram of Fisher outputs");
pause
%
figure(3);
w = inv(cov(X1)+cov(X2))*(mean(X1)-mean(X2))';
FisherResults={X1*w X2*w};
nhist(FisherResults)
title("Distributions of Fisher outputs by true category");
pause
%
figure(4)
histogram(X*w-Class);
xlabel('Hypothesis - Truth');
title('Fisher linear discriminant for XOR: Performance on Training Data');
pause
%
figure(5)
net = feedforwardnet([2 20 20 20 1],'trainrp'); 
net = train(net,X',Class');
view(net);
Class1 = net(X');
hist(Class1)
title("Histogram of net outputs");
pause
%
figure(6)
Results = [abs(Class1)' Class];
histogram(abs(Results(:,1)-Results(:,2)));
xlabel('Hypothesis - Truth')
title('Feed Forward Net for XOR: Performance on Training Data')
xlim([0 1]);
sum(abs(Results(:,1)-Results(:,2))>0.5)
%
