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

%close all;
%clear;

%perform calibration on xprd, yprd (2)
tic
[trainedModel, validationRMSE] = trainRegressionModelE(xprd, yprd);
partitionedModel = crossval(trainedModel.RegressionGP, 'KFold', 5);
zprd = kfoldPredict(partitionedModel);
figure
mdlprd = fitlm(zprd,yprd); %returns a linear regression model of the responses y, fit to the data matrix X.
anova(mdlprd,'summary'); %test fit by anova
plot(mdlprd);
title('mdle2 cal')
TMprd = trainedModel;
MARDprd = 100*mean(abs(yprd-zprd)./zprd);
SEPprd = validationRMSE;
toc

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

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