function [correlation,maxRidgeParamIndex]=ridgeCV(savePath,data,goal,k,ridgeParams)
    load(savePath);
    clear classification;
    
    if strcmp(data,'EEG')
        trainingData=trainingDataEEG;
    elseif strcmp(data,'EMG')
        trainingData=trainingDataEMG;
    elseif strcmp(data,'LF')
        trainingData=trainingDataEEGlf;
    else
        error('only EEG, EMG and LF are valid inputs for data');
    end
    
    clear trainingDataEEG;
    clear trainingDataEEGlf;
    clear trainingDataEMG;
    
    if strcmp(goal,'Autoenc')
        predicted=synergiesAutoenc;
    elseif strcmp(goal,'PCA')
        predicted=synergiesPCA;
    elseif strcmp(goal,'NNMF')
        predicted=synergiesNNMF;
    elseif strcmp(goal,'kin')
        predicted=kinematics;
    else
        error('only kin, Autoenc, PCA and NNMF are valid inputs for goal');
    end
    
    clear kinematics;
    clear synergies*;
    
    
    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