function [correlation,viaCorrelation]=ridgeCVvia(savePath,data,via,goal,k,ridgeParams,eegOffset)
    load(savePath);
    clear classification;
    eeg=false;
    if strcmp(data,'EEG')
        eeg=true;
        trainingData=trainingDataEEG(eegOffset+1:end,:);
    elseif strcmp(data,'EMG')
        trainingData=trainingDataEMG;
    elseif strcmp(data,'LF')
        eeg=true;
        trainingData=trainingDataEEGlf(eegOffset+1:end,:);
    else
        error('only EEG, EMG and LF are valid inputs for data');
    end
    
    factor=size(trainingDataEMG,1)/(size(trainingData,1)+eegOffset);


    if strcmp(via,'Autoenc')
        viaData=shiftingMean(synergiesAutoenc,factor);
    elseif strcmp(via,'PCA')
        viaData=shiftingMean(synergiesPCA,factor);
    elseif strcmp(via,'NNMF')
        viaData=shiftingMean(synergiesNNMF,factor);
    else
        error('only Autoenc, PCA nad NNMF are valid inputs for via');
    end
    
        
    if strcmp(goal,'kin')
        predicted=shiftingMean(kinematics,factor);
    elseif strcmp(goal,'EMG')
        predicted=trainingDataEMG;
    else
        error('only kin and EMG are valid inputs for goal');
    end

    clear trainingDataEEG;
    clear trainingDataEEGlf;
    clear trainingDataEMG;
    clear kinematics;
    clear synergies*;

    if eeg
        viaData=viaData(1:end-eegOffset,:);
        predicted=predicted(1:end-eegOffset,:);
    end

    viaDataPredicted=zeros(size(viaData));
    correlation=zeros(size(predicted,2));
    viaCorrelation=zeros(size(predicted,2));

    parfor j=1:size(viaData,2)
        pred=viaData(:,j);
        
        coeffs=ridge(pred,trainingData,ridgeParams(1),0);
        
        viaDataPredicted(:,j)=coeffs(1)+trainingData*coeffs(2:end);
        viaCorrelation(:,j)=diag(corr(viaData(:,j),viaDataPredicted(:,j)));
    end
    
    parfor j=1:size(predicted,2)
        pred=predicted(:,j);
        
        coeffs=ridge(pred,viaDataPredicted,ridgeParams(1),0);
        
        correlation(j)=ridgeCorrelation(viaDataPredicted,pred,coeffs);

    end
end