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

close all;
clear;
load('dat_d1r0c0s0119cdc');

%perform calibration on xcal,ycal (2)
tic
[trainedModel, validationRMSE] = trainRegressionModelSEGPR(xcaln, ycal);
partitionedModel = crossval(trainedModel.RegressionGP, 'KFold', 5);
zcal = kfoldPredict(partitionedModel);
figure
mdlcal = fitlm(zcal,ycal); %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')
TMcal = 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')

save('cal_d1r0c0s0119cdc');
