%Performs calibration on  xcal(n),ycal
%*****************************************************************************************************

%xcal=xcal1;
%ycal=ycal1;
%xcal=xcal2;
%ycal=ycal2;
xcal=xcal3;
ycal=ycal3;

tic
[trainedModel, validationRMSE] = trainRegressionModelEGPR64(xcal, ycal);
partitionedModel = crossval(trainedModel.RegressionGP, 'KFold', 5);
zcal = kfoldPredict(partitionedModel);
figure
mdlcal = fitlm(ycal,zcal); %returns a linear regression model of the responses y, fit to the data matrix X.
anova(mdlcal,'summary'); %test fit by anova
plot(mdlcal)
title('mdle2 cal')

TMcal64 = trainedModel;
MARDcal = 100*mean(abs(ycal-zcal)./zcal); 
SEPcal = validationRMSE;
toc

[N M] = size(zcal);
rn=[1:N];
rn=rn';
figure; plot(rn,ycal,'-ro',rn,zcal,'-bo');title('Validation'); xlabel('Record Number]'); ylabel('Concentration [mg/dL]');
legend('Reference', 'Predicted');

save('cal_d1r0c0sUnivPDS_EGPR64');
