function [correlation,maxRidgeParamIndex]=ridgeCV(savePath,data,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,:);
    elseif strcmp(data,'Autoenc')
        trainingData=synergiesAutoenc;
    else
        error('only EEG, EMG and LF are valid inputs for data');
    end
    
    factor=size(trainingDataEMG,1)/(size(trainingData,1)+eegOffset);


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

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

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

    correlation=zeros(size(predicted,2),1);
    maxRidgeParamIndex=zeros(size(predicted,2),k);

    for j=1:size(predicted,2)
        randMap=randperm(size(trainingData,1));
        pred=predicted(:,j);
        correlations=zeros([k,1]);

        for i=1:k
            leaveData=trainingData(mod(randMap,k)==i-1,:);
            leavePerd=pred(mod(randMap,k)==i-1);
            remainingData=trainingData(mod(randMap,k)~=i-1,:);
            remainingPred=pred(mod(randMap,k)~=i-1);

            [coeffs,maxRidgeParamIndex(j,i)]=kFoldRidge(remainingData,remainingPred,k,ridgeParams);

            correlations(i)=ridgeCorrelation(leaveData,leavePerd,coeffs);
        end

        correlation(j)=mean(correlations);
    end
end
