Surface plot using fitrpg

10 次查看(过去 30 天)
Dear all,
I tried to make a surface plot of the gaussian process function with the following code:
gprMdl = fitrgp(X,Y1,'KernelFunction','squaredexponential','OptimizeHyperparameters','auto','HyperparameterOptimizationOptions',struct('AcquisitionFunctionName','expected-improvement-plus'));
ypred = predict(gprMdl,X);
[X1,X2] = meshgrid(0.1:0.1:0.9,0.1:0.1:0.9);
surf(X1,X2,reshape(ypred,9,9));
hold on
plot3(X(:,1),X(:,2),Y1,'.r','DisplayName','Observations')
Where the result is presented below.
However, I would expect something more like this. Because the surface plot I have now doesn't fit the data properly and the contour lines are widespread. What am I doing wrong here?
I also tried the following with the help of another post (https://nl.mathworks.com/matlabcentral/answers/407736-plot-3d-hyperplane-from-fitcsvm-results#answer_326570)
But this doens't seem sufficient either.
[x,y]=meshgrid(0.1:0.01:0.9,0.1:0.01:0.9);
xGrid = [x(:),y(:)];
gprMdl = fitrgp(X,Y1,'KernelFunction','squaredexponential','OptimizeHyperparameters','auto','HyperparameterOptimizationOptions',struct('AcquisitionFunctionName','expected-improvement-plus'));
[~,f]=predict(gprMdl2,xGrid);
f=reshape(f(:,1),size(x));
figure
surf(x,y,f)
hold on
plot3(X(:,1),X(:,2),Y1,'.r','DisplayName','Observations')

采纳的回答

Mario Malic
Mario Malic 2020-11-3
Hello,
Take a look at the code below, unfortunately I can't find the link where I found an example I took the code from, but look for scatteredInterpolant function. I am not sure whether this is applicable, so, please verify.
clc;
clear;
close all;
load data.mat
gprMdl = fitrgp(X,Y1,'KernelFunction','squaredexponential','OptimizeHyperparameters','auto','HyperparameterOptimizationOptions',struct('AcquisitionFunctionName','expected-improvement-plus'));
ypred = predict(gprMdl,X);
% so I don't write indexes below
x_data = X(:,1);
y_data = X(:,2);
% Getting the 2d grid
Num_Points = 50;
X_Lin = linspace(min(x_data),max(x_data),Num_Points);
Y_Lin = linspace(min(y_data),max(y_data),Num_Points);
[X,Y] = meshgrid(X_Lin,Y_Lin);
% Interpolating the surface from ypred
f = scatteredInterpolant(x_data, y_data, ypred);
Z = f(X,Y);
surf(X,Y,Z);
% plotting the observed points
hold on;
plot3(x_data,y_data, Y1,'.r','DisplayName','Observations');
  4 个评论
Tessa Kol
Tessa Kol 2020-11-3
I tried that function, but it gives errors saying: "The sample points arrays must have the same size
as the sample values array."
Mario Malic
Mario Malic 2020-11-3
I am not completely sure whether it's possible to do the griddedInterpolation as you need values for your objective function across the grid. Let's say your grid is 50x50, you would need values for your objective function at each grid point. Maybe you could use the scatteredInterpolation to get grid values and interpolated values for obj. fun., but I don't know if this is a silly thing to do.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Gaussian Process Regression 的更多信息

产品


版本

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by