Surface plot using fitrpg
8 ビュー (過去 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')
0 件のコメント
採用された回答
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 件のコメント
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 Center および File Exchange で Gaussian Process Regression についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!