diff --git a/evaluation.mat b/evaluation.mat index 9750f23..e0c755c 100644 --- a/evaluation.mat +++ b/evaluation.mat Binary files differ diff --git a/text/TODO.txt b/text/TODO.txt index 3756d86..9b0a74e 100644 --- a/text/TODO.txt +++ b/text/TODO.txt @@ -122,7 +122,5 @@ ---- * compare Autoenc -> kin to PCA -> kin and NNMF -> kin * ridgeCV - - -* max per class * 2 und 4 Synergien * vergleich EMG Synergie diff --git a/text/thesis/02MaterialsAndMethods.tex b/text/thesis/02MaterialsAndMethods.tex index 06f45c5..57cb268 100644 --- a/text/thesis/02MaterialsAndMethods.tex +++ b/text/thesis/02MaterialsAndMethods.tex @@ -375,7 +375,7 @@ \subsection{EEG offset} \label{mat:offset} Since it takes some time for commands to go from brain to the muscles, we introduced an variable offset between EEG and other data. The offset has to be given in a number of shifts, so in default is a multiple of 200ms.\\ - Results are given in Section~\ref{res:offset}. + Results are given in Sections~\ref{res:offsetEEG} and~\ref{res:offsetLF}. \subsection{Pause} \label{mat:pause} \subsection{Prediction with interim step} diff --git a/text/thesis/03Results.tex b/text/thesis/03Results.tex index f32f80c..5672470 100644 --- a/text/thesis/03Results.tex +++ b/text/thesis/03Results.tex @@ -1,6 +1,7 @@ \chapter{Results} \label{chp:results} \section{Classification} +%TODO: Confusion Matrices \subsection{Comparison of methods of recording} The different methods of recording (EEG, EMG and Low frequencies) also differ in the results. An ANOVA gives $p<0.001$ for all classifications done on 4 different movements and rest. \begin{figure} @@ -16,7 +17,7 @@ \begin{array} {r||c|c|c|c} &\text{EMG}&\text{EEG}&\text{LF}&\text{chance}\\\hline - mean&60.4&40.4&32.7&25\\ + mean&60.4&40.4&32.7&20\\ std&7.97&2.27&3.35\\ max&71.9&46.7&43.4\\ min&35.7&37.2&26.2 @@ -25,12 +26,6 @@ \caption{Accuracys for the different methods of recording in default configuration} \label{tab:accs} \end{table} - % \begin{itemize} - % \item[EMG:] $60.4\%$ - % \item[EEG:] $40.4\%$ - % \item[LF:] $32.7\%$ - % \item[chance:] $25\%$ - % \end{itemize} \subsection{EMG} In figure~\ref{fig:overviewEMG} the different settings for classification based on EMG-data are shown. Default has values as in \ref{mat:default}. The runs with pause leave out the data 1 second before the movement begins (cf. \ref{mat:pause}). \begin{figure} @@ -39,12 +34,6 @@ \caption{Classification with EMG-data} \label{fig:overviewEMG} \end{figure} - % \begin{figure} - % \centering - % \includegraphics[width=\textwidth]{pictures/results/pauseEMG.png} - % \caption{EMG-data without and with pause} - % \label{fig:pauseEMG} - % \end{figure} When calculating an ANOVA on the data with and without pause we get $p<0.001$. \subsection{EEG} In figure~\ref{fig:overviewEEG} the different settings for classification based on EEG-data are shown. Default has values as in \ref{mat:default}. The runs with pause leave out the data 1 second before the movement begins (cf. \ref{mat:pause}). Runs with offset have an offset of 1 or 2 (cf. \ref{mat:offset}). @@ -64,10 +53,28 @@ \end{figure} \subsection{Trade-off parameter} With a cross validation we compare the results for the soft-margin parameter for $\lambda=0.1,1,10$. The results are shown in figure~\ref{fig:svmCV}.%TODO + \subsection{Confusion Matrices} + A confusion matrix shows whether there is systematic error in classification. In figure \ref{fig:cmFull} there are the confusion matrices for EEG and Low Frequency data, in figure \ref{fig:cmEMG} there is the confusion matrix for EMG data. Since EMG works well for classifying Move/Rest there is also one where only the decision is shown which movement is present. In the second plot we see that many movements are classified as class 3. Especially those belonging to class 2. + \begin{figure}[p] + \centering + \includegraphics[width=\textwidth]{pictures/results/cmEEGfull.png} + \includegraphics[width=\textwidth]{pictures/results/cmLFfull.png} + \caption{Confusion Matrices in default configuration} + \label{fig:cmFull} + \end{figure} + \begin{figure}[p] + \centering + \includegraphics[width=\textwidth]{pictures/results/cmEMGfull.png} + \includegraphics[width=\textwidth]{pictures/results/cmEMGmovements.png} + \caption{Confusion Matrices in default configuration} + \label{fig:cmEMG} + \end{figure} + \section{Regression} \subsection{Comparison of methods of recording} \subsubsection{Velocities} - Predicting velocities from EEG, EMG and Low Frequencies is significantly\footnote{$p<0.001$} pairwise different (cf. figure~\ref{fig:corrEEGemgLF}). The corresponding $p$-Values of the ANOVA are given in table~\ref{tab:pCorr}. + Predicting velocities from EEG, EMG and Low Frequencies is significantly\footnote{$p<0.001$} pairwise different (cf. figure~\ref{fig:corrEEGemgLF}). The corresponding $p$-Values of the ANOVA are given in table~\ref{tab:pCorr}.\\ + The over all performance is given in table \ref{tab:corrKin}. \begin{figure} \centering \includegraphics[width=0.9\textwidth]{pictures/results/corrEEGemgLF.png} @@ -88,8 +95,24 @@ \caption{$p$-Values for prediction of velocities from EEG, EMG or LF respectively} \label{tab:pCorr} \end{table} + \begin{table} + \centering + \begin{math} + \begin{array} + {r||c|c|c|c} + &\text{EMG}&\text{EEG}&\text{LF}\\\hline + mean&(0.06,0.08,0.02)&(0.18,0.20,0.01)&(0.04,0.07,-0.01)\\ + std&(0.05,0.05,0.02)&(0.15,0.13,0.09)&(0.05,0.05,0.04)\\ + max&(0.19,0.17,0.11)&(0.49,0.49,0.21)&(0.16,0.17,0.10)\\ + min&(-0.007,0.003,-0.01)&(-0.06,-0.03,-0.18)&(-0.07,-0.02,-0.08) + \end{array} + \end{math} + \caption{Correlations for the different methods of recording in default configuration predicting velocities} + \label{tab:corrKin} + \end{table} \subsubsection{Positions} - Predicting positions from EEG, EMG and Low Frequencies is significantly\footnote{$p<0.001$} different, however not pairwise (cf. figure~\ref{fig:corrEEGemgLFpos}). Positions predicted from EMG and LF are not significantly different. The corresponding $p$-Values of the ANOVA are given in table~\ref{tab:pCorrPos}. + Predicting positions from EEG, EMG and Low Frequencies is significantly\footnote{$p<0.001$} different, however not pairwise (cf. figure~\ref{fig:corrEEGemgLFpos}). Positions predicted from EMG and LF are not significantly different. The corresponding $p$-Values of the ANOVA are given in table~\ref{tab:pCorrPos}.\\ + The over all performance is given in table \ref{tab:corrPos}. \begin{figure} \centering \includegraphics[width=0.9\textwidth]{pictures/results/corrEEGemgLFpos.png} @@ -110,6 +133,21 @@ \caption{$p$-Values for prediction of positions from EEG, EMG or LF respectively} \label{tab:pCorrPos} \end{table} + \begin{table} + \centering + \begin{math} + \begin{array} + {r||c|c|c|c} + &\text{EMG}&\text{EEG}&\text{LF}\\\hline + mean&(0.27,0.30,0.15)&(0.57,0.56,0.50)&(0.27,0.26,0.20)\\ + std&(0.14,0.16,0.09)&(0.13,0.13,0.13)&(0.09,0.07,0.08)\\ + max&(0.52,0.56,0.42)&(0.79,0.75,0.84)&(0.52,0.43,0.44)\\ + min&(0.07,0.05,0.04)&(0.19,0.28,0.24)&(0.13,0.14,0.10) + \end{array} + \end{math} + \caption{Correlations for the different methods of recording in default configuration predicting positions} + \label{tab:corrPos} + \end{table} \subsection{Compare Prediction direct and via Synergies} \subsubsection{Velocities} There is a significant\footnote{$p<0.001$} difference between the predictions. The different synergies however have no significant difference ($p\approx0.87$). Also see figure~\ref{fig:directVia}. @@ -127,11 +165,28 @@ \caption{Positions predicted from EEG direct or via Synergies} \label{fig:directViaPos} \end{figure} + \subsubsection{EMG} + There is a significant difference between predicting EMG from EEG directly or via Autoencoders ($p<0.001$, see figure~\ref{fig:directViaEMG}). + \begin{figure} + \centering + \includegraphics[width=\textwidth]{pictures/results/predictEMGfromEEG.png} + \caption{EMG predicted from EEG direct or via Autoencoder} + \label{fig:directViaEMG} + \end{figure} \subsection{EEG} \subsubsection{Offset} + \label{res:offsetEEG} Offset makes no significant difference when predicting Synergies\footnote{Autoencoder: $p\approx0.81$, PCA: $p\approx0.77$, NMF: $p\approx0.60$} or velocities ($p\approx0.99$) or positions ($p\approx0.98$). \subsubsection{Pause} Whether there is a pause of 1s or only 0.5s doesn't make a significant difference for Autoencoder ($p\approx0.13$), PCA ($p\approx0.29$), NMF ($p\approx0.05$) or Velocities ($p\approx0.95$). + \subsubsection{EMG} + We also predict EMG from EEG. The results are shown in figure \ref{fig:EEGemg}. There are no significant differences between the channels ($p\approx0.29$). + \begin{figure} + \centering + \includegraphics[width=\textwidth]{pictures/results/EEGemg.png} + \caption{Prediction of EMG from EEG} + \label{fig:EEGemg} + \end{figure} \subsection{EMG} Using a offset or not does not make any difference since the offset is only applied on EEG-data (cf. \ref{mat:offset}).\\ Predicting synergies from EMG does not make sense since they are computed from EMG (cf. \ref{mat:synergies}).\\ @@ -139,6 +194,7 @@ There is no significant effect of the use of a pause when predicting velocities from EMG ($p\approx0.90$). \subsection{Low Frequencies} \subsubsection{Offset} + \label{res:offsetLF} Offset makes no significant difference for predicting Autoencoder ($p\approx0.50$), PCA ($p\approx0.59$), NMF ($p\approx0.38$), velocities ($p\approx0.97$) or position ($p\approx1.0$). \subsubsection{Pause} There is no effect of pause for velocities from low frequencies ($p\approx0.73$).\\ @@ -151,6 +207,24 @@ \caption{Autoencoder data predicted from Low Frequencies} \label{fig:lfToAutoencPause} \end{figure} -% mean, std of correlation -%EEG -> EMG -%Autoenc kin/pos + \subsection{Autoencoder} + In table~\ref{tab:corrAutoenc} the correlations for velocities and positions predicted from Autoencoder are given. The data for the Autoencoder were calculated from recorded EMG data. + \begin{table} + \centering + \begin{math} + \begin{array} + {r||c|c|c|c} + &\text{velocities}&\text{positions}\\\hline + mean&(0.05,0.08,0.01)&(0.20,0.29,0.11)\\ + std&(0.04,0.05,0.02)&(0.12,0.16,0.08)\\ + max&(0.18,0.17,0.08)&(0.51,0.60,0.38)\\ + min&(-0.02,-0.01,-0.01)&(0.03,0.03,0.02) + \end{array} + \end{math} + \caption{Correlations for predicting velocities and positions from Autoencoder data} + \label{tab:corrAutoenc} + \end{table} + \subsection{Cross-validation of Ridge Parameter} + %TODO +\section{Topographical plots} + %Maybe in discussion diff --git a/text/thesis/pictures/results/EEGemg.png b/text/thesis/pictures/results/EEGemg.png new file mode 100644 index 0000000..4afe22f --- /dev/null +++ b/text/thesis/pictures/results/EEGemg.png Binary files differ diff --git a/text/thesis/pictures/results/cmEEGfull.png b/text/thesis/pictures/results/cmEEGfull.png new file mode 100644 index 0000000..c011ddc --- /dev/null +++ b/text/thesis/pictures/results/cmEEGfull.png Binary files differ diff --git a/text/thesis/pictures/results/cmEMGfull.png b/text/thesis/pictures/results/cmEMGfull.png new file mode 100644 index 0000000..394853c --- /dev/null +++ b/text/thesis/pictures/results/cmEMGfull.png Binary files differ diff --git a/text/thesis/pictures/results/cmEMGmovements.png b/text/thesis/pictures/results/cmEMGmovements.png new file mode 100644 index 0000000..3b7d969 --- /dev/null +++ b/text/thesis/pictures/results/cmEMGmovements.png Binary files differ diff --git a/text/thesis/pictures/results/cmLFfull.png b/text/thesis/pictures/results/cmLFfull.png new file mode 100644 index 0000000..40d1436 --- /dev/null +++ b/text/thesis/pictures/results/cmLFfull.png Binary files differ diff --git a/text/thesis/pictures/results/predictEMGfromEEG.png b/text/thesis/pictures/results/predictEMGfromEEG.png new file mode 100644 index 0000000..df3a43f --- /dev/null +++ b/text/thesis/pictures/results/predictEMGfromEEG.png Binary files differ diff --git a/usedMcode/evaluation.m b/usedMcode/evaluation.m index 3e9ad9e..62a346f 100644 --- a/usedMcode/evaluation.m +++ b/usedMcode/evaluation.m @@ -36,6 +36,7 @@ correlations.EEG.pos.ViaAutoenc=correlationViaAutoenc; correlations.EEG.pos.ViaNNMF=correlationViaNNMF; correlations.EEG.pos.ViaPCA=correlationViaPCA; +correlations.EEG.emg.ViaAutoenc=correlationEMGViaAutoenc; correlations.Autoenc.pos.Default=correlationAutoencKin; diff --git a/usedMcode/evaluationCorrelations.m b/usedMcode/evaluationCorrelations.m index 791ee34..d252a06 100644 --- a/usedMcode/evaluationCorrelations.m +++ b/usedMcode/evaluationCorrelations.m @@ -1,7 +1,7 @@ load('/home/jph/Uni/masterarbeit/evaluation.mat') figureSavePath='/home/jph/Uni/masterarbeit/text/thesis/pictures/results/'; -% saveFigure(gcf,'plot') +% mySaveFigure(gcf,'plot') %% compare methods of recording % velocities eegCorrKin=pickFromStruct(correlations.EEG.kin,1:3); @@ -65,6 +65,15 @@ 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; @@ -92,3 +101,11 @@ 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') +saveFigure(gcf,strcat(figureSavePath,'EEGemg')) \ No newline at end of file diff --git a/usedMcode/mySaveFigure.m b/usedMcode/mySaveFigure.m new file mode 100644 index 0000000..504c07e --- /dev/null +++ b/usedMcode/mySaveFigure.m @@ -0,0 +1,9 @@ +function []=mySaveFigure(fig,filename) + + set(fig,'Position',[251 49 1105 636]); + axes = findobj(fig,'type','axes'); + set(axes,'FontSize',12); + set(fig,'PaperPositionMode','auto'); + print(fig,'-dpng','-zbuffer','-r300',filename) + disp(strcat('file saved at ',filename)) +end \ No newline at end of file diff --git a/usedMcode/overview.m b/usedMcode/overview.m new file mode 100644 index 0000000..625e15b --- /dev/null +++ b/usedMcode/overview.m @@ -0,0 +1,6 @@ +input=correlations.EEG.emg.Default; + +m=mean(input) +s=std(input) +ma=max(input) +mi=min(input) \ No newline at end of file diff --git a/usedMcode/plotCM.m b/usedMcode/plotCM.m new file mode 100644 index 0000000..c0d291c --- /dev/null +++ b/usedMcode/plotCM.m @@ -0,0 +1,22 @@ +function [fig] = plotCM(cm,figureTitle) + imagesc(squeeze(mean(cm,1))) + colorbar(); + fig=gcf; + axes =gca; + if size(cm,2)==5 + axes.YAxis.TickLabels={'Rest','1','2','3','4'}; + axes.YAxis.TickValues=[1,2,3,4,5]; + axes.XAxis.TickLabels={'Rest','1','2','3','4'}; + axes.XAxis.TickValues=[1,2,3,4,5]; + elseif size(cm,2)==4 + axes.YAxis.TickLabels={'1','2','3','4'}; + axes.YAxis.TickValues=[1,2,3,4]; + axes.XAxis.TickLabels={'1','2','3','4'}; + axes.XAxis.TickValues=[1,2,3,4]; + else + error('CM has neither 5 nor 4 entries - change plotCM to match your needs') + end + xlabel('classified as') + ylabel('actual class') + title(figureTitle) +end \ No newline at end of file diff --git a/usedMcode/saveFigure.m b/usedMcode/saveFigure.m deleted file mode 100644 index b2e2f84..0000000 --- a/usedMcode/saveFigure.m +++ /dev/null @@ -1,9 +0,0 @@ -function []=saveFigure(fig,filename) - - set(fig,'Position',[251 49 1105 636]); - axes = findobj(fig,'type','axes'); - set(axes,'FontSize',12); - set(fig,'PaperPositionMode','auto'); - print(fig,'-dpng','-zbuffer','-r300',filename) - disp(strcat('file saved at ',filename)) -end \ No newline at end of file