clear;clc;
addpath(genpath('libsvm-3.18'));

% ²ÎÊý
[Groundtruth,hyperdata,panseg,hypersize] = ALDataread('Sandiego');
[ppara.a,ppara.b] = deal(hypersize(1),hypersize(2));
[ppara.select_per,ppara.delta] = deal(64,1000);
ppara.AL_method = 'MBT';
for repjj = 1:10
    [sampleindex.trainindex,sampleindex.validindex,sampleindex.testindex] = SampleSelect(Groundtruth,10);
    eval(['save sampleindex',num2str(repjj),'.mat sampleindex']);
end
h = waitbar(0,'Classification...');
for repjj = 1:10    %ÖØ¸´10´Î   
    eval(['load sampleindex',num2str(repjj),'.mat']);
    ppara.StopCond = 0.01;
    [NBresult_cla,iterN(repjj)] = SVMAL_FNCan(hyperdata,Groundtruth,sampleindex,ppara);
    
    ppara.StopCond = 0;
    ppara.DiversityRule = 'SBSL';       
    [SBresult_cla,iterI(repjj)] = SVMAL_ObjCan_Diversity(hyperdata,panseg,Groundtruth,sampleindex,ppara);
    
    ppara.DiversityRule = 'SPA';       
    [SBresult_claS,iterS(repjj)] = SVMAL_ObjCan_Diversity(hyperdata,panseg,Groundtruth,sampleindex,ppara);
    
    ppara.DiversityRule = 'K-SAM';    
    [SBresult_claD,iterD(repjj)] = SVMAL_ObjCan_Diversity(hyperdata,panseg,Groundtruth,sampleindex,ppara);

    ppara.DiversityRule = 'K-CLUSTER';   
    [SBresult_claC,iterC(repjj)] = SVMAL_ObjCan_Diversity(hyperdata,panseg,Groundtruth,sampleindex,ppara);
    
    for kk = 1:20
        NBOA(repjj,kk) = NBresult_cla{kk}.OA;
        SBOA(repjj,kk) = SBresult_cla{kk}.OA;  
        SBOA_S(repjj,kk) = SBresult_claS{kk}.OA;
        SBOA_D(repjj,kk) = SBresult_claD{kk}.OA;
        SBOA_C(repjj,kk) = SBresult_claC{kk}.OA;
    end    
    
    for kk = 1:20
        NBKappa(repjj,kk) = NBresult_cla{kk}.Kappa;
        SBKappa(repjj,kk) = SBresult_cla{kk}.Kappa;  
        SBKappa_S(repjj,kk) = SBresult_claS{kk}.Kappa;
        SBKappa_D(repjj,kk) = SBresult_claD{kk}.Kappa;
        SBKappa_C(repjj,kk) = SBresult_claC{kk}.Kappa;
    end 
    
    waitbar(repjj/10,h,'Classification');
end
close(h);

OAError(1,:) = std(NBOA,0,1);
OAError(2,:) = std(SBOA,0,1);
OAError(3,:) = std(SBOA_S,0,1);
OAError(4,:) = std(SBOA_D,0,1);
OAError(5,:) = std(SBOA_C,0,1);
OAError = OAError*100;

OA(1,:) = mean(NBOA,1);
OA(2,:) = mean(SBOA,1);
OA(3,:) = mean(SBOA_S,1);
OA(4,:) = mean(SBOA_D,1);
OA(5,:) = mean(SBOA_C,1);
OA = OA*100;

KappaError(1,:) = std(NBKappa,0,1);
KappaError(2,:) = std(SBKappa,0,1);
KappaError(3,:) = std(SBKappa_S,0,1);
KappaError(4,:) = std(SBKappa_D,0,1);
KappaError(5,:) = std(SBKappa_C,0,1);

Kappa(1,:) = mean(NBKappa,1);
Kappa(2,:) = mean(SBKappa,1);
Kappa(3,:) = mean(SBKappa_S,1);
Kappa(4,:) = mean(SBKappa_D,1);
Kappa(5,:) = mean(SBKappa_C,1);


figure;set(gca,'LooseInset',get(gca,'TightInset'));
set(gcf, 'position', [640 400 350 270]);
plot(1:20,OA(1,:),'b-o','LineWidth',3,'MarkerSize',5);
hold on;    plot(1:20,OA(2,:),'r-o','LineWidth',3,'MarkerSize',5);
hold on;    plot(1:20,OA(3,:),'g-*','LineWidth',3,'MarkerSize',8);
hold on;    plot(1:20,OA(4,:),'k-s','LineWidth',3,'MarkerSize',5);
hold on;    plot(1:20,OA(5,:),'m-^','LineWidth',3,'MarkerSize',5);
set(gca,'FontName','Times New Roman','FontSize',10,'FontWeight','bold');

set(gca,'XTick',5:5:20);
set(gca,'XTickLabel',{'5','10','15','20'});
xlabel('Iterations','FontSize',12,'FontName','Times New Roman','FontWeight','bold');
ylabel('Overall Accuracy (%)','FontSize',12,'FontName','Times New Roman','FontWeight','bold');
legend1 = legend('NBSL','SBSL','SBSL-SPA','SBSL-KCA','SBSL-KKM','Location','SouthEast'); 
set(legend1,'FontName','Times New Roman','FontSize',10,'FontWeight','bold');


