function plotMREs(predictions, predictionsWithPruning,actuals, errorMeasure,algorithms,preprocessors,datasetName)
% MRE = abs(actual - predicted)/actual and MMRE is the mean of all MREs

% define a variable to keep the MMRE results for each algorithm
MREResults = -1 * ones(size(algorithms,1),size(actuals,1));
MREResultsWithPruning = -1 * ones(size(algorithms,1),size(actuals,1));

% below two variables are used for plotting purposes later in the algorithm
minSumMRE = inf;    % first define miminum sum of MRE as plus infinity
minSumMREIndex = 0; % index is the row number

% process each algorithm's results to find the MRE values
for i = 1:size(algorithms,1)
   MREResults(i,:) = abs(actuals' - predictions(i,:))./actuals';
   if sum(MREResults(i,:)) < minSumMRE
       minSumMRE = sum(MREResults(i,:));
       minSumMREIndex = i;
   end   
end

% process each algorithm's results to find the GAC pruned MRE values
for i = 1:size(algorithms,1)
   MREResultsWithPruning(i,:) = abs(actuals' - predictionsWithPruning(i,:))./actuals';  
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% this part is for plotting purposes only

MREResultsToPlot = MREResults;  % copy the MRE results to protect from changes
% get the indices of the sorted MRE's for the method that had the lowest
% sum MRE
[C sortedIndex] = sort(MREResultsToPlot(minSumMREIndex,:));
% then apply this indexing to all the methods
toSave = figure('units','normalized','outerposition',[0 0 1 1]);;
hold all;
% axis([0 size(predictions,2) 0 10]);
set(gca,'FontSize', 6,'FontName','Times New Roman');
title(char(datasetName));
for i = 1:size(algorithms,1)
   MREResultsToPlot(i,:) = MREResultsToPlot(i,sortedIndex);  
   MREResultsWithPruning(i,:) = MREResultsWithPruning(i,sortedIndex); 
   hold all;
   subplot(3,3,i);
   eval(['h1' num2str(i) ' = semilogy(MREResultsToPlot(i,:));']);
   eval(['set(h1' num2str(i) ',  ''LineStyle'', ''-'', ''LineWidth'', 1.0, ''Color'', ''Black'');']);
   eval(['set(h1' num2str(i) ', ''Marker'', ''o'', ''MarkerFaceColor'', [0 0 0], ''MarkerEdgeColor'', [0 0 0], ''MarkerSize'', 10);']);
   eval(['h2' num2str(i) ' = semilogy(MREResultsWithPruning(i,:));']);
   eval(['set(h2' num2str(i) ',  ''LineStyle'', ''-.'', ''LineWidth'', 1.0, ''Color'', ''Black'');']);
   eval(['set(h2' num2str(i) ', ''Marker'', ''+'', ''MarkerFaceColor'', [0 0 0], ''MarkerEdgeColor'', [0 0 0], ''MarkerSize'', 15);']);
   legendStr = [ char(preprocessors(i)) '-' char(algorithms(i))];
   legend(legendStr);
   hold off;
end
hold off;
saveas(toSave, [char(datasetName) '.png']);
close(toSave);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


end