%
% Example with two spirals
%
clear

load dados_two_spirals_XY_944

n=fix(size(X,1)/4);

alt=randperm(size(X,1));
X=X(alt,:);
Y=Y(alt);

% Training
P=X(1:2*n,:)'; 
cP=Y(1:2*n)'>=0;

% Validation
V=X(2*n+1:3*n,:)'; 
cV=Y(2*n+1:3*n)'>=0;

% Test
T=X(3*n+1:4*n,:)'; 
cT=Y(3*n+1:4*n)'>=0;

clear X; clear Y; clear alt;

[p,W,EX,EV,ET]=LearnSLMP(P,cP,V,cV,T,cT);
% Or [p,W,EX,EV,ET]=LearnSLMPA(P,cP,V,cV,T,cT);

figure(2);
plot(1:length(EX),EX,'--k',1:length(EV),EV,'-.b',1:length(ET),ET,'-r');
legend('Training Error','Validation Error','Test Error');

% Select the dendrites that minimizes the validation error.
[aux,ind]=min(EV);
disp(sprintf('\n We selected %d dendrites. In this case, the validation error is %0.4f (minimum) and the test error is %0.4f.\n',ind,aux,ET(ind)));

figure(1);
verclasse(p,W,T,cT)
title('Test set and the region for the SLMP');
