clc;
clear all
close all;
%Dimensionality reduction using LDA before subjected to SVM
load TRAINLPC
s=[];
for i=1:1:3
    s=[s size(TRAINLPC{i},1)];
end
x=min(s);
DATA=[];
for i=1:1:3
    DATA=[DATA TRAINLPC{i}(1:1:x,:)];
end
U=isnan(DATA);
[R,S]=find(U==1);
for i=1:1:length(R)
    DATA(R(i),S(i))=eps;
end
SW=cov(DATA(:,1:1:5)',1)+cov(DATA(:,6:1:10)',1)+cov(DATA(:,11:1:15)',1);
[E1,V1]=eigs(SW,12);
for i=1:1:15
PR(:,i)=DATA(:,i)-E1*E1'*DATA(:,i);
end
M1=mean(PR(:,1:1:5)');
M2=mean(PR(:,6:1:10)');
M3=mean(PR(:,11:1:15)');
SB=cov([M1' M2' M3']',1);
[E,D]=eigs(SB,2);
%Projected vectors (P)
P=E'*DATA;
%mi=min(min(P));
%P=P-mi+eps;
%ma=max(max(abs(P)));
%P=P/ma;
M=P'*P;
CLUSTER1=1:1:5;
Y=[ones(1,5) ones(1,10)*(-1)];
POS1=dosvm(M,Y,P,x,E,CLUSTER1);
CLUSTER2=6:1:10;
Y=[ones(1,5)*(-1) ones(1,5) ones(1,5)*(-1)];
POS2=dosvm(M,Y,P,x,E,CLUSTER2);
CLUSTER3=11:1:15;
Y=[ones(1,10)*(-1) ones(1,5)*(1)];
POS3=dosvm(M,Y,P,x,E,CLUSTER3);


    



