% define datasets of experiment
myDatasets = {
    'cocomo81o','cocomo81s','cocomo81','cocomo81e',...
    'desharnaisL1','desharnais','desharnaisL2',...
    'desharnaisL3',...
    'nasa93','nasa93_center_1','nasa93_center_2','nasa93_center_5',...
    'sdr'...
    'albrecht',...
    'finnish','kemerer','maxwell','miyazaki94','telecom1',...
    %'china'
    };

datasetSize = size(myDatasets,2);
for datasetCounter = 1:datasetSize
    
    eval(['load(''workspaces\3way\',char(myDatasets(datasetCounter)),'.mat'');']);
    actuals3Way = actual10by3values;
    algorithmResults3Way = algorithmResults;
    biasValues3Way = -1*ones(size(algorithmResults,1),1);
    varianceValues3Way = -1*ones(size(algorithmResults,1),1);
    
    eval(['load(''workspaces\LOO\',char(myDatasets(datasetCounter)),'.mat'');']);
    actualsLOO = actualsToSave';
    algorithmResultsLOO = algorithmResults;
    biasValuesLOO = -1*ones(size(algorithmResults3Way,1),1);
    varianceValuesLOO = -1*ones(size(algorithmResults3Way,1),1);
    
    % calculate bias and variance
    labels = {};
    for i = 1:size(varianceValues3Way,1)
        labels =[labels i];
        fHatMean3Way = mean(algorithmResults3Way(i,:));
        biasValues3Way(i) = mean((fHatMean3Way - actuals3Way).^2);
        varValues3Way(i) = mean((fHatMean3Way - algorithmResults3Way(i,:)).^2);
        
        fHatMeanLOO = mean(algorithmResultsLOO(i,:));
        biasValuesLOO(i) = mean((fHatMeanLOO - actualsLOO).^2);
        varValuesLOO(i) = mean((fHatMeanLOO - algorithmResultsLOO(i,:)).^2);
    end
    
    % now start plotting
    h = figure;hold on;
    plot(log(biasValues3Way), log(varValues3Way),'.');
    text(log(biasValues3Way),log(varValues3Way), labels,'EdgeColor','green','LineStyle',':');
    plot(log(biasValuesLOO), log(varValuesLOO),'.');
    text(log(biasValuesLOO),log(varValuesLOO), labels,'EdgeColor','red','LineStyle','-.');
    
    
    %     h = figure;hold on;
    %     myMin = min([biasValues3Way;biasValuesLOO]);
    %     myMax = max([biasValues3Way;biasValuesLOO]);
    %     biasValues3Way = (biasValues3Way - myMin)/(myMax -  myMin);
    %     biasValuesLOO = (biasValuesLOO - myMin)/(myMax -  myMin);
    %     %%%%%%%%
    %     myMin = min([varValues3Way,varValuesLOO]);
    %     myMax = max([varValues3Way,varValuesLOO]);
    %     varValues3Way = (varValues3Way - myMin)/(myMax -  myMin);
    %     varValuesLOO = (varValuesLOO - myMin)/(myMax -  myMin);
    %     plot((biasValues3Way), (varValues3Way),'.');
    %     text((biasValues3Way),(varValues3Way), labels,'EdgeColor','green','LineStyle',':');
    %     plot((biasValuesLOO), (varValuesLOO),'.');
    %     text((biasValuesLOO),(varValuesLOO), labels,'EdgeColor','red','LineStyle','-.');
    xlabel('Logged Bias Values');
    ylabel('Logged Variance Values');
    title([char(myDatasets(datasetCounter)) ' Bias-Variance Plots for 102 Methods.' ...
        ' Dotted squares are for 3Way and dashed squares are for LOO.']);
    eval(['print(h,''-dps'', ''biasVarPlots\',char(myDatasets(datasetCounter)),'.ps'');']);
    eval(['print(h,''-dpng'', ''biasVarPlots\',char(myDatasets(datasetCounter)),'.png'');']);
    hold off;close all;
    
end