clc
load('my_GPR')
RegObj = obj_TrainedSet1.RegressionGP;
SigmaL = RegObj.KernelInformation.KernelParameters(1);
SigmaF = RegObj.KernelInformation.KernelParameters(2);
Sigma = RegObj.Sigma;
Alpha = RegObj.Alpha;
Xraw = table2array(RegObj.X);
Yraw = RegObj.Y;
offsetX = RegObj.PredictorLocation';
scaleX = RegObj.PredictorScale';
offsetY = RegObj.Beta;
X = repmat(scaleX,size(Xraw,1),1).\(Xraw - offsetX);
Y = Yraw - offsetY;
dist = @ (x1,x2) sqrt(sum((x1-x2).*(x1-x2),2));
matern52 = @(x1,x2) SigmaF^2*(1+ sqrt(5)*dist(x1,x2)/SigmaL + 5*dist(x1,x2).^2/(3*SigmaL^2)).*exp(-sqrt(5)*dist(x1,x2)/SigmaL);
K = [];
for i=1:size(X,1)
K(:,i) = matern52(X(i,:),X);
end
Alpha_reconstructed = (K + Sigma^2*eye(size(X,1)))\Y;
norm(Alpha-Alpha_reconstructed);
for i=1:size(X,1)
pred_test(i) = matern52(X(i,:),X)'*Alpha;
end
x_new_raw = rand(1,3);
x_new = scaleX.*(x_new_raw - offsetX);
x_new = scaleX.\(rand_Input - offsetX);
mean_prediction = matern52(x_new,X)'*Alpha + offsetY;
var_prediction = matern52(x_new,x_new) + matern52(x_new,X)'*((K + Sigma*eye(size(X,1)))\matern52(x_new,X));
Best Answer