%该函数运行实现不同方法对于测试样本集的分类
%设置的变化有：label比例、循环10次
%伪代码如下
%***********start***********************
%获得初始数据（为区分有无标签训练集和选出的固定测试集）
%for label 比例
%     for  循环次数1：N
%         计算获得label样本集，unlabel样本集
%         计算NN SVM ELM三种方法的训练测试输入和输出集合
%         计算GLCC的训练测试输入输出集合
%          精度=NN（训练集，测试集）（参数按经验值）
%          精度=SVR（训练集，测试集）（参数按经验值）
%          精度=ELM（训练集，测试集）（参数按经验值）
%          精度=GLCC（训练集，测试集）（参数按经验值）
%     记录该次循环下的各方法的精度
%     end （循环次数）
%     记录该比例下，各种方法循环N次的平均值
%end（label比例）

clear;clc
for LabeledSampNum=10
for AlldataNum=5:10
allres=[];
load netdata.mat
%请在此处修改训练数据
xx1=A1;
tt1=T1; 
%请在此处修改测试数据
eval(['xx2=A',num2str(AlldataNum),';']);
eval(['tt2=T',num2str(AlldataNum),';']);
% xx2=A4;
% tt2=T4;

[mt,nt]=size(xx1);
A=[xx1;xx2];

[m n] = size(A);
% normalize each row to unit
for i = 1:n
    A(:,i)=A(:,i)/max(abs(A(:,i)));
end
xx1=A(1:mt,:);
xx2=A(mt+1:end,:);
traindata=xx1';
testdata=xx2';
%*********************************************************
%以下一段代码是与setting2 不同的代码需要将xx2 中的一部分（20个label转移到xx1）  目标tt也要变动。
[mx nx]=size(testdata);
numseries=randperm(nx);
traindata=[traindata,testdata(:,numseries(1:LabeledSampNum))];
testdata=testdata(:,numseries(LabeledSampNum+1:nx));
tt1=[tt1;tt2(numseries(1:LabeledSampNum),1)];
tt2=tt2(numseries(LabeledSampNum+1:nx),1);
%%%*************************************************************

[m1 n1]=size(traindata);%m 维数 n 样本个数
t1=-1*ones(6,n1);

for i=1:n1
    switch (tt1(i))
        case 1
            t1(1,i)=1;
        case 2
            t1(2,i)=1;
        case 3
            t1(3,i)=1;
        case 4
            t1(4,i)=1;
        case 5
            t1(5,i)=1;
        case 6
            t1(6,i)=1;
    end
end
[m2 n2]=size(testdata);
t2=-1*ones(6,n2);
ttt2=zeros(6,n2);
for i=1:n2
    switch (tt2(i))
        case 1
            t2(1,i)=1;
        case 2
            t2(2,i)=1;
        case 3
            t2(3,i)=1;
        case 4
            t2(4,i)=1;
        case 5
            t2(5,i)=1;
        case 6
            t2(6,i)=1;
    end
end
train_P=traindata;
train_T=t1;
test_P=testdata;
test_T=t2;

train_P=[train_P test_P];
train_T=[train_T ttt2];





for jj=-4:4  %核参数
    corep=2^(jj);
    X=reshape(train_P,8,16,n1+n2);
    X1=reshape(X(1,:,:),16,n1+n2);
    X2=reshape(X(2,:,:),16,n1+n2);
    X3=reshape(X(3,:,:),16,n1+n2);
    X4=reshape(X(4,:,:),16,n1+n2);
    X5=reshape(X(5,:,:),16,n1+n2);
    X6=reshape(X(6,:,:),16,n1+n2);
    X7=reshape(X(7,:,:),16,n1+n2);
    X8=reshape(X(8,:,:),16,n1+n2);
    
    tX=reshape(test_P,8,16,n2);
    tX1=reshape(tX(1,:,:),16,n2);
    tX2=reshape(tX(2,:,:),16,n2);
    tX3=reshape(tX(3,:,:),16,n2);
    tX4=reshape(tX(4,:,:),16,n2);
    tX5=reshape(tX(5,:,:),16,n2);
    tX6=reshape(tX(6,:,:),16,n2);
    tX7=reshape(tX(7,:,:),16,n2);
    tX8=reshape(tX(8,:,:),16,n2);
    SetNum=8;
    %高斯核矩阵变换
   
        for i=1:SetNum
            eval(['tX',num2str(i) ,'=corematrixtrans(X', num2str(i), ',tX' , num2str(i),',corep);']);
        end
        for i=1:SetNum
            eval(['X',num2str(i) ,'=corematrixtrans(X', num2str(i), ',X' , num2str(i),',corep);']);
        end
        
        XCELL=cell(SetNum,1);
        tXCELL=cell(SetNum,1);
        nnl=n2-LabeledSampNum;
        for i=1:SetNum
            
            eval(['XCELL{i}=X' num2str(i)]);
            eval(['tXCELL{i}=tX' num2str(i)]);
        end
        %****************计算近邻矩阵*****************
        [m3 n3]=size(XCELL{1});
        A=cell(SetNum,1);
        D=cell(SetNum,1);
        L=cell(SetNum,1);
        dist=[];
        aj_num=5;
        %计算近邻矩阵
        for i=1:SetNum
            featuredata=XCELL{i};
            Atemp=zeros(n3,n3);
            for j=1:n3
                for k=1:n3
                    temp1=featuredata(:,j);
                    temp2=featuredata(:,k);
                    dist=[dist norm(temp1-temp2)];
                    % dist=[dist (AW*(temp1-temp2).^2)];
                end
                [a1,b1]=sort(dist);
                Atemp(j,b1(1:aj_num))=1;
                dist=[];
            end
            A{i}=Atemp;
        end
        
        for i=1:SetNum
            Dtemp=zeros(n3,n3);
            for j=1:n3
                Dtemp(j,j)=sum(A{i}(j,:));
            end
            D{i}=Dtemp;
        end
        
        %计算拉普拉斯矩阵
        for i=1:SetNum
            L{i}=D{i}-A{i};
        end
        %*************************************************************************
        
      for ii=-4:1 
        g=10^(ii);  
        [GLCCgas_recog,res,deltaP]=GLCCfuc1Modify(SetNum,XCELL,train_T',nnl,tXCELL,test_T',g,L);
        allres=[allres ;g corep GLCCgas_recog];  
      end        
end   
%setting3_num_X（num代表后面label个数，X代表第几组作为测试的结果，注意这一组有20个样本送进去了训练集）
%save  setting3_10_2  allres
eval(['save seting3_',num2str(LabeledSampNum),'_',num2str(AlldataNum),' allres']);
end
end
%[GLCCone_recog GLCCtwo_recog GLCCthree_recog GLCCfour_recog GLCCfive_recog six_recog]=GLCCfuc(X1,X2,X3,X4,X5,X6,X7,X8,train_T',0,tX1,tX2,tX3,tX4,tX5,tX6,tX7,tX8,test_T');
%[GLCCCOREMATIXco_recog GLCCCOREMATIXnox_recog GLCCCOREMATIXhcho_recog]=GLCCCOREMATIXfuc(X1,X2,X3,X4,X5,Y,nnl,tX1,tX2,tX3,tX4,tX5,tY);
%[GLCCSIGMODco_recog GLCCSIGMODnox_recog GLCCSIGMODhcho_recog]=GLCCSIGMODfuc(X1,X2,X3,X4,X5,Y,nnl,tX1,tX2,tX3,tX4,tX5,tY);
%[NNone_recog NNtwo_recog NNthree_recog NNfour_recog NNfive_recog NNsix_recog]=NNfuc(train_P,train_T,test_P,test_T);
%[SVMone_recog SVMtwo_recog SVMthree_recog SVMfour_recog SVMfive_recog SVMsix_recog]=SVMfuc(train_P,T1',test_P,T2');
%[ELMone_recog ELMtwo_recog ELMthree_recog ELMfour_recog ELMfive_recog ELMsix_recog]=ELMfuc(train_P,train_T,test_P,test_T);
%  recog(cycle,:)=[GLCCco_recog GLCCnox_recog GLCChcho_recog GLCCCOREMATIXco_recog GLCCCOREMATIXnox_recog GLCCCOREMATIXhcho_recog GLCCSIGMODco_recog GLCCSIGMODnox_recog GLCCSIGMODhcho_recog NNco_recog NNnox_recog NNhcho_recog SVMco_recog SVMnox_recog SVMhcho_recog ELMco_recog ELMnox_recog ELMhcho_recog];
%  recog(cycle,:)=[GLCCco_recog GLCCnox_recog GLCChcho_recog zeros(1,15)];
%  recog(cycle,:)=[NNco_recog NNnox_recog NNhcho_recog zeros(1,12)];
%  recog(cycle,:)=[GLCCSIGMODco_recog GLCCSIGMODnox_recog GLCCSIGMODhcho_recog zeros(1,12)];
%  recog(cycle,:)=[SVMco_recog SVMnox_recog SVMhcho_recog zeros(1,12)];
%  recog(cycle,:)=[ELMco_recog ELMnox_recog ELMhcho_recog zeros(1,12)];
%  recog(cycle,:)=[GLCCCOREMATIXco_recog GLCCCOREMATIXnox_recog GLCCCOREMATIXhcho_recog zeros(1,15)];

%  allres=[allres ;mean(recog)];
%  allres=[allres ;recog];


