
% Plot confidence intervals for DS, for the three options settings


varargin={};

OPT = struct(...
   'resultsDir_DS10000_allpoints',      'd:\Repos\OpenEarthTools\test\matlab\applications\probabilistic\grooteman_test_problems\resultsDS10000_allpoints', ...
   'resultsDir_DS1000_allpoints',      'd:\Repos\OpenEarthTools\test\matlab\applications\probabilistic\grooteman_test_problems\resultsDS1000_allpoints', ...
   'resultsDir_DS1000_withCOV',      'd:\Repos\OpenEarthTools\test\matlab\applications\probabilistic\grooteman_test_problems\resultsDS1000_withCOV',...
   'tests',        1:14);

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


N=100; % number of seeds


for iTest = 1:length(OPT.tests)
 
        testNr  = num2str(OPT.tests(iTest));
  
        fileName1   = ['DS_all_results10000_none' testNr '.mat'];
        r1=load([OPT.resultsDir_DS10000_allpoints '\' fileName1]);
        r1=r1.fresults; 

        fileName2   = ['DS_all_results1000_none' testNr '.mat'];
        r2=load([OPT.resultsDir_DS1000_allpoints '\' fileName2]);
        r2=r2.fresults;
          
        fileName3   = ['DS_results_1000_withCOV' testNr '.mat'];
        r3=load([OPT.resultsDir_DS1000_withCOV '\' 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  DS 10000 noCOV(blue), DS 1000 noCOV(red), DS 1000 withCOV(green) ')
print -dpng Comparison_number_of_evaluations_DS_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 DS 10000 noCOV(blue), DS 1000 noCOV(red), DS 1000 withCOV(green) ')
print -dpng Comparison_Beta_DS_options1to3

















