필터 지우기
필터 지우기

Surface plot using fitrpg

조회 수: 7 (최근 30일)
Tessa Kol
Tessa Kol 2020년 11월 2일
댓글: Mario Malic 2020년 11월 3일
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