addpath('/home/hohlochj/masterarbeitNew/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=4;
allSubjects=false; %run all subjects and days or only one random day for one random subject
windowEMG=0.2;
windowEEG=1;
shift=0.05;
pburgOrder=50;
minEEGFreq=0;
maxEEGFreq=200;
pause=false;
noLFsamples=5;
ridgeParams=[10];
k=10;
maxExpC=0;
maxPerClass=250;
EEG=true;
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;
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,shift,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);
[correlationEEGkin(j,:),maxRidgeParamIndexEEGkin(j,:,:)]=ridgeCV(savePath,'EEG','kin',k,ridgeParams);
[correlationLFkin(j,:),maxRidgeParamIndexLFkin(j,:,:)]=ridgeCV(savePath,'LF','kin',k,ridgeParams);
[correlationEMGautoenc(j,:),maxRidgeParamIndexEMGautoenc(j,:,:)]=ridgeCV(savePath,'EMG','Autoenc',k,ridgeParams);
[correlationEEGautoenc(j,:),maxRidgeParamIndexEEGautoenc(j,:,:)]=ridgeCV(savePath,'EEG','Autoenc',k,ridgeParams);
[correlationLFautoenc(j,:),maxRidgeParamIndexLFautoenc(j,:,:)]=ridgeCV(savePath,'LF','Autoenc',k,ridgeParams);
[correlationEMGpca(j,:),maxRidgeParamIndexEMGpca(j,:,:)]=ridgeCV(savePath,'EMG','PCA',k,ridgeParams);
[correlationEEGpca(j,:),maxRidgeParamIndexEEGpca(j,:,:)]=ridgeCV(savePath,'EEG','PCA',k,ridgeParams);
[correlationLFpca(j,:),maxRidgeParamIndexLFpca(j,:,:)]=ridgeCV(savePath,'LF','PCA',k,ridgeParams);
[correlationEMGnnmf(j,:),maxRidgeParamIndexEMGnnmf(j,:,:)]=ridgeCV(savePath,'EMG','NNMF',k,ridgeParams);
[correlationEEGnnmf(j,:),maxRidgeParamIndexEEGnnmf(j,:,:)]=ridgeCV(savePath,'EEG','NNMF',k,ridgeParams);
[correlationLFnnmf(j,:),maxRidgeParamIndexLFnnmf(j,:,:)]=ridgeCV(savePath,'LF','NNMF',k,ridgeParams);
fprintf('%s%i finished %s\n',subject,number,datestr(datetime('now')))
end
save(strcat(pathToFile,sprintf('../matlabData/%s_callAll.mat',datestr(datetime('now')))));
else
j=fix(rand()*size(numbersMat,2)+1);
number=numbersMat(j);
subject=subjectsForNumbers{j};
savePath=readAll(pathToFile,subject,number,windowEMG,windowEEG,shift,maxFile,threshold,pburgOrder,minEEGFreq,maxEEGFreq,pause,noLFsamples,EMGChannels,noSynergiesergies);
[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);
[correlationEEGkin,maxRidgeParamIndexEEGkin(:,:)]=ridgeCV(savePath,'EEG','kin',k,ridgeParams);
[correlationLFkin,maxRidgeParamIndexLFkin(:,:)]=ridgeCV(savePath,'LF','kin',k,ridgeParams);
[correlationEMGautoenc,maxRidgeParamIndexEMGautoenc(:,:)]=ridgeCV(savePath,'EMG','Autoenc',k,ridgeParams);
[correlationEEGautoenc,maxRidgeParamIndexEEGautoenc(:,:)]=ridgeCV(savePath,'EEG','Autoenc',k,ridgeParams);
[correlationLFautoenc,maxRidgeParamIndexLFautoenc(:,:)]=ridgeCV(savePath,'LF','Autoenc',k,ridgeParams);
[correlationEMGpca,maxRidgeParamIndexEMGpca(:,:)]=ridgeCV(savePath,'EMG','PCA',k,ridgeParams);
[correlationEEGpca,maxRidgeParamIndexEEGpca(:,:)]=ridgeCV(savePath,'EEG','PCA',k,ridgeParams);
[correlationLFpca,maxRidgeParamIndexLFpca(:,:)]=ridgeCV(savePath,'LF','PCA',k,ridgeParams);
[correlationEMGnnmf,maxRidgeParamIndexEMGnnmf(:,:)]=ridgeCV(savePath,'EMG','NNMF',k,ridgeParams);
[correlationEEGnnmf,maxRidgeParamIndexEEGnnmf(:,:)]=ridgeCV(savePath,'EEG','NNMF',k,ridgeParams);
[correlationLFnnmf,maxRidgeParamIndexLFnnmf(:,:)]=ridgeCV(savePath,'LF','NNMF',k,ridgeParams);
fprintf('%s%i finished %s\n',subject,number,datestr(datetime('now')))
save(strcat(pathToFile,sprintf('../matlabData/%s_call%s%i.mat',datestr(datetime('now')),subject,number)));
end
delete(poolObj)