clear
t_95margin_df4 = 2.78;
numElement = 80;

%% Plotting the AUC comparisons

% run 21~25: 5 positive training examples
count = 1; 
auc5_activebasis = zeros(1,5);
auc5_eigenface = zeros(1,5);
auc5_activebasisAdapt =zeros(1,5);
for iRun = 21:25
    load(sprintf('sigmoid/out_run%d.mat',iRun),'testAUC');
    auc5_activebasis(count) = testAUC(numElement);
    load(sprintf('sigmoidAdaptive/out_run%d.mat',iRun),'testAUC');
    auc5_activebasisAdapt(count) = testAUC(numElement);
    count = count + 1;
end

% run 16~20: 80 positive training examples
count = 1; 
auc80_activebasis = zeros(1,5);
auc80_activebasisAdapt =zeros(1,5);
for iRun = 16:20
    load(sprintf('sigmoid/out_run%d.mat',iRun),'testAUC');
    auc80_activebasis(count) = testAUC(numElement);
    load(sprintf('sigmoidAdaptive/out_run%d.mat',iRun),'testAUC');
    auc80_activebasisAdapt(count) = testAUC(numElement);
    count = count + 1;
end

% run 11~15: 40 positive training examples
count = 1; 
auc40_activebasis = zeros(1,5);
auc40_activebasisAdapt =zeros(1,5);
for iRun = 11:15
    load(sprintf('sigmoid/out_run%d.mat',iRun),'testAUC');
    auc40_activebasis(count) = testAUC(numElement);
    load(sprintf('sigmoidAdaptive/out_run%d.mat',iRun),'testAUC');
    auc40_activebasisAdapt(count) = testAUC(numElement);
    count = count + 1;
end

% run 6~10: 20 positive training examples
count = 1; 
auc20_activebasis = zeros(1,5);
auc20_activebasisAdapt =zeros(1,5);
for iRun = 6:10
    load(sprintf('sigmoid/out_run%d.mat',iRun),'testAUC');
    auc20_activebasis(count) = testAUC(end);
    load(sprintf('sigmoidAdaptive/out_run%d.mat',iRun),'testAUC');
    auc20_activebasisAdapt(count) = testAUC(end);
    count = count + 1;
end

% run 1~5: 10 positive training examples
count = 1; 
auc10_activebasis = zeros(1,5);
auc10_activebasisAdapt =zeros(1,5);
for iRun = 1:5
    load(sprintf('sigmoid/out_run%d.mat',iRun),'testAUC');
    auc10_activebasis(count) = testAUC(numElement);
    load(sprintf('sigmoidAdaptive/out_run%d.mat',iRun),'testAUC');
    auc10_activebasisAdapt(count) = testAUC(numElement);
    count = count + 1;
end

curve1 = [mean(auc5_activebasis), mean(auc10_activebasis), mean(auc20_activebasis), mean(auc40_activebasis), mean(auc80_activebasis)];
err1 = [...
    t_95margin_df4 * std(auc5_activebasis) / sqrt(5), t_95margin_df4 * std(auc10_activebasis) / sqrt(5),...
    t_95margin_df4 * std(auc20_activebasis) / sqrt(5), t_95margin_df4 * std(auc40_activebasis) / sqrt(5),...
    t_95margin_df4 * std(auc80_activebasis) / sqrt(5) ];
curve5 = [mean(auc5_activebasisAdapt), mean(auc10_activebasisAdapt), mean(auc20_activebasisAdapt), mean(auc40_activebasisAdapt), mean(auc80_activebasisAdapt)];
err5 = [ ...
    t_95margin_df4 * std(auc5_activebasisAdapt) / sqrt(5), t_95margin_df4 * std(auc10_activebasisAdapt) / sqrt(5), ...
    t_95margin_df4 * std(auc20_activebasisAdapt) / sqrt(5), t_95margin_df4 * std(auc40_activebasisAdapt) / sqrt(5), ...
    t_95margin_df4 * std(auc80_activebasisAdapt) / sqrt(5)];

% Plot the three curves of Test AUC
%   with 95% confidence bounds
figure;
hold on;
trainSizes = [5,10,20,40,80];

h5 = errorbar(log(trainSizes),curve5,err5,'b-.','LineWidth',3); hold on
h1 = errorbar(log(trainSizes),curve1,err1,'r-','LineWidth',2);

set(gca,'FontSize',12);
set(gca,'xlim',[log(4) log(80)+0.1]);
set(gca,'ylim',[0.95 1]);
set(get(gca,'XLabel'),'String','log of # training positives','FontSize',18);
set(get(gca,'YLabel'),'String','testing AUC','FontSize',18);
legend([h5 h1],{'Active Basis Adaptive','Active Basis'},'Location','SouthEast','FontSize',20);
title('AUC vs. the number of positive training examples','FontSize',18);
set(gcf, 'PaperPositionMode', 'auto');
print -depsc auc_trainSize_activebasis.eps
print -dpng auc_trainSize_activebasis.png


% plot only the mean AUC (without the error bounds)
figure;
hold on;
plot(trainSizes,curve5,'k-s','LineWidth',3);
plot(trainSizes,curve1,'k-.','LineWidth',3);
set(gcf, 'PaperPositionMode', 'auto');
set(gca,'FontSize',12);
set(gca,'ylim',[0.95 1]);
set(get(gca,'XLabel'),'String','# training positives','FontSize',18);
set(get(gca,'YLabel'),'String','testing AUC','FontSize',18);
legend({'Active Basis Adaptive','Active Basis'},'Location','SouthEast','FontSize',20);
title('AUC vs. the number of positive training examples','FontSize',18);
print -depsc auc_trainSize_activebasis_mean.eps
print -dpng auc_trainSize_activebasis_mean.png
