diff --git a/text/TODO.txt b/text/TODO.txt index 5db7e0a..6f78c2a 100644 --- a/text/TODO.txt +++ b/text/TODO.txt @@ -44,7 +44,9 @@ shift echt variabel, bisher EEG und EMG gleich (done) -offset für EEG +offset für EEG (done) + +debug Output, Fortschritt Refactoring, Comments (incl. save -append) diff --git a/usedMcode/callAll.m b/usedMcode/callAll.m index 99d6ae8..6f8ad3b 100644 --- a/usedMcode/callAll.m +++ b/usedMcode/callAll.m @@ -7,11 +7,12 @@ noSynergies=4; allSubjects=false; %run all subjects and days or only one random day for one random subject -name='differentShifts'; %suffix for the output, has to be valid name for file (no space, /, ...) +name='eegOffsetSingle'; %suffix for the output, has to be valid name for file (no space, /, ...) windowEMG=0.2; windowEEG=1; shiftEMG=0.05; shiftEEG=0.2; +eegOffset=1; %predict actions x*shiftEEG after EEG measurement pburgOrder=50; minEEGFreq=0; maxEEGFreq=200; @@ -77,21 +78,21 @@ number=numbersMat(j); subject=subjectsForNumbers{j}; savePath=readAll(pathToFile,subject,number,windowEMG,windowEEG,shiftEMG,shiftEEG,maxFile,threshold,pburgOrder,minEEGFreq,maxEEGFreq,pause,noLFsamples); - [meanAccurancysEMG(j),maxCEMG(j,:),cmScaledEMG(j,:,:)]=svmEciton(savePath,'EMG',k,maxExpC,maxPerClass); - [meanAccurancysEEG(j),maxCEEG(j,:),cmScaledEEG(j,:,:)]=svmEciton(savePath,'EEG',k,maxExpC,maxPerClass); - [meanAccurancysLF(j),maxCLF(j,:),cmScaledLF(j,:,:)]=svmEciton(savePath,'LF',k,maxExpC,maxPerClass); - [correlationEMGkin(j,:),maxRidgeParamIndexEMGkin(j,:,:)]=ridgeCV(savePath,'EMG','kin',k,ridgeParams,shiftEMG,shiftEEG); - [correlationEEGkin(j,:),maxRidgeParamIndexEEGkin(j,:,:)]=ridgeCV(savePath,'EEG','kin',k,ridgeParams,shiftEMG,shiftEEG); - [correlationLFkin(j,:),maxRidgeParamIndexLFkin(j,:,:)]=ridgeCV(savePath,'LF','kin',k,ridgeParams,shiftEMG,shiftEEG); - [correlationEMGautoenc(j,:),maxRidgeParamIndexEMGautoenc(j,:,:)]=ridgeCV(savePath,'EMG','Autoenc',k,ridgeParams,shiftEMG,shiftEEG); - [correlationEEGautoenc(j,:),maxRidgeParamIndexEEGautoenc(j,:,:)]=ridgeCV(savePath,'EEG','Autoenc',k,ridgeParams,shiftEMG,shiftEEG); - [correlationLFautoenc(j,:),maxRidgeParamIndexLFautoenc(j,:,:)]=ridgeCV(savePath,'LF','Autoenc',k,ridgeParams,shiftEMG,shiftEEG); - [correlationEMGpca(j,:),maxRidgeParamIndexEMGpca(j,:,:)]=ridgeCV(savePath,'EMG','PCA',k,ridgeParams,shiftEMG,shiftEEG); - [correlationEEGpca(j,:),maxRidgeParamIndexEEGpca(j,:,:)]=ridgeCV(savePath,'EEG','PCA',k,ridgeParams,shiftEMG,shiftEEG); - [correlationLFpca(j,:),maxRidgeParamIndexLFpca(j,:,:)]=ridgeCV(savePath,'LF','PCA',k,ridgeParams,shiftEMG,shiftEEG); - [correlationEMGnnmf(j,:),maxRidgeParamIndexEMGnnmf(j,:,:)]=ridgeCV(savePath,'EMG','NNMF',k,ridgeParams,shiftEMG,shiftEEG); - [correlationEEGnnmf(j,:),maxRidgeParamIndexEEGnnmf(j,:,:)]=ridgeCV(savePath,'EEG','NNMF',k,ridgeParams,shiftEMG,shiftEEG); - [correlationLFnnmf(j,:),maxRidgeParamIndexLFnnmf(j,:,:)]=ridgeCV(savePath,'LF','NNMF',k,ridgeParams,shiftEMG,shiftEEG); + [meanAccurancysEMG(j),maxCEMG(j,:),cmScaledEMG(j,:,:)]=svmEciton(savePath,'EMG',k,maxExpC,maxPerClass,eegOffset); + [meanAccurancysEEG(j),maxCEEG(j,:),cmScaledEEG(j,:,:)]=svmEciton(savePath,'EEG',k,maxExpC,maxPerClass,eegOffset); + [meanAccurancysLF(j),maxCLF(j,:),cmScaledLF(j,:,:)]=svmEciton(savePath,'LF',k,maxExpC,maxPerClass,eegOffset); + [correlationEMGkin(j,:),maxRidgeParamIndexEMGkin(j,:,:)]=ridgeCV(savePath,'EMG','kin',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + [correlationEEGkin(j,:),maxRidgeParamIndexEEGkin(j,:,:)]=ridgeCV(savePath,'EEG','kin',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + [correlationLFkin(j,:),maxRidgeParamIndexLFkin(j,:,:)]=ridgeCV(savePath,'LF','kin',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + %[correlationEMGautoenc(j,:),maxRidgeParamIndexEMGautoenc(j,:,:)]=ridgeCV(savePath,'EMG','Autoenc',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + [correlationEEGautoenc(j,:),maxRidgeParamIndexEEGautoenc(j,:,:)]=ridgeCV(savePath,'EEG','Autoenc',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + [correlationLFautoenc(j,:),maxRidgeParamIndexLFautoenc(j,:,:)]=ridgeCV(savePath,'LF','Autoenc',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + %[correlationEMGpca(j,:),maxRidgeParamIndexEMGpca(j,:,:)]=ridgeCV(savePath,'EMG','PCA',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + [correlationEEGpca(j,:),maxRidgeParamIndexEEGpca(j,:,:)]=ridgeCV(savePath,'EEG','PCA',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + [correlationLFpca(j,:),maxRidgeParamIndexLFpca(j,:,:)]=ridgeCV(savePath,'LF','PCA',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + %[correlationEMGnnmf(j,:),maxRidgeParamIndexEMGnnmf(j,:,:)]=ridgeCV(savePath,'EMG','NNMF',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + [correlationEEGnnmf(j,:),maxRidgeParamIndexEEGnnmf(j,:,:)]=ridgeCV(savePath,'EEG','NNMF',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + [correlationLFnnmf(j,:),maxRidgeParamIndexLFnnmf(j,:,:)]=ridgeCV(savePath,'LF','NNMF',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); fprintf('%s%i finished %s\n',subject,number,datestr(datetime('now'))) end @@ -102,25 +103,23 @@ number=numbersMat(j); subject=subjectsForNumbers{j}; savePath=readAll(pathToFile,subject,number,windowEMG,windowEEG,shiftEMG,shiftEEG,maxFile,threshold,pburgOrder,minEEGFreq,maxEEGFreq,pause,noLFsamples,EMGChannels,noSynergies); - [meanAccurancysEMG,maxCEMG,cmScaledEMG(:,:)]=svmEciton(savePath,'EMG',k,maxExpC,maxPerClass); - [meanAccurancysEEG,maxCEEG,cmScaledEEG(:,:)]=svmEciton(savePath,'EEG',k,maxExpC,maxPerClass); - [meanAccurancysLF,maxCLF,cmScaledLF(:,:)]=svmEciton(savePath,'LF',k,maxExpC,maxPerClass); - [correlationEMGkin,maxRidgeParamIndexEMGkin(:,:)]=ridgeCV(savePath,'EMG','kin',k,ridgeParams,shiftEMG,shiftEEG); - [correlationEEGkin,maxRidgeParamIndexEEGkin(:,:)]=ridgeCV(savePath,'EEG','kin',k,ridgeParams,shiftEMG,shiftEEG); - [correlationLFkin,maxRidgeParamIndexLFkin(:,:)]=ridgeCV(savePath,'LF','kin',k,ridgeParams,shiftEMG,shiftEEG); - [correlationEMGautoenc,maxRidgeParamIndexEMGautoenc(:,:)]=ridgeCV(savePath,'EMG','Autoenc',k,ridgeParams,shiftEMG,shiftEEG); - [correlationEEGautoenc,maxRidgeParamIndexEEGautoenc(:,:)]=ridgeCV(savePath,'EEG','Autoenc',k,ridgeParams,shiftEMG,shiftEEG); - [correlationLFautoenc,maxRidgeParamIndexLFautoenc(:,:)]=ridgeCV(savePath,'LF','Autoenc',k,ridgeParams,shiftEMG,shiftEEG); - [correlationEMGpca,maxRidgeParamIndexEMGpca(:,:)]=ridgeCV(savePath,'EMG','PCA',k,ridgeParams,shiftEMG,shiftEEG); - [correlationEEGpca,maxRidgeParamIndexEEGpca(:,:)]=ridgeCV(savePath,'EEG','PCA',k,ridgeParams,shiftEMG,shiftEEG); - [correlationLFpca,maxRidgeParamIndexLFpca(:,:)]=ridgeCV(savePath,'LF','PCA',k,ridgeParams,shiftEMG,shiftEEG); - [correlationEMGnnmf,maxRidgeParamIndexEMGnnmf(:,:)]=ridgeCV(savePath,'EMG','NNMF',k,ridgeParams,shiftEMG,shiftEEG); - [correlationEEGnnmf,maxRidgeParamIndexEEGnnmf(:,:)]=ridgeCV(savePath,'EEG','NNMF',k,ridgeParams,shiftEMG,shiftEEG); - [correlationLFnnmf,maxRidgeParamIndexLFnnmf(:,:)]=ridgeCV(savePath,'LF','NNMF',k,ridgeParams,shiftEMG,shiftEEG); + [meanAccurancysEMG,maxCEMG,cmScaledEMG(:,:)]=svmEciton(savePath,'EMG',k,maxExpC,maxPerClass,eegOffset); + [meanAccurancysEEG,maxCEEG,cmScaledEEG(:,:)]=svmEciton(savePath,'EEG',k,maxExpC,maxPerClass,eegOffset); + [meanAccurancysLF,maxCLF,cmScaledLF(:,:)]=svmEciton(savePath,'LF',k,maxExpC,maxPerClass,eegOffset); + [correlationEMGkin,maxRidgeParamIndexEMGkin(:,:)]=ridgeCV(savePath,'EMG','kin',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + [correlationEEGkin,maxRidgeParamIndexEEGkin(:,:)]=ridgeCV(savePath,'EEG','kin',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + [correlationLFkin,maxRidgeParamIndexLFkin(:,:)]=ridgeCV(savePath,'LF','kin',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + %[correlationEMGautoenc,maxRidgeParamIndexEMGautoenc(:,:)]=ridgeCV(savePath,'EMG','Autoenc',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + [correlationEEGautoenc,maxRidgeParamIndexEEGautoenc(:,:)]=ridgeCV(savePath,'EEG','Autoenc',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + [correlationLFautoenc,maxRidgeParamIndexLFautoenc(:,:)]=ridgeCV(savePath,'LF','Autoenc',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + %[correlationEMGpca,maxRidgeParamIndexEMGpca(:,:)]=ridgeCV(savePath,'EMG','PCA',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + [correlationEEGpca,maxRidgeParamIndexEEGpca(:,:)]=ridgeCV(savePath,'EEG','PCA',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + [correlationLFpca,maxRidgeParamIndexLFpca(:,:)]=ridgeCV(savePath,'LF','PCA',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + %[correlationEMGnnmf,maxRidgeParamIndexEMGnnmf(:,:)]=ridgeCV(savePath,'EMG','NNMF',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + [correlationEEGnnmf,maxRidgeParamIndexEEGnnmf(:,:)]=ridgeCV(savePath,'EEG','NNMF',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); + [correlationLFnnmf,maxRidgeParamIndexLFnnmf(:,:)]=ridgeCV(savePath,'LF','NNMF',k,ridgeParams,shiftEMG,shiftEEG,eegOffset); fprintf('%s%i finished %s\n',subject,number,datestr(datetime('now'))) save(strcat(pathToFile,sprintf('../matlabData/%s_call%s%i-%s.mat',datestr(datetime('now')),subject,number,name))); end delete(poolObj) - - diff --git a/usedMcode/ridgeCV.m b/usedMcode/ridgeCV.m index 3bcb0f6..f481f03 100644 --- a/usedMcode/ridgeCV.m +++ b/usedMcode/ridgeCV.m @@ -1,15 +1,17 @@ -function [correlation,maxRidgeParamIndex]=ridgeCV(savePath,data,goal,k,ridgeParams,shiftEMG,shiftEEG) +function [correlation,maxRidgeParamIndex]=ridgeCV(savePath,data,goal,k,ridgeParams,shiftEMG,shiftEEG,eegOffset) load(savePath); clear classification; - + eeg=false; if strcmp(data,'EEG') - trainingData=trainingDataEEG; + eeg=true; + trainingData=trainingDataEEG(eegOffset+1:end,:); factor=shiftEEG/shiftEMG; elseif strcmp(data,'EMG') trainingData=trainingDataEMG; factor=1; elseif strcmp(data,'LF') - trainingData=trainingDataEEGlf; + eeg=true; + trainingData=trainingDataEEGlf(eegOffset+1:end,:); factor=shiftEEG/shiftEMG; else error('only EEG, EMG and LF are valid inputs for data'); @@ -34,6 +36,9 @@ clear kinematics; clear synergies*; + if eeg + predicted=predicted(1:end-eegOffset,:); + end correlation=zeros(size(predicted,2),1); maxRidgeParamIndex=zeros(size(predicted,2),k); diff --git a/usedMcode/svmEciton.m b/usedMcode/svmEciton.m index 2293c49..4b98740 100644 --- a/usedMcode/svmEciton.m +++ b/usedMcode/svmEciton.m @@ -1,18 +1,18 @@ -function [meanAccurancy,maxC, cmScaled]= svmEciton(savePath,EEG,k,maxExpC,maxPerClass) +function [meanAccurancy,maxC, cmScaled]= svmEciton(savePath,EEG,k,maxExpC,maxPerClass,eegOffset) load(savePath) % fprintf('%i,%i,%i',size(trainingDataEMG,1),size(trainingDataEEG,1),size(classification,1)) addpath('/nfs/wsi/ti/messor/hohlochj/libsvm/matlab'); %choose to estimate based on EEG or EMG if strcmp(EEG,'EEG') - trainingData=trainingDataEEG; - classification=classificationEEG; + trainingData=trainingDataEEG(1:end-eegOffset,:); + classification=classificationEEG(eegOffset+1:end); elseif strcmp(EEG,'EMG') trainingData=trainingDataEMG; classification=classificationEMG; elseif strcmp(EEG,'LF') - trainingData=trainingDataEEGlf; - classification=classificationEEG; + trainingData=trainingDataEEGlf(1:end-eegOffset,:); + classification=classificationEEG(eegOffset+1:end); else error('only EEG, EMG and LF are valid inputs'); end @@ -22,6 +22,7 @@ clear kinematics; clear synergies*; + accurancy=zeros(k,3); maxC=zeros(k,1); noClasses=size(unique(classification),1);