-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLGP.m
More file actions
27 lines (20 loc) · 701 Bytes
/
Copy pathLGP.m
File metadata and controls
27 lines (20 loc) · 701 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
% linear GP
function [theta_pred,F_model,GP_model] = LGP(X,s,y)
% Train the linear model for the mean using X
linear_model = fitlm(X, y);
% Subtract the linear model predictions from y
y_res = y - predict(linear_model, X);
% Fit Gaussian Process model
gpModel = fitrgp(s, y_res, 'KernelFunction','exponential');
kernelParams = gpModel.KernelInformation.KernelParameters;
lengthScale = kernelParams(1);
signalStd = kernelParams(2);
noiseStd = gpModel.Sigma;
theta_pred = [lengthScale, signalStd, noiseStd];
F_model = linear_model;
GP_model = gpModel;
% Make predictions
y_pred = predict(gpModel, s);
F_pred = predict(linear_model, X);
y_pred_full = y_pred + F_pred;
end