function resultsAnalysis_exp2
% Analysis of the results of experiment 2. The experiment was done by 9
% participants. The participants were asked to imitate a simulated hand
% model. Two different machine learning methods were tested in batch,
% namely Ridge regression (RR) and Gaussian process (GPR) with RBF kernels.
% The inputs of regression methods were sEMG, TMG or both. Results were
% computed using MLmethods_{sEMG,TMG,multimodal}_exp2.m files.
% Models were trained on complete and zero activations of six movements and
% tested on the whole range of activation values in between.
% The movements were thumb rotation, index and little finger flexion, wrist
% flexion, extension and supination.
% This file computee RMSE error for predictions made by RR and GPR with
% different RBF kernels using sEMG, TMG or both as input.
% Results are registered in results/Exp2_results.txt and graphs are
% registered in graphs/ if saveOpt is activated.
%
%
%
% Writing code takes time. Polishing it and making it available to others takes longer! 
% If some parts of the code were useful for your research of for a better understanding 
% of the algorithms, please cite the related publications.
%
% @article{Jaquier17MDPI,
%   author="Jaquier, N. and Connan, M. and Castellini, C. and Calinon, S.",
%   title="Combining electro- and tactile myography to improve hand and 
%		wrist activity detection in prostheses",
%   year="2017",
%	journal = "Technologies",
%	volume = "",
%	number = "",
%	article number = "",
% }
% 
% Copyright (c) 2017 Idiap Research Institute, http://idiap.ch/
% Written by Noémie Jaquier
% 
% This code is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License version 3 as
% published by the Free Software Foundation.
% 
% This code is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
% 
% You should have received a copy of the GNU General Public License
% along with this code. If not, see <http://www.gnu.org/licenses/>.

%% Parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nbSub = 9;

% saveOpt = true to save figures, false otherwise.
saveOpt = true;

oneColorGraph = [0.3151 0.0712 0.4848];

%% Initialisation of errors for different methods
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rmse_tmg_Eucl = [];
rmse_tmg_KL = [];
rmse_tmg_logSPD = [];
rmse_tmg_SPD = [];
rmse_tmg_rr = [];

rmse_emg_Eucl = [];
rmse_emg_logSPD = [];
rmse_emg_SPD = [];
rmse_emg_rr = [];

rmse_tmgemg_KL_Eucl = [];
rmse_tmgemg_KL_logSPD = [];
rmse_tmgemg_KL_SPD = [];
rmse_tmgemg_SPD_Eucl = [];
rmse_tmgemg_SPD_logSPD = [];
rmse_tmgemg_SPD_SPD = [];
rmse_tmgemg_Eucl_Eucl = [];
rmse_tmgemg_Eucl_logSPD = [];
rmse_tmgemg_Eucl_SPD = [];
rmse_tmgemg_rr = [];

nbData = [];

yhatTot_tmg_Eucl = [];
yhatTot_tmg_KL = [];
yhatTot_tmg_logSPD = [];
yhatTot_tmg_SPD = [];
yhatTot_tmg_rr = [];

yhatTot_emg_Eucl = [];
yhatTot_emg_logSPD = [];
yhatTot_emg_SPD = [];
yhatTot_emg_rr = [];

yhatTot_tmgemg_KL_Eucl = [];
yhatTot_tmgemg_KL_logSPD = [];
yhatTot_tmgemg_KL_SPD = [];
yhatTot_tmgemg_SPD_Eucl = [];
yhatTot_tmgemg_SPD_logSPD = [];
yhatTot_tmgemg_SPD_SPD = [];
yhatTot_tmgemg_Eucl_Eucl = [];
yhatTot_tmgemg_Eucl_logSPD = [];
yhatTot_tmgemg_Eucl_SPD = [];
yhatTot_tmgemg_rr = [];

yTestTot = [];
%% Compute RMSE between stimulus and prediction for different methods
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for subjectId = 1:nbSub
	
	% Load data TMG
	strTMG = sprintf('results/TMGpredictions%d.mat',subjectId);
	strEMG = sprintf('results/EMGpredictions%d.mat',subjectId);
	strTMGEMG = sprintf('results/MULTIMODALpredictions%d.mat',subjectId);
	load(strTMG);
	
	rmse_tmg_Eucl = [rmse_tmg_Eucl; computeRMSE(yTest(:,1:9),yhat_tmg_Eucl)];
	rmse_tmg_KL = [rmse_tmg_KL; computeRMSE(yTest(:,1:9),yhat_tmg_KL)];
	rmse_tmg_logSPD = [rmse_tmg_logSPD; computeRMSE(yTest(:,1:9),yhat_tmg_logSPD)];
	rmse_tmg_SPD = [rmse_tmg_SPD; computeRMSE(yTest(:,1:9),yhat_tmg_SPD)];
	rmse_tmg_rr = [rmse_tmg_rr; computeRMSE(yTest(:,1:9),yhat_tmg_rr)];
	
	yhatTot_tmg_Eucl = [yhatTot_tmg_Eucl; yhat_tmg_Eucl];
	yhatTot_tmg_KL = [yhatTot_tmg_KL; yhat_tmg_KL];
	yhatTot_tmg_logSPD = [yhatTot_tmg_logSPD; yhat_tmg_logSPD];
	yhatTot_tmg_SPD = [yhatTot_tmg_SPD; yhat_tmg_SPD];
	yhatTot_tmg_rr = [yhatTot_tmg_rr; yhat_tmg_rr];

	
	load(strEMG);
	
	rmse_emg_Eucl = [rmse_emg_Eucl; computeRMSE(yTest(:,1:9),yhat_emg_Eucl)];
	rmse_emg_logSPD = [rmse_emg_logSPD; computeRMSE(yTest(:,1:9),yhat_emg_logSPD)];
	rmse_emg_SPD = [rmse_emg_SPD; computeRMSE(yTest(:,1:9),yhat_emg_SPD)];
	rmse_emg_rr = [rmse_emg_rr; computeRMSE(yTest(:,1:9),yhat_emg_rr)];
	
	yhatTot_emg_Eucl = [yhatTot_emg_Eucl; yhat_emg_Eucl];
	yhatTot_emg_logSPD = [yhatTot_emg_logSPD; yhat_emg_logSPD];
	yhatTot_emg_SPD = [yhatTot_emg_SPD; yhat_emg_SPD];
	yhatTot_emg_rr = [yhatTot_emg_rr; yhat_emg_rr];
	
	load(strTMGEMG);
	
	rmse_tmgemg_KL_Eucl = [rmse_tmgemg_KL_Eucl; computeRMSE(yTest(:,1:9),yhat_tmgemg_KL_Eucl)];
	rmse_tmgemg_KL_logSPD = [rmse_tmgemg_KL_logSPD; computeRMSE(yTest(:,1:9),yhat_tmgemg_KL_logSPD)];
	rmse_tmgemg_KL_SPD = [rmse_tmgemg_KL_SPD; computeRMSE(yTest(:,1:9),yhat_tmgemg_KL_SPD)];
	rmse_tmgemg_SPD_Eucl = [rmse_tmgemg_SPD_Eucl; computeRMSE(yTest(:,1:9),yhat_tmgemg_SPD_Eucl)];
	rmse_tmgemg_SPD_logSPD = [rmse_tmgemg_SPD_logSPD; computeRMSE(yTest(:,1:9),yhat_tmgemg_SPD_logSPD)];
	rmse_tmgemg_SPD_SPD = [rmse_tmgemg_SPD_SPD; computeRMSE(yTest(:,1:9),yhat_tmgemg_SPD_SPD)];
	rmse_tmgemg_Eucl_Eucl = [rmse_tmgemg_Eucl_Eucl; computeRMSE(yTest(:,1:9),yhat_tmgemg_Eucl_Eucl)];
	rmse_tmgemg_Eucl_logSPD = [rmse_tmgemg_Eucl_logSPD; computeRMSE(yTest(:,1:9),yhat_tmgemg_Eucl_logSPD)];
	rmse_tmgemg_Eucl_SPD = [rmse_tmgemg_Eucl_SPD; computeRMSE(yTest(:,1:9),yhat_tmgemg_Eucl_SPD)];
	rmse_tmgemg_rr = [rmse_tmgemg_rr; computeRMSE(yTest(:,1:9),yhat_tmgemg_rr)];
	
	yhatTot_tmgemg_KL_Eucl = [yhatTot_tmgemg_KL_Eucl; yhat_tmgemg_KL_Eucl];
	yhatTot_tmgemg_KL_logSPD = [yhatTot_tmgemg_KL_logSPD; yhat_tmgemg_KL_logSPD];
	yhatTot_tmgemg_KL_SPD = [yhatTot_tmgemg_KL_SPD; yhat_tmgemg_KL_SPD];
	yhatTot_tmgemg_SPD_Eucl = [yhatTot_tmgemg_SPD_Eucl; yhat_tmgemg_SPD_Eucl];
	yhatTot_tmgemg_SPD_logSPD = [yhatTot_tmgemg_SPD_logSPD; yhat_tmgemg_SPD_logSPD];
	yhatTot_tmgemg_SPD_SPD = [yhatTot_tmgemg_SPD_SPD; yhat_tmgemg_SPD_SPD];
	yhatTot_tmgemg_Eucl_Eucl = [yhatTot_tmgemg_Eucl_Eucl; yhat_tmgemg_Eucl_Eucl];
	yhatTot_tmgemg_Eucl_logSPD = [yhatTot_tmgemg_Eucl_logSPD; yhat_tmgemg_Eucl_logSPD];
	yhatTot_tmgemg_Eucl_SPD = [yhatTot_tmgemg_Eucl_SPD; yhat_tmgemg_Eucl_SPD];
	yhatTot_tmgemg_rr = [yhatTot_tmgemg_rr; yhat_tmgemg_rr];
	
	yTestTot = [yTestTot; yTest];
	nbData = [nbData, size(yTest,1)];
end

predTot = yTestTot(:,1:9);

%% Write results in txt file
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fileID = fopen('results/Exp2_results.txt','w');

fprintf(fileID, 'TMG: Eucl RMSE = %2.2f pm %2.2f\n', mean(rmse_tmg_Eucl), std(rmse_tmg_Eucl));
fprintf(fileID, 'TMG: logSPD RMSE = %2.2f pm %2.2f\n', mean(rmse_tmg_logSPD), std(rmse_tmg_logSPD));
fprintf(fileID, 'TMG: SPD RMSE = %2.2f pm %2.2f\n', mean(rmse_tmg_SPD), std(rmse_tmg_SPD));
fprintf(fileID, 'TMG: KL RMSE = %2.2f pm %2.2f\n', mean(rmse_tmg_KL), std(rmse_tmg_KL));
fprintf(fileID, 'TMG: RR RMSE = %2.2f pm %2.2f\n', mean(rmse_tmg_rr), std(rmse_tmg_rr));

fprintf(fileID, 'EMG: Eucl RMSE = %2.2f pm %2.2f\n', mean(rmse_emg_Eucl), std(rmse_emg_Eucl));
fprintf(fileID, 'EMG: logSPD RMSE = %2.2f pm %2.2f\n', mean(rmse_emg_logSPD), std(rmse_emg_logSPD));
fprintf(fileID, 'EMG: SPD RMSE = %2.2f pm %2.2f\n', mean(rmse_emg_SPD), std(rmse_emg_SPD));
fprintf(fileID, 'EMG: RR RMSE = %2.2f pm %2.2f\n', mean(rmse_emg_rr), std(rmse_emg_rr));

fprintf(fileID, 'TMG-EMG: Eucl-Eucl RMSE = %2.2f pm %2.2f\n', mean(rmse_tmgemg_Eucl_Eucl), std(rmse_tmgemg_Eucl_Eucl));
fprintf(fileID, 'TMG-EMG: Eucl-logSPD RMSE = %2.2f pm %2.2f\n', mean(rmse_tmgemg_Eucl_logSPD), std(rmse_tmgemg_Eucl_logSPD));
fprintf(fileID, 'TMG-EMG: Eucl-SPD RMSE = %2.2f pm %2.2f\n', mean(rmse_tmgemg_Eucl_SPD), std(rmse_tmgemg_Eucl_SPD));
fprintf(fileID, 'TMG-EMG: SPD-Eucl RMSE = %2.2f pm %2.2f\n', mean(rmse_tmgemg_SPD_Eucl), std(rmse_tmgemg_SPD_Eucl));
fprintf(fileID, 'TMG-EMG: SPD-logSPD RMSE = %2.2f pm %2.2f\n', mean(rmse_tmgemg_SPD_logSPD), std(rmse_tmgemg_SPD_logSPD));
fprintf(fileID, 'TMG-EMG: SPD-SPD RMSE = %2.2f pm %2.2f\n', mean(rmse_tmgemg_SPD_SPD), std(rmse_tmgemg_SPD_SPD));
fprintf(fileID, 'TMG-EMG: KL-Eucl RMSE = %2.2f pm %2.2f\n', mean(rmse_tmgemg_KL_Eucl), std(rmse_tmgemg_KL_Eucl));
fprintf(fileID, 'TMG-EMG: KL-logSPD RMSE = %2.2f pm %2.2f\n', mean(rmse_tmgemg_KL_logSPD), std(rmse_tmgemg_KL_logSPD));
fprintf(fileID, 'TMG-EMG: KL-SPD RMSE = %2.2f pm %2.2f\n', mean(rmse_tmgemg_KL_SPD), std(rmse_tmgemg_KL_SPD));
fprintf(fileID, 'TMG-EMG: RR RMSE = %2.2f pm %2.2f\n', mean(rmse_tmgemg_rr), std(rmse_tmgemg_rr));

fclose(fileID);

%% Plot error per method
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N = size(predTot,1);
% TMG
figure('position',[500,300,600,350]); hold on
groups = [repmat({'Eucl'},N,1);repmat({'logSPD'},N,1);repmat({'SPD'},N,1);repmat({'KL'},N,1);repmat({'RR'},N,1)];
boxplot([sqrt(sum((predTot-yhatTot_tmg_Eucl).^2,2)); sqrt(sum((predTot-yhatTot_tmg_logSPD).^2,2));...
	sqrt(sum((predTot-yhatTot_tmg_SPD).^2,2)); sqrt(sum((predTot-yhatTot_tmg_KL).^2,2));...
	sqrt(sum((predTot-yhatTot_tmg_rr).^2,2));],groups, ...
	'Colors','k','widths',0.4);
h = findobj(gca,'Tag','Box');
for j=1:length(h)
	p1 = patch(get(h(j),'XData'),get(h(j),'YData'),oneColorGraph,'FaceAlpha',.7);
end

ylim([0 2]);
set(gca,'Fontsize',14);
ylabel('Error','Fontsize',18);
if(saveOpt)
	print('-dpng','graphs/exp2_error_TMG.png');
end

% sEMG
figure('position',[500,300,500,350]); hold on
groups = [repmat({'Eucl'},N,1);repmat({'logSPD'},N,1);repmat({'SPD'},N,1);repmat({'RR'},N,1)];
boxplot([sqrt(sum((predTot-yhatTot_emg_Eucl).^2,2)); sqrt(sum((predTot-yhatTot_emg_logSPD).^2,2));...
	sqrt(sum((predTot-yhatTot_emg_SPD).^2,2)); sqrt(sum((predTot-yhatTot_emg_rr).^2,2))],groups, ...
	'Colors','k','widths',0.4);
h = findobj(gca,'Tag','Box');
for j=1:length(h)
	p1 = patch(get(h(j),'XData'),get(h(j),'YData'),oneColorGraph,'FaceAlpha',.7);
end

ylim([0 2]);
set(gca,'Fontsize',14);
ylabel('Error','Fontsize',18);
if(saveOpt)
	print('-dpng','graphs/exp2_error_EMG.png');
end

% TMG and sEMG
figure('position',[500,300,1300,350]); hold on
groups = [repmat({'Eucl/Eucl'},N,1);repmat({'Eucl/logSPD'},N,1);repmat({'Eucl/SPD'},N,1);...
	repmat({'SPD/Eucl'},N,1);repmat({'SPD/logSPD'},N,1);repmat({'SPD/SPD'},N,1);...
	repmat({'KL/Eucl'},N,1);repmat({'KL/logSPD'},N,1);repmat({'KL/SPD'},N,1); ;repmat({'RR'},N,1)];
boxplot([sqrt(sum((predTot-yhatTot_tmgemg_Eucl_Eucl).^2,2)); sqrt(sum((predTot-yhatTot_tmgemg_Eucl_logSPD).^2,2)); ...
	sqrt(sum((predTot-yhatTot_tmgemg_Eucl_SPD).^2,2));	sqrt(sum((predTot-yhatTot_tmgemg_SPD_Eucl).^2,2));...
	sqrt(sum((predTot-yhatTot_tmgemg_SPD_logSPD).^2,2)); sqrt(sum((predTot-yhatTot_tmgemg_SPD_SPD).^2,2));...
	sqrt(sum((predTot-yhatTot_tmgemg_KL_Eucl).^2,2)); sqrt(sum((predTot-yhatTot_tmgemg_KL_logSPD).^2,2));...
	sqrt(sum((predTot-yhatTot_tmgemg_KL_SPD).^2,2)); sqrt(sum((predTot-yhatTot_tmgemg_rr).^2,2))],groups, ...
	'Colors','k','widths',0.4);
h = findobj(gca,'Tag','Box');
for j=1:length(h)
	p1 = patch(get(h(j),'XData'),get(h(j),'YData'),oneColorGraph,'FaceAlpha',.7);
end

ylim([0 2]);
set(gca,'Fontsize',14);
ylabel('Error','Fontsize',18);
if(saveOpt)
	print('-dpng','graphs/exp2_error_MULTIMODAL.png');
end
%% Plot RMSE per method
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TMG
figure('position',[500,300,600,350]); hold on
groups = [repmat({'Eucl'},nbSub,1);repmat({'logSPD'},nbSub,1);repmat({'SPD'},nbSub,1);repmat({'KL'},nbSub,1);repmat({'RR'},nbSub,1)];
boxplot([rmse_tmg_Eucl; rmse_tmg_logSPD; rmse_tmg_SPD; rmse_tmg_KL; rmse_tmg_rr],groups, ...
	'Colors','k','widths',0.4);
h = findobj(gca,'Tag','Box');
for j=1:length(h)
	p1 = patch(get(h(j),'XData'),get(h(j),'YData'),oneColorGraph,'FaceAlpha',.7);
end

ylim([0 .85]);
set(gca,'Fontsize',14);
ylabel('RMSE','Fontsize',18);
if(saveOpt)
	print('-dpng','graphs/exp2_rmse_TMG.png');
end

% sEMG
figure('position',[500,300,500,350]); hold on
groups = [repmat({'Eucl'},nbSub,1);repmat({'logSPD'},nbSub,1);repmat({'SPD'},nbSub,1);repmat({'RR'},nbSub,1)];
boxplot([rmse_emg_Eucl; rmse_emg_logSPD; rmse_emg_SPD; rmse_emg_rr],groups, ...
	'Colors','k','widths',0.4);
h = findobj(gca,'Tag','Box');
for j=1:length(h)
	p1 = patch(get(h(j),'XData'),get(h(j),'YData'),oneColorGraph,'FaceAlpha',.7);
end

ylim([0 .85]);
set(gca,'Fontsize',14);
ylabel('RMSE','Fontsize',18);
if(saveOpt)
	print('-dpng','graphs/exp2_rmse_EMG.png');
end

% TMG and sEMG
figure('position',[500,300,1300,350]); hold on
groups = [repmat({'Eucl/Eucl'},nbSub,1);repmat({'Eucl/logSPD'},nbSub,1);repmat({'Eucl/SPD'},nbSub,1);...
	repmat({'SPD/Eucl'},nbSub,1);repmat({'SPD/logSPD'},nbSub,1);repmat({'SPD/SPD'},nbSub,1);...
	repmat({'KL/Eucl'},nbSub,1);repmat({'KL/logSPD'},nbSub,1);repmat({'KL/SPD'},nbSub,1);repmat({'RR'},nbSub,1)];
boxplot([rmse_tmgemg_Eucl_Eucl; rmse_tmgemg_Eucl_logSPD; rmse_tmgemg_Eucl_SPD;...
	rmse_tmgemg_SPD_Eucl; rmse_tmgemg_SPD_logSPD; rmse_tmgemg_SPD_SPD;...
	rmse_tmgemg_KL_Eucl; rmse_tmgemg_KL_logSPD; rmse_tmgemg_KL_SPD; rmse_tmgemg_rr],groups, ...
	'Colors','k','widths',0.4);
h = findobj(gca,'Tag','Box');
for j=1:length(h)
	p1 = patch(get(h(j),'XData'),get(h(j),'YData'),oneColorGraph,'FaceAlpha',.7);
end

ylim([0 .85]);
set(gca,'Fontsize',14);
ylabel('RMSE','Fontsize',18);
if(saveOpt)
	print('-dpng','graphs/exp2_rmse_MULTIMODAL.png');
end

%% Plot RMSE per method and per subject
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TMG
figure('position',[500,300,1100,450]); hold on
error_vec = [rmse_tmg_Eucl'; rmse_tmg_logSPD'; rmse_tmg_SPD'; rmse_tmg_KL'];
positions = bsxfun(@plus,[0.7 0.9 1.1 1.3]',0:nbSub-1);
groups = [{'Eucl1'};{'Eucl2'};{'Eucl3'};{'Eucl4'};{'Eucl5'};{'Eucl6'};{'Eucl7'};{'Eucl8'};{'Eucl9'};...
	{'logSPD1'};{'logSPD2'};{'logSPD3'};{'logSPD4'};{'logSPD5'};{'logSPD6'};{'logSPD7'};{'logSPD8'};{'logSPD9'};...
	{'SPD1'};{'SPD2'};{'SPD3'};{'SPD4'};{'SPD5'};{'SPD6'};{'SPD7'};{'SPD8'};{'SPD9'};...
	{'KL1'};{'KL2'};{'KL3'};{'KL4'};{'KL5'};{'KL6'};{'KL7'};{'KL8'};{'KL9'}];
boxplot(error_vec(:),groups,'Colors','k','widths',0.15,'positions',positions(:));
h = findobj(gca,'Tag','Box');

for j=1:4:length(h)
	xp = get(h(j),'XData');
	yp = get(h(j),'YData');
	yp([1,end-1,end]) = 0;
	p1 = patch(xp,yp,[0.9871 0.9914 0.7495],'FaceAlpha',.75);
end
for j=2:4:length(h)
	xp = get(h(j),'XData');
	yp = get(h(j),'YData');
	yp([1,end-1,end]) = 0;
	p2 = patch(xp,yp,[0.9440 0.3776 0.3651],'FaceAlpha',.75);
end
for j=3:4:length(h)
	xp = get(h(j),'XData');
	yp = get(h(j),'YData');
	yp([1,end-1,end]) = 0;
	p3 = patch(xp,yp,[0.4452 0.1227 0.5069],'FaceAlpha',.75);
end
for j=4:4:length(h)
	xp = get(h(j),'XData');
	yp = get(h(j),'YData');
	yp([1,end-1,end]) = 0;
	p4 = patch(xp,yp,[0.0015 0.0005 0.0139],'FaceAlpha',.75);
end

ylim([0 .8]);
set(gca,'xtick',1:nbSub, 'xticklabel',{'1','2','3','4','5','6','7','8','9'},'Fontsize',14);
xlabel('Participant','Fontsize',18);
ylabel('RMSE','Fontsize',18);
legend([p4,p3,p2,p1],'Eucl','logSPD','SPD','KL','location','north','orientation','horizontal');
if(saveOpt)
	print('-dpng','graphs/exp2_rmse_subj_TMG.png');
end

% sEMG
figure('position',[500,300,1100,450]); hold on
error_vec = [rmse_emg_Eucl'; rmse_emg_logSPD'; rmse_emg_SPD'];
positions = bsxfun(@plus,[0.8 1 1.2]',0:nbSub-1);
groups = [{'Eucl1'};{'Eucl2'};{'Eucl3'};{'Eucl4'};{'Eucl5'};{'Eucl6'};{'Eucl7'};{'Eucl8'};{'Eucl9'};...
	{'logSPD1'};{'logSPD2'};{'logSPD3'};{'logSPD4'};{'logSPD5'};{'logSPD6'};{'logSPD7'};{'logSPD8'};{'logSPD9'};...
	{'SPD1'};{'SPD2'};{'SPD3'};{'SPD4'};{'SPD5'};{'SPD6'};{'SPD7'};{'SPD8'};{'SPD9'}];
boxplot(error_vec(:),groups,'Colors','k','widths',0.15,'positions',positions(:));
h = findobj(gca,'Tag','Box');
for j=1:3:length(h)
	xp = get(h(j),'XData');
	yp = get(h(j),'YData');
	yp([1,end-1,end]) = 0;
	p1 = patch(xp,yp,[0.9871 0.9914 0.7495],'FaceAlpha',.75);
end
for j=2:3:length(h)
	xp = get(h(j),'XData');
	yp = get(h(j),'YData');
	yp([1,end-1,end]) = 0;
	p2 = patch(xp,yp,[0.7132 0.2139 0.4763],'FaceAlpha',.75);
end
for j=3:3:length(h)
	xp = get(h(j),'XData');
	yp = get(h(j),'YData');
	yp([1,end-1,end]) = 0;
	p3 = patch(xp,yp,[0.0015 0.0005 0.0139],'FaceAlpha',.75);
end

ylim([0 .8]);
set(gca,'xtick',1:nbSub, 'xticklabel',{'1','2','3','4','5','6','7','8','9'},'Fontsize',14);
xlabel('Participant','Fontsize',18);
ylabel('RMSE','Fontsize',18);
legend([p3,p2,p1],'Eucl','logSPD','SPD','location','north','orientation','horizontal');
if(saveOpt)
	print('-dpng','graphs/exp2_rmse_subj_EMG.png');
end

% TMG and sEMG
figure('position',[500,300,1400,450]); hold on
error_vec = [rmse_tmgemg_Eucl_Eucl'; rmse_tmgemg_Eucl_logSPD'; rmse_tmgemg_Eucl_SPD';...
	rmse_tmgemg_SPD_Eucl'; rmse_tmgemg_SPD_logSPD'; rmse_tmgemg_SPD_SPD';...
	rmse_tmgemg_KL_Eucl'; rmse_tmgemg_KL_logSPD'; rmse_tmgemg_KL_SPD'];
positions = bsxfun(@plus,[0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 1.4]',0:nbSub-1);
groups = [{'EE1'};{'EE2'};{'EE3'};{'EE4'};{'EE5'};{'EE6'};{'EE7'};{'EE8'};{'EE9'};...
	{'ElS1'};{'ElS2'};{'ElS3'};{'ElS4'};{'ElS5'};{'ElS6'};{'ElS7'};{'ElS8'};{'ElS9'};...
	{'ES1'};{'ES2'};{'ES3'};{'ES4'};{'ES5'};{'ES6'};{'ES7'};{'ES8'};{'ES9'};...
	{'SE1'};{'SE2'};{'SE3'};{'SE4'};{'SE5'};{'SE6'};{'SE7'};{'SE8'};{'SE9'};...
	{'SlS1'};{'SlS2'};{'SlS3'};{'SlS4'};{'SlS5'};{'SlS6'};{'SlS7'};{'SlS8'};{'SlS9'};...
	{'SS1'};{'SS2'};{'SS3'};{'SS4'};{'SS5'};{'SS6'};{'SS7'};{'SS8'};{'SS9'};...
	{'KE1'};{'KE2'};{'KE3'};{'KE4'};{'KE5'};{'KE6'};{'KE7'};{'KE8'};{'KE9'};...
	{'KlS1'};{'KlS2'};{'KlS3'};{'KlS4'};{'KlS5'};{'KlS6'};{'KlS7'};{'KlS8'};{'KlS9'};...
	{'KS1'};{'KS2'};{'KS3'};{'KS4'};{'KS5'};{'KS6'};{'KS7'};{'KS8'};{'KS9'}];
boxplot(error_vec(:),groups,'Colors','k','widths',0.1,'positions',positions(:));
h = findobj(gca,'Tag','Box');
for j=1:9:length(h)
	xp = get(h(j),'XData');
	yp = get(h(j),'YData');
	yp([1,end-1,end]) = 0;
	p1 = patch(xp,yp,[0.9871 0.9914 0.7495],'FaceAlpha',.75);
end
for j=2:9:length(h)
	xp = get(h(j),'XData');
	yp = get(h(j),'YData');
	yp([1,end-1,end]) = 0;
	p2 = patch(xp,yp,[0.9970 0.7633 0.5296],'FaceAlpha',.75);
end
for j=3:9:length(h)
	xp = get(h(j),'XData');
	yp = get(h(j),'YData');
	yp([1,end-1,end]) = 0;
	p3 = patch(xp,yp,[0.9859 0.5300 0.3801],'FaceAlpha',.75);
end
for j=4:9:length(h)
	xp = get(h(j),'XData');
	yp = get(h(j),'YData');
	yp([1,end-1,end]) = 0;
	p4 = patch(xp,yp,[0.9013 0.3165 0.3899],'FaceAlpha',.75);
end
for j=5:9:length(h)
	xp = get(h(j),'XData');
	yp = get(h(j),'YData');
	yp([1,end-1,end]) = 0;
	p5 = patch(xp,yp,[0.7132 0.2139 0.4763],'FaceAlpha',.75);
end
for j=6:9:length(h)
	xp = get(h(j),'XData');
	yp = get(h(j),'YData');
	yp([1,end-1,end]) = 0;
	p6 = patch(xp,yp,[0.5109 0.1473 0.5082],'FaceAlpha',.75);
end
for j=7:9:length(h)
	xp = get(h(j),'XData');
	yp = get(h(j),'YData');
	yp([1,end-1,end]) = 0;
	p7 = patch(xp,yp,[0.3151 0.0712 0.4848],'FaceAlpha',.75);
end
for j=8:9:length(h)
	xp = get(h(j),'XData');
	yp = get(h(j),'YData');
	yp([1,end-1,end]) = 0;
	p8 = patch(xp,yp,[0.1124 0.0654 0.2756],'FaceAlpha',.75);
end
for j=9:9:length(h)
	xp = get(h(j),'XData');
	yp = get(h(j),'YData');
	yp([1,end-1,end]) = 0;
	p9 = patch(xp,yp,[0.0015 0.0005 0.0139],'FaceAlpha',.75);
end

ylim([0 .8]);
set(gca,'xtick',1:nbSub, 'xticklabel',{'1','2','3','4','5','6','7','8','9'},'Fontsize',14);
xlabel('Participant','Fontsize',18);
ylabel('RMSE','Fontsize',18);
legend([p9,p8,p7,p6,p5,p4,p3,p2,p1],'Eucl/Eucl','Eucl/logSPD','Eucl/SPD','SPD/Eucl',...
	'SPD/logSPD','SPD/SPD','KL/Eucl','KL/logSPD','KL/SPD','location','north','orientation','horizontal');
if(saveOpt)
	print('-dpng','graphs/exp2_rmse_subj_MULTIMODAL.png');
end

%% Plot error per movement for selected method
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nbDataSub = [0, cumsum(nbData)];
for subjectId = 1:9
	yTestSub = yTestTot(nbDataSub(subjectId)+1:nbDataSub(subjectId+1),:);
	yTestSub(yTestSub(:,7)== -1,10) = -pow2(6);
	yTestSub(yTestSub(:,9)== -1,10) = -pow2(8);
	dataId = yTestSub(:,10);

	yhatSub_tmgemg_rr = yhatTot_tmgemg_rr(nbDataSub(subjectId)+1:nbDataSub(subjectId+1),:);
	rmse_RR_rest(subjectId,:) = computeRMSE(yhatSub_tmgemg_rr(dataId == 0 , :), yTestSub(dataId == 0,1:9));
	rmse_RR_thumb(subjectId,:) = computeRMSE(yhatSub_tmgemg_rr(dataId == 2^0 , :), yTestSub(dataId == 2^0,1:9));
	rmse_RR_index(subjectId,:) = computeRMSE(yhatSub_tmgemg_rr(dataId == 2^2, :), yTestSub(dataId == 2^2,1:9));
	rmse_RR_little(subjectId,:) = computeRMSE(yhatSub_tmgemg_rr(dataId == 2^5, :), yTestSub(dataId == 2^5,1:9));
	rmse_RR_wext(subjectId,:) = computeRMSE(yhatSub_tmgemg_rr(dataId == 2^6, :), yTestSub(dataId == 2^6,1:9));
	rmse_RR_wflex(subjectId,:) = computeRMSE(yhatSub_tmgemg_rr(dataId == -2^6, :), yTestSub(dataId == -2^6,1:9));
	rmse_RR_wsup(subjectId,:) = computeRMSE(yhatSub_tmgemg_rr(dataId == -2^8, :), yTestSub(dataId == -2^8,1:9));
	
	yhatSub_tmgemg_Eucl_Eucl = yhatTot_tmgemg_Eucl_Eucl(nbDataSub(subjectId)+1:nbDataSub(subjectId+1),:);
	rmse_Eucl_Eucl_rest(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_Eucl(dataId == 0 , :), yTestSub(dataId == 0,1:9));
	rmse_Eucl_Eucl_thumb(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_Eucl(dataId == 2^0 , :), yTestSub(dataId == 2^0,1:9));
	rmse_Eucl_Eucl_index(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_Eucl(dataId == 2^2, :), yTestSub(dataId == 2^2,1:9));
	rmse_Eucl_Eucl_little(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_Eucl(dataId == 2^5, :), yTestSub(dataId == 2^5,1:9));
	rmse_Eucl_Eucl_wext(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_Eucl(dataId == 2^6, :), yTestSub(dataId == 2^6,1:9));
	rmse_Eucl_Eucl_wflex(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_Eucl(dataId == -2^6, :), yTestSub(dataId == -2^6,1:9));
	rmse_Eucl_Eucl_wsup(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_Eucl(dataId == -2^8, :), yTestSub(dataId == -2^8,1:9));
	
	yhatSub_tmgemg_Eucl_SPD = yhatTot_tmgemg_Eucl_SPD(nbDataSub(subjectId)+1:nbDataSub(subjectId+1),:);
	rmse_Eucl_SPD_rest(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_SPD(dataId == 0 , :), yTestSub(dataId == 0,1:9));
	rmse_Eucl_SPD_thumb(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_SPD(dataId == 2^0 , :), yTestSub(dataId == 2^0,1:9));
	rmse_Eucl_SPD_index(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_SPD(dataId == 2^2, :), yTestSub(dataId == 2^2,1:9));
	rmse_Eucl_SPD_little(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_SPD(dataId == 2^5, :), yTestSub(dataId == 2^5,1:9));
	rmse_Eucl_SPD_wext(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_SPD(dataId == 2^6, :), yTestSub(dataId == 2^6,1:9));
	rmse_Eucl_SPD_wflex(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_SPD(dataId == -2^6, :), yTestSub(dataId == -2^6,1:9));
	rmse_Eucl_SPD_wsup(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_SPD(dataId == -2^8, :), yTestSub(dataId == -2^8,1:9));

	yhatSub_tmgemg_Eucl_logSPD = yhatTot_tmgemg_Eucl_logSPD(nbDataSub(subjectId)+1:nbDataSub(subjectId+1),:);
	rmse_Eucl_logSPD_rest(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_logSPD(dataId == 0 , :), yTestSub(dataId == 0,1:9));
	rmse_Eucl_logSPD_thumb(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_logSPD(dataId == 2^0 , :), yTestSub(dataId == 2^0,1:9));
	rmse_Eucl_logSPD_index(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_logSPD(dataId == 2^2, :), yTestSub(dataId == 2^2,1:9));
	rmse_Eucl_logSPD_little(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_logSPD(dataId == 2^5, :), yTestSub(dataId == 2^5,1:9));
	rmse_Eucl_logSPD_wext(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_logSPD(dataId == 2^6, :), yTestSub(dataId == 2^6,1:9));
	rmse_Eucl_logSPD_wflex(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_logSPD(dataId == -2^6, :), yTestSub(dataId == -2^6,1:9));
	rmse_Eucl_logSPD_wsup(subjectId,:) = computeRMSE(yhatSub_tmgemg_Eucl_logSPD(dataId == -2^8, :), yTestSub(dataId == -2^8,1:9));

	yhatSub_tmgemg_SPD_Eucl = yhatTot_tmgemg_SPD_Eucl(nbDataSub(subjectId)+1:nbDataSub(subjectId+1),:);
	rmse_SPD_Eucl_rest(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_Eucl(dataId == 0 , :), yTestSub(dataId == 0,1:9));
	rmse_SPD_Eucl_thumb(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_Eucl(dataId == 2^0 , :), yTestSub(dataId == 2^0,1:9));
	rmse_SPD_Eucl_index(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_Eucl(dataId == 2^2, :), yTestSub(dataId == 2^2,1:9));
	rmse_SPD_Eucl_little(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_Eucl(dataId == 2^5, :), yTestSub(dataId == 2^5,1:9));
	rmse_SPD_Eucl_wext(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_Eucl(dataId == 2^6, :), yTestSub(dataId == 2^6,1:9));
	rmse_SPD_Eucl_wflex(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_Eucl(dataId == -2^6, :), yTestSub(dataId == -2^6,1:9));
	rmse_SPD_Eucl_wsup(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_Eucl(dataId == -2^8, :), yTestSub(dataId == -2^8,1:9));
	
	yhatSub_tmgemg_SPD_SPD = yhatTot_tmgemg_SPD_SPD(nbDataSub(subjectId)+1:nbDataSub(subjectId+1),:);
	rmse_SPD_SPD_rest(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_SPD(dataId == 0 , :), yTestSub(dataId == 0,1:9));
	rmse_SPD_SPD_thumb(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_SPD(dataId == 2^0 , :), yTestSub(dataId == 2^0,1:9));
	rmse_SPD_SPD_index(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_SPD(dataId == 2^2, :), yTestSub(dataId == 2^2,1:9));
	rmse_SPD_SPD_little(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_SPD(dataId == 2^5, :), yTestSub(dataId == 2^5,1:9));
	rmse_SPD_SPD_wext(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_SPD(dataId == 2^6, :), yTestSub(dataId == 2^6,1:9));
	rmse_SPD_SPD_wflex(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_SPD(dataId == -2^6, :), yTestSub(dataId == -2^6,1:9));
	rmse_SPD_SPD_wsup(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_SPD(dataId == -2^8, :), yTestSub(dataId == -2^8,1:9));

	yhatSub_tmgemg_SPD_logSPD = yhatTot_tmgemg_SPD_logSPD(nbDataSub(subjectId)+1:nbDataSub(subjectId+1),:);
	rmse_SPD_logSPD_rest(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_logSPD(dataId == 0 , :), yTestSub(dataId == 0,1:9));
	rmse_SPD_logSPD_thumb(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_logSPD(dataId == 2^0 , :), yTestSub(dataId == 2^0,1:9));
	rmse_SPD_logSPD_index(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_logSPD(dataId == 2^2, :), yTestSub(dataId == 2^2,1:9));
	rmse_SPD_logSPD_little(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_logSPD(dataId == 2^5, :), yTestSub(dataId == 2^5,1:9));
	rmse_SPD_logSPD_wext(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_logSPD(dataId == 2^6, :), yTestSub(dataId == 2^6,1:9));
	rmse_SPD_logSPD_wflex(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_logSPD(dataId == -2^6, :), yTestSub(dataId == -2^6,1:9));
	rmse_SPD_logSPD_wsup(subjectId,:) = computeRMSE(yhatSub_tmgemg_SPD_logSPD(dataId == -2^8, :), yTestSub(dataId == -2^8,1:9));
	
end

figure('position',[500,300,1100,450]); hold on
error_vec = [rmse_RR_thumb; rmse_Eucl_Eucl_thumb; rmse_Eucl_SPD_thumb; rmse_Eucl_logSPD_thumb; rmse_SPD_Eucl_thumb; rmse_SPD_SPD_thumb; rmse_SPD_logSPD_thumb; ...
	rmse_RR_index; rmse_Eucl_Eucl_index; rmse_Eucl_SPD_index; rmse_Eucl_logSPD_index; rmse_SPD_Eucl_index; rmse_SPD_SPD_index;rmse_SPD_logSPD_index; ...
	rmse_RR_little; rmse_Eucl_Eucl_little; rmse_Eucl_SPD_little; rmse_Eucl_logSPD_little; rmse_SPD_Eucl_little; rmse_SPD_SPD_little; rmse_SPD_logSPD_little; ...
	rmse_RR_wext; rmse_Eucl_Eucl_wext; rmse_Eucl_SPD_wext; rmse_Eucl_logSPD_wext; rmse_SPD_Eucl_wext; rmse_SPD_SPD_wext; rmse_SPD_logSPD_wext; ...
	rmse_RR_wflex; rmse_Eucl_Eucl_wflex; rmse_Eucl_SPD_wflex; rmse_Eucl_logSPD_wflex; rmse_SPD_Eucl_wflex; rmse_SPD_SPD_wflex; rmse_SPD_logSPD_wflex; ...
	rmse_RR_wsup; rmse_Eucl_Eucl_wsup; rmse_Eucl_SPD_wsup; rmse_Eucl_logSPD_wsup; rmse_SPD_Eucl_wsup; rmse_SPD_SPD_wsup; rmse_SPD_logSPD_wsup	];
positions = bsxfun(@plus,[0.7 0.8 0.9 1 1.1 1.2 1.3 ]',0:6-1);
groups=[repmat({'RRthumb'},9,1); repmat({'EEthumb'},9,1);repmat({'ESthumb'},9,1);repmat({'ElSthumb'},9,1);repmat({'SEthumb'},9,1);repmat({'SSthumb'},9,1);repmat({'SlSthumb'},9,1);...
	repmat({'RRindex'},9,1); repmat({'EEindex'},9,1);repmat({'ESindex'},9,1);repmat({'ElSindex'},9,1);repmat({'SEindex'},9,1);repmat({'SSindex'},9,1);repmat({'SlSindex'},9,1);...
	repmat({'RRlittle'},9,1); repmat({'EElittle'},9,1);repmat({'ESlittle'},9,1);repmat({'ElSlittle'},9,1);repmat({'SElittle'},9,1);repmat({'SSlittle'},9,1);repmat({'SlSlittle'},9,1);...
	repmat({'RRwext'},9,1); repmat({'EEwext'},9,1);repmat({'ESwext'},9,1);repmat({'ElSwext'},9,1);repmat({'SEwext'},9,1);repmat({'SSwext'},9,1);repmat({'SlSwext'},9,1);...
	repmat({'RRwflex'},9,1); repmat({'EEwflex'},9,1);repmat({'ESwflex'},9,1);repmat({'ElSwflex'},9,1);repmat({'SEwflex'},9,1);repmat({'SSwflex'},9,1);repmat({'SlSwflex'},9,1);...
	repmat({'RRwsup'},9,1); repmat({'EEwsup'},9,1);repmat({'ESwsup'},9,1);repmat({'ElSwsup'},9,1);repmat({'SEwsup'},9,1);repmat({'SSwsup'},9,1);repmat({'SlSwsup'},9,1)];
boxplot(error_vec(:),groups,'Colors','k','widths',0.08,'positions',positions(:));
h = findobj(gca,'Tag','Box');
for j=1:7:length(h)
	p1 = patch(get(h(j),'XData'),get(h(j),'YData'),[0.9871 0.9914 0.7495],'FaceAlpha',.75);
end
for j=2:7:length(h)
	p2 = patch(get(h(j),'XData'),get(h(j),'YData'),[0.9970 0.6865 0.4692],'FaceAlpha',.75);
end
for j=3:7:length(h)
	p3 = patch(get(h(j),'XData'),get(h(j),'YData'),[0.9440 0.3776 0.3651],'FaceAlpha',.75);
end
for j=4:7:length(h)
	p4 = patch(get(h(j),'XData'),get(h(j),'YData'),[0.7132 0.2139 0.4763],'FaceAlpha',.75);
end
for j=5:7:length(h)
	p5 = patch(get(h(j),'XData'),get(h(j),'YData'),[0.4452 0.1227 0.5069],'FaceAlpha',.75);
end
for j=6:7:length(h)
	p6 = patch(get(h(j),'XData'),get(h(j),'YData'),[0.1749 0.0670 0.3751],'FaceAlpha',.75);
end
for j=7:7:length(h)
	p7 = patch(get(h(j),'XData'),get(h(j),'YData'),[0.0015 0.0005 0.0139],'FaceAlpha',.75);
end

ylim([0 .65]);
set(gca,'xtick',1:6, 'xticklabel',{'Thumb flex.','Index flex.','Little flex.', 'Wrist ext.', 'Wrist flex.','Wrist sup.'},'Fontsize',14);
xlabel('Movement','Fontsize',18);
ylabel('RMSE','Fontsize',18);
legend([p7,p6,p5,p4,p3,p2,p1],'RR','Eucl/Eucl','Eucl/logSPD','Eucl/SPD','SPD/Eucl',...
	'SPD/logSPD','SPD/SPD','Location','north','Orientation','horizontal');
if(saveOpt)
	print('-dpng','graphs/exp2_rmse_movement_MULTIMODAL.png');
end

end

function [ error ] = computeRMSE( Y, Yhat )
%computeRMSE Computes the root mean square error
%
%   Y       Expected output N x d
%   YHat    Predicted output N x d

N = length(Y);

diff_square = sum((Y-Yhat).^2,2);

error = sum(diff_square);

error = sqrt(error./N);
end