
% Plot confidence intervals for ADIS, for the three options settings
varargin={};

OPT = struct(...
   'resultsDirADIS1000',      'd:\Repos\OpenEarthTools\test\matlab\applications\probabilistic\grooteman_test_problems\resultsADIS1000_startup_aproxpoints', ...
    'tests',        1:14, ...
    'name',         '', ...
    'Labels',       '', ...
    'Methods',      {{'ADIS'}}, ...
    'StartUp',      {{''}});

OPT = setproperty(OPT, varargin{:});


N=100; % number of seeds

%% Read results & plot analysis
% plot the performance of different methods for the same problem

for iTest = 1:length(OPT.tests)
 
    testNr  = num2str(OPT.tests(iTest));
  
    
        fileName1   = [OPT.Methods{1},'_resultsADIS1000_AxialP_Aprox50none' testNr '.mat'];
        fileName2   = [OPT.Methods{1},'_resultsADIS1000_AxialP_Aprox50selection' testNr '.mat'];
        fileName3   = [OPT.Methods{1},'_resultsADIS1000_AxialP_Aprox50weighted' testNr '.mat'];
        
          r1=load([OPT.resultsDirADIS1000 '\' fileName1]);
          r1=r1.fresults; 
          
          r2=load([OPT.resultsDirADIS1000 '\' fileName2]);
          r2=r2.fresults;
          
          r3=load([OPT.resultsDirADIS1000 '\' fileName3]);
          r3=r3.fresults;
          
            
            for iSeed=1:length(r1)% for all the seeds
                
                result1.Pf(iTest,iSeed)        = r1(iTest,iSeed).P_f;
                result1.Beta(iTest,iSeed)      = r1(iTest,iSeed).Beta;
                result1.Calc(iTest,iSeed)      = r1(iTest,iSeed).Calc;
                
                result2.Pf(iTest,iSeed)        = r2(iTest,iSeed).P_f;
                result2.Beta(iTest,iSeed)      = r2(iTest,iSeed).Beta;
                result2.Calc(iTest,iSeed)      = r2(iTest,iSeed).Calc;
                
                result3.Pf(iTest,iSeed)        = r3(iTest,iSeed).P_f;
                result3.Beta(iTest,iSeed)      = r3(iTest,iSeed).Beta;
                result3.Calc(iTest,iSeed)      = r3(iTest,iSeed).Calc;
            end

 
          median1_calc(iTest) = median(result1.Calc(iTest,:)',1);       
          median1_beta(iTest) = median(result1.Beta(iTest,:)',1);
          median1_Pf(iTest)   = median(result1.Pf(iTest,:)',1);
          
          median2_calc(iTest) = median(result2.Calc(iTest,:)',1);
          median2_beta(iTest) = median(result2.Beta(iTest,:)',1);
          median2_Pf(iTest)   = median(result2.Pf(iTest,:)',1);
         
          median3_calc(iTest) = median(result3.Calc(iTest,:)',1);
          median3_beta(iTest) = median(result3.Beta(iTest,:)',1);
          median3_Pf(iTest)   = median(result3.Pf(iTest,:)',1);
          

          tmp = result1.Beta(iTest,:);
          tmp = tmp(~isnan(tmp) & ~isinf(tmp));
          std1_Beta(iTest) = std(tmp);
          
          tmp2 = result2.Beta(iTest,:);
          tmp2 = tmp2(~isnan(tmp2) & ~isinf(tmp2));
          std2_Beta(iTest) = std(tmp2);
          
          tmp3 = result3.Beta(iTest,:);
          tmp3 = tmp3(~isnan(tmp3) & ~isinf(tmp3));
          std3_Beta(iTest) = std(tmp3);
          
end



p=1;
k=1;
calc_tmp  =result1.Calc';
calc_tmp2 =result2.Calc';
calc_tmp3 =result3.Calc';

mixed_matrix =[];
for k=1:size(calc_tmp,2)
 
mixed_matrix(:,p)= calc_tmp(:,k);
p=p+1;
mixed_matrix(:,p)= calc_tmp2(:,k);
p=p+1;
mixed_matrix(:,p)= calc_tmp3(:,k);
p=p+1;
end

 xtck = 1:size(mixed_matrix,2);
 xtckname ={'1','1','1','2','2','2','3','3','3','4','4','4','5','5'...
            '5','6','6','6','7','7','7','8','8','8','9','9','9',...
            '10','10','10','11','11','11','12','12','12','13','13','13','14','14','14'};
figure(1)
 p=1;
for k=1:(size(mixed_matrix,2)/3)
    
bplot(mixed_matrix(:,p),p,p,'nodots', 'nomean', 'color','blue')
hold on;
p=p+1;
bplot(mixed_matrix(:,p),p,p,'nodots', 'nomean', 'color','red')
p=p+1;
hold on;
bplot(mixed_matrix(:,p),p,p,'nodots', 'nomean', 'color','green')
p=p+1;

end
%ylim([1 300])

set(gca,'Xtick',xtck,'XtickLabel',xtckname )
xlabel('Test function')
ylabel('Number of evaluations')
title('Nr. Evaluations for  ADIS option 1(blue), ADIS option 2(red), ADIS option 3(green) ')
print -dpng Comparison_number_of_evaluations_ADIS_options1to3



p=1;
k=1;
beta_tmp  =result1.Beta';
beta_tmp2 =result2.Beta';
beta_tmp3 =result3.Beta'

mixed_matrix =[];
for k=1:size(beta_tmp,2)
 
mixed_matrix(:,p)= beta_tmp(:,k);
p=p+1;
mixed_matrix(:,p)= beta_tmp2(:,k);
p=p+1;
mixed_matrix(:,p)= beta_tmp3(:,k);
p=p+1;
end

figure(2)
 p=1;
for k=1:(size(mixed_matrix,2)/3)
    % we do this to get rid of the Nan and Inf
temp=  mixed_matrix(:,p);
temp = temp(~isnan(temp) & ~isinf(temp));

bplot(temp,p,p,'nodots', 'nomean', 'color','blue')
hold on;
p=p+1;
temp=  mixed_matrix(:,p);
temp = temp(~isnan(temp) & ~isinf(temp));

bplot(temp,p,p,'nodots', 'nomean', 'color','red')
p=p+1;
temp=  mixed_matrix(:,p);
temp = temp(~isnan(temp) & ~isinf(temp));

hold on;
bplot(temp,p,p,'nodots', 'nomean', 'color','green')
p=p+1;

end
%ylim([1 900])
%legend('ADIS','ADIS+Selection','ADIS+Weighted')
set(gca,'Xtick',xtck,'XtickLabel',xtckname )
xlabel('Test function')
ylabel('Beta Values')
title('Beta values ADIS option 1(blue), ADIS option 2(red), ADIS option 3(green) ')
print -dpng Comparison_Beta_ADIS_options1to3

















