Use a regressionGP model (from fitrgp()) to predict the gradient with uncertainty
6 views (last 30 days)
Show older comments
I'm working with the Gaussian Process Regression functions in MATLAB to produce a fitted curve to a discrete set of observations: (X,y). I'm able to produce a fit with uncertainties using fitrgp(X,y) to generate a regressionGP object and then [output, uncertainties] = predict(regressionGP) to get the result. However, what I'm really after is the gradient of the fit with its uncertainties. Is there a simple way to compute this using MATLAB?
Thank you for your help.
0 Comments
Answers (1)
Aditya
on 5 Feb 2025
Hi Evan,
To compute the gradient of a Gaussian Process Regression (GPR) fit along with its uncertainties in MATLAB, you can follow these steps:
% Sample data (replace with your actual data)
X = linspace(0, 10, 100)'; % Predictor variable
y = sin(X) + 0.1 * randn(size(X)); % Response variable with noise
% Fit the Gaussian Process Model
regressionGP = fitrgp(X, y);
% Predict the mean and standard deviation
[xGrid, yPred, ySD] = predict(regressionGP, X);
% Compute the gradient of the predicted mean
dy_dx = gradient(yPred, X);
% Compute the gradient of the standard deviation (uncertainty in the gradient)
dSD_dx = gradient(ySD, X);
% Plot the results
figure;
subplot(2, 1, 1);
plot(X, y, 'o', X, yPred, '-');
xlabel('X');
ylabel('Predicted y');
title('Gaussian Process Regression Fit');
legend('Data', 'GPR Fit');
subplot(2, 1, 2);
plot(X, dy_dx, '-');
hold on;
plot(X, dy_dx + dSD_dx, '--', X, dy_dx - dSD_dx, '--');
xlabel('X');
ylabel('Gradient of Predicted y');
title('Gradient and Uncertainty');
legend('Gradient', 'Gradient + Uncertainty', 'Gradient - Uncertainty');
0 Comments
See Also
Categories
Find more on Gaussian Process Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!