load('/home/jph/Uni/masterarbeit/evaluation.mat')

figureSavePath='/home/jph/Uni/masterarbeit/text/thesis/pictures/results/';
% mySaveFigure(gcf,strcat(figureSavePath,'plot'))
%% compare methods of recording
% velocities
eegCorrKin=pickFromStruct(correlations.EEG.kin,1:3);
emgCorrKin=correlations.EMG.kin.Default;
LFCorrKin=pickFromStruct(correlations.LF.kin,1:3);
EEG=cell(3*size(eegCorrKin,1),1);
EEG(:)={'EEG'};
EMG=cell(3,1);
EMG(:)={'EMG'};
LF=cell(3*size(LFCorrKin,1),1);
LF(:)={'LF'};

anova1(cell2mat(cat(1,eegCorrKin,emgCorrKin,LFCorrKin)'),cat(1,EEG,EMG,LF))

ylabel('correlation recorded - predicted')
title('prediction of velocities for EEG, EMG and LF')
anova1(cell2mat(cat(1,eegCorrKin,emgCorrKin)'),cat(1,EEG,EMG))
anova1(cell2mat(cat(1,eegCorrKin,LFCorrKin)'),cat(1,EEG,LF))
anova1(cell2mat(cat(1,emgCorrKin,LFCorrKin)'),cat(1,EMG,LF))

% positions
eegCorrPos=pickFromStruct(correlations.EEG.pos,1:3);
emgCorrPos=correlations.EMG.pos.Default;
LFCorrPos=pickFromStruct(correlations.LF.pos,1:3);
EEG=cell(3*size(eegCorrPos,1),1);
EEG(:)={'EEG'};
EMG=cell(3,1);
EMG(:)={'EMG'};
LF=cell(3*size(LFCorrPos,1),1);
LF(:)={'LF'};

anova1(cell2mat(cat(1,eegCorrPos,emgCorrPos,LFCorrPos)'),cat(1,EEG,EMG,LF))
ylabel('correlation recorded - predicted')
title('prediction of positions for EEG, EMG and LF')
anova1(cell2mat(cat(1,eegCorrPos,emgCorrPos)'),cat(1,EEG,EMG))
anova1(cell2mat(cat(1,eegCorrPos,LFCorrPos)'),cat(1,EEG,LF))
anova1(cell2mat(cat(1,emgCorrPos,LFCorrPos)'),cat(1,EMG,LF))

%% compare direct and via
%kin
direct=correlations.EEG.kin.Default;
viaAutoenc=correlations.EEG.kin.ViaAutoenc;
viaPCA=correlations.EEG.kin.ViaPCA;
viaNNMF=correlations.EEG.kin.ViaNNMF;

anova1([direct(:),viaAutoenc(:),viaPCA(:),viaNNMF(:)],{'direct','Autoenc','PCA','NMF'})
ylabel('correlation recorded - predicted')
title('Compare velocity prediction direct and via')

anova1([viaAutoenc(:),viaPCA(:),viaNNMF(:)],{'Autoenc','PCA','NMF'})

%pos
direct=correlations.EEG.pos.Default;
viaAutoenc=correlations.EEG.pos.ViaAutoenc;
viaPCA=correlations.EEG.pos.ViaPCA;
viaNNMF=correlations.EEG.pos.ViaNNMF;

anova1([direct(:),viaAutoenc(:),viaPCA(:),viaNNMF(:)],{'direct','Autoenc','PCA','NMF'})
ylabel('correlation recorded - predicted')
title('Compare position prediction direct and via')

anova1([viaAutoenc(:),viaPCA(:),viaNNMF(:)],{'Autoenc','PCA','NMF'})

% EMG
direct=correlations.EEG.emg.Default;
viaAutoenc=correlations.EEG.emg.ViaAutoenc;

anova1([direct(:),viaAutoenc(:)],{'direct','Autoenc'})
ylabel('correlation recorded - predicted')
title('Compare EMG prediction direct and viaAutoenc')
mySaveFigure(gcf,'predictEMGfromEEG')

%% evaluate single combination
input=correlations.LF.Autoenc;
sizeY=2;
limits_y=[1,-1];

names=fieldnames(input);
noOfPlots=size(names,1);

for i=1:noOfPlots
    limits_y=[min(min(min(input.(sprintf('%s',names{i})))),limits_y(1)),...
        max(max(max(input.(sprintf('%s',names{i})))),limits_y(2))];
end
limits_y=[limits_y(1)-0.1*diff(limits_y),limits_y(2)+0.1*diff(limits_y)]

figure();

sizeX=ceil(noOfPlots/sizeY);
for i=1:noOfPlots
    subplot(sizeY,sizeX,i)
    boxplot(input.(sprintf('%s',names{i})))
    title(names{i})
    ylim(limits_y)
    if ceil(i/sizeX) > ceil((i-1)/sizeX)
        ylabel('correlation recorded - predicted')
    end
end

anova1(cat(2,input.Default(:),input.Offset1(:),input.Offset2(:)),[0,1,2])
ylabel('Offset')
anova1(cat(2,input.Default(:),input.Offset1(:),input.Pause1(:),input.Pause1Offset1(:)),{'0.5s Pause','0.5s Pause', '1s Pause', '1s Pause'})

%% EEG to EMG
EMGChannels={'AbdPolLo','Biceps','Triceps','FrontDelt','MidDelt','BackDelt'};

anova1(correlations.EEG.emg.Default,EMGChannels)

title('EMG from EEG')
mySaveFigure(gcf,strcat(figureSavePath,'EEGemg'))