function plot_sffs_reg_progress(var)

% plot_sffs_reg_progress(var)
%
% This function plots the variable changes during the sequential floating 
% forward selection algorithm. It prints the evolution: root mean squared
% and also selected score function (default: 'mae' - mean absolute error)
% It is designed to also plot the number of selected variables changes 
% during the running time of the SFFS algorithm.
%
% var       - input structure that holds the change of output variables
%             in SFFS during the function runtime (rmse, score)
%
%
%
% --
% ing. Zoltán Galáž
% xgalaz00@stud.feec.vutbr.cz       
% 
% Department of Telecommunications
% Faculty of Electrical Engineering and Communication
% Brno University of Technology

%% Paths and variables
mae = var.mae;
%mse = var.mse;
rmse = var.rmse;
eer = var.eer;
scr  = var.score;


rmse_std = var.rmse_std;
scr_std  = var.score_std;
mae_std = var.mae_std;
%mse_std = var.mse_std;
eer_std = var.eer_std;


num_f = var.num_features;
num_f = +num_f + 1;

%% Determine the feature set changes
feat_changes = find((abs([num_f 0] - [0 num_f])) == 1);
feat_changes = feat_changes(2:end);

%% Find maximums and minimums
max_score = min(min(scr));
max_index = find(scr == max_score);
max_index = max_index(1);

%% Set the markers
ymark_rmse  = rmse(max_index);
ymark_score = scr(max_index);
ymark_mae = mae(max_index);
%ymark_mse = mse(max_index);
ymark_eer = eer(max_index);

MIN = [min(min(rmse)); min(min(scr)); min(min(mae)); min(min(eer))];
MIN = min(MIN);   

MAX = [max(max(rmse)); max(max(scr)); min(min(mae)); min(min(eer))];
MAX = max(MAX);

%% Plot SFFS progress during running time
errorbar(rmse, rmse_std, 'b', 'linewidth', 1.4); hold on; grid on;
errorbar(mae, mae_std, 'r', 'linewidth', 1.4); hold on; grid on; 
%errorbar(eer, eer_std, 'g', 'linewidth', 1.4); hold on; grid on; 
plot(scr,  'r', 'linewidth', 1.5);
%plot(mae,  'y', 'linewidth', 1.5); 
%plot(mse,  'y', 'linewidth', 1.5); 
%plot(eer,  'g', 'linewidth', 1.5); 
plot(max_index, ymark_rmse,  'b*', 'MarkerSize', 10);
plot(max_index, ymark_score, 'r*', 'MarkerSize', 10);
plot(max_index, ymark_mae,  'r*', 'MarkerSize', 10);
%plot(max_index, ymark_mse, 'y*', 'MarkerSize', 10);
%plot(max_index, ymark_eer,  'g*', 'MarkerSize', 10);



str = ['' num2str(num_f(1))];
text(1, MIN, str, 'fontweight', 'bold');

if (length(feat_changes) > 2)
    for i = 1:length(feat_changes)
        str = [' ' num2str(num_f(feat_changes(i)))];
        text(feat_changes(i), MIN, str, 'fontweight', 'bold');
        plot([feat_changes(i), feat_changes(i)], ...
            [(MIN - 3.5) (MAX + 3.5)], 'k-', 'linewidth', 1); 
    end
end

hold off;
axis([0 length(scr) (MIN - 3.5) (MAX + 3.5)]);
ylim ([4 12])
xlabel('\rightarrow {\it počet změn v nejlepším souboru parametrů} [-]');
ylabel('\rightarrow {\it rmse, mae}');
legend('rmse', 'scr (= mae)', 'Location', 'northwest');