addpath('/home/hohlochj/masterarbeit/usedMcode')
pathToFile='/nfs/wsi/ti/messor/hohlochj/origData/';
%pathToFile='/home/jph/Uni/masterarbeit/origData/';
maxFile=5;
threshold=10000; %EMG is classified as movement
EMGChannels={'AbdPolLo','Biceps','Triceps','FrontDelt','MidDelt','BackDelt'};
noSynergies=3;
allSubjects=false; %run all subjects and days or only one random day for one random subject
name='default3SynTest'; %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=0; %predict actions x*shiftEEG after EEG measurement
pburgOrder=50;
minEEGFreq=0;
maxEEGFreq=200;
pause=false;
noLFsamples=5;
ridgeParams=100;
k=10;
maxExpC=0;
maxPerClass=250;
poolObj=parpool(32);
[subjects,numbers]=namesAndNumbers(pathToFile);
numbersMat=cell2mat(numbers);
subjectsForNumbers=cell(size(numbersMat,2),1);
j=1;
for i=1:size(subjects,2)
subject=subjects{i};
for number=numbers{i}
subjectsForNumbers{j}=subject;
j=j+1;
end
end
j=j-1; %number of trial-days for all subjects
if allSubjects
meanAccurancysEMG=zeros([j,1]);
meanAccurancysEEG=zeros([j,1]);
meanAccurancysLF=zeros([j,1]);
maxCEMG=zeros([j,k,1]);
maxCEEG=zeros([j,k,1]);
maxCLF=zeros([j,k,1]);
cmScaledEMG=zeros([j,5,5]);
cmScaledEEG=zeros([j,5,5]);
cmScaledLF=zeros([j,5,5]);
maxRidgeParamIndexEEGkin=zeros([j,3,k]);
maxRidgeParamIndexEMGkin=zeros([j,3,k]);
maxRidgeParamIndexLFkin=zeros([j,3,k]);
correlationEMGkin=zeros([j,3]); %x,y,angle
correlationEEGkin=zeros([j,3]);
correlationLFkin=zeros([j,3]);
maxRidgeParamIndexEEGautoenc=zeros([j,noSynergies,k]);
maxRidgeParamIndexEMGautoenc=zeros([j,noSynergies,k]);
maxRidgeParamIndexLFautoenc=zeros([j,noSynergies,k]);
correlationEMGautoenc=zeros([j,noSynergies]);
correlationEEGautoenc=zeros([j,noSynergies]);
correlationLFautoenc=zeros([j,noSynergies]);
maxRidgeParamIndexEEGpca=zeros([j,noSynergies,k]);
maxRidgeParamIndexEMGpca=zeros([j,noSynergies,k]);
maxRidgeParamIndexLFpca=zeros([j,noSynergies,k]);
correlationEMGpca=zeros([j,noSynergies]);
correlationEEGpca=zeros([j,noSynergies]);
correlationLFpca=zeros([j,noSynergies]);
maxRidgeParamIndexEEGnnmf=zeros([j,noSynergies,k]);
maxRidgeParamIndexEMGnnmf=zeros([j,noSynergies,k]);
maxRidgeParamIndexLFnnmf=zeros([j,noSynergies,k]);
correlationEMGnnmf=zeros([j,noSynergies]);
correlationEEGnnmf=zeros([j,noSynergies]);
correlationLFnnmf=zeros([j,noSynergies]);
parfor j=1:size(numbersMat,2)
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,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,eegOffset);
[correlationEEGkin(j,:),maxRidgeParamIndexEEGkin(j,:,:)]=ridgeCV(savePath,'EEG','kin',k,ridgeParams,eegOffset);
[correlationLFkin(j,:),maxRidgeParamIndexLFkin(j,:,:)]=ridgeCV(savePath,'LF','kin',k,ridgeParams,eegOffset);
[correlationEMGautoenc(j,:),maxRidgeParamIndexEMGautoenc(j,:,:)]=ridgeCV(savePath,'EMG','Autoenc',k,ridgeParams,eegOffset);
[correlationEEGautoenc(j,:),maxRidgeParamIndexEEGautoenc(j,:,:)]=ridgeCV(savePath,'EEG','Autoenc',k,ridgeParams,eegOffset);
[correlationLFautoenc(j,:),maxRidgeParamIndexLFautoenc(j,:,:)]=ridgeCV(savePath,'LF','Autoenc',k,ridgeParams,eegOffset);
[correlationEMGpca(j,:),maxRidgeParamIndexEMGpca(j,:,:)]=ridgeCV(savePath,'EMG','PCA',k,ridgeParams,eegOffset);
[correlationEEGpca(j,:),maxRidgeParamIndexEEGpca(j,:,:)]=ridgeCV(savePath,'EEG','PCA',k,ridgeParams,eegOffset);
[correlationLFpca(j,:),maxRidgeParamIndexLFpca(j,:,:)]=ridgeCV(savePath,'LF','PCA',k,ridgeParams,eegOffset);
[correlationEMGnnmf(j,:),maxRidgeParamIndexEMGnnmf(j,:,:)]=ridgeCV(savePath,'EMG','NNMF',k,ridgeParams,eegOffset);
[correlationEEGnnmf(j,:),maxRidgeParamIndexEEGnnmf(j,:,:)]=ridgeCV(savePath,'EEG','NNMF',k,ridgeParams,eegOffset);
[correlationLFnnmf(j,:),maxRidgeParamIndexLFnnmf(j,:,:)]=ridgeCV(savePath,'LF','NNMF',k,ridgeParams,eegOffset);
fprintf('%s%i finished %s\n',subject,number,datestr(datetime('now')))
end
save(strcat(pathToFile,sprintf('../matlabData/%s_callAll-%s.mat',datestr(datetime('now')),name)));
else
meanAccurancysEMG=zeros([1]);
meanAccurancysEEG=zeros([1]);
meanAccurancysLF=zeros([1]);
maxCEMG=zeros([k,1]);
maxCEEG=zeros([k,1]);
maxCLF=zeros([k,1]);
cmScaledEMG=zeros([5,5]);
cmScaledEEG=zeros([5,5]);
cmScaledLF=zeros([5,5]);
maxRidgeParamIndexEEGkin=zeros([3,k]);
maxRidgeParamIndexEMGkin=zeros([3,k]);
maxRidgeParamIndexLFkin=zeros([3,k]);
correlationEMGkin=zeros([3]); %x,y,angle
correlationEEGkin=zeros([3]);
correlationLFkin=zeros([3]);
maxRidgeParamIndexEEGautoenc=zeros([noSynergies,k]);
maxRidgeParamIndexEMGautoenc=zeros([noSynergies,k]);
maxRidgeParamIndexLFautoenc=zeros([noSynergies,k]);
correlationEMGautoenc=zeros([noSynergies]);
correlationEEGautoenc=zeros([noSynergies]);
correlationLFautoenc=zeros([noSynergies]);
maxRidgeParamIndexEEGpca=zeros([noSynergies,k]);
maxRidgeParamIndexEMGpca=zeros([noSynergies,k]);
maxRidgeParamIndexLFpca=zeros([noSynergies,k]);
correlationEMGpca=zeros([noSynergies]);
correlationEEGpca=zeros([noSynergies]);
correlationLFpca=zeros([noSynergies]);
maxRidgeParamIndexEEGnnmf=zeros([noSynergies,k]);
maxRidgeParamIndexEMGnnmf=zeros([noSynergies,k]);
maxRidgeParamIndexLFnnmf=zeros([noSynergies,k]);
correlationEMGnnmf=zeros([noSynergies]);
correlationEEGnnmf=zeros([noSynergies]);
correlationLFnnmf=zeros([noSynergies]);
j=fix(rand()*size(numbersMat,2)+1);
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,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,eegOffset);
[correlationEEGkin,maxRidgeParamIndexEEGkin(:,:)]=ridgeCV(savePath,'EEG','kin',k,ridgeParams,eegOffset);
[correlationLFkin,maxRidgeParamIndexLFkin(:,:)]=ridgeCV(savePath,'LF','kin',k,ridgeParams,eegOffset);
[correlationEMGautoenc,maxRidgeParamIndexEMGautoenc(:,:)]=ridgeCV(savePath,'EMG','Autoenc',k,ridgeParams,eegOffset);
[correlationEEGautoenc,maxRidgeParamIndexEEGautoenc(:,:)]=ridgeCV(savePath,'EEG','Autoenc',k,ridgeParams,eegOffset);
[correlationLFautoenc,maxRidgeParamIndexLFautoenc(:,:)]=ridgeCV(savePath,'LF','Autoenc',k,ridgeParams,eegOffset);
[correlationEMGpca,maxRidgeParamIndexEMGpca(:,:)]=ridgeCV(savePath,'EMG','PCA',k,ridgeParams,eegOffset);
[correlationEEGpca,maxRidgeParamIndexEEGpca(:,:)]=ridgeCV(savePath,'EEG','PCA',k,ridgeParams,eegOffset);
[correlationLFpca,maxRidgeParamIndexLFpca(:,:)]=ridgeCV(savePath,'LF','PCA',k,ridgeParams,eegOffset);
[correlationEMGnnmf,maxRidgeParamIndexEMGnnmf(:,:)]=ridgeCV(savePath,'EMG','NNMF',k,ridgeParams,eegOffset);
[correlationEEGnnmf,maxRidgeParamIndexEEGnnmf(:,:)]=ridgeCV(savePath,'EEG','NNMF',k,ridgeParams,eegOffset);
[correlationLFnnmf,maxRidgeParamIndexLFnnmf(:,:)]=ridgeCV(savePath,'LF','NNMF',k,ridgeParams,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)