%Performs calibration on  xo2,yo2
%*****************************************************************************************************

%close all;
%clear;

%perform calibration on xo2,yo2 (2)
tic
[trainedModel, validationRMSE] = trainRegressionModelE(xo2, yo2);
partitionedModel = crossval(trainedModel.RegressionGP, 'KFold', 5);
zoe2 = kfoldPredict(partitionedModel);
figure
mdlcal = fitlm(zoe2,yo2); %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')
MDLe2 = mdlcal;
TMe2 = trainedModel;
MARDe2 = 100*mean(abs(yo2-zoe2)./zoe2);
SEPe2 = validationRMSE;
toc

[N M] = size(zoe2);
rn=[1:N];
rn=rn';
figure; plot(rn,yo2,'-ro',rn,zoe2,'-bo')

fncal = "cal_"+ idacq+idses;
save(fncal);
