📄 testcross2d.m
字号:
clear;
% test for LWPR on 2D data set
n = 5000;
% a random training set using the CROSS function
X = (rand(n,2)-.5)*2;
Y = max([exp(-X(:,1).^2 * 10),exp(-X(:,2).^2 * 50),1.25*exp(-(X(:,1).^2+X(:,2).^2)*5)]');
Y = Y' + randn(n,1)*0.1;
% a systematic test set on a grid
Xt = [];
for i=-1:0.05:1,
for j=-1:0.05:1,
Xt = [Xt; i j];
end
end
Yt = max([exp(-Xt(:,1).^2 * 10),exp(-Xt(:,2).^2 * 50),1.25*exp(-(Xt(:,1).^2+Xt(:,2).^2)*5)]');
Yt = Yt';
N = size(X,1);
nXdim = size(X,2);
nYdim = size(Y,2);
q = 20;
knn = 1;
freezeW = 40;
x_quantize = 0.01;
y_quantize = 0.1;
disp('Train by using the sample set');
tid = createIHDRT(nXdim,nYdim,q,knn,freezeW,x_quantize,y_quantize);
for i=1:size(X,1)
ret = addPatternIHDRT(tid, X(i,:), Y(i,:));
end
disp('Test using the test set');
mse = 0;
for i=1:size(Xt,1)
%[ret, Xout, Yout, dist] = RetrieveIHDRT(tid, Xt(i,:));
%[ret,Yo1, Yo2]=regressionIHDRT2(tid,Xt(i,:),1, 1, 'knn',20, 'lambda', 0.01);
[ret,Yout]=regressionIHDRT(tid,Xt(i,:),'knn',40, 'lambda', 0.1);
%Yout=Yo1+Yo2;
error(i) = (Yout - Yt(i))^2;
mse = mse + (Yout - Yt(i))^2;
Yp(i) = Yout;
end
Yp = Yp';
mse = mse/size(Xt,1)
%nmse =sqrt(mse/size(Xt,1)); %normalized mean square error
fprintf(1,'The fitted function: MSE=%5.3f',mse);
figure(1);
clf;
% plot the fitted surface
axis([-1 1 -1 1 -.5 1.5]);
subplot(2,1,1);
[x,y,z]=makesurf([Xt,Yp],sqrt(length(Xt)));
surfl(x,y,z);
axis([-1 1 -1 1 -.5 1.5]);
title(sprintf('The fitted function: MSE=%5.3f',mse));
% plot the true surface
subplot(2,1,2);
[x,y,z]=makesurf([Xt,Yt],sqrt(length(Xt)));
surfl(x,y,z);
axis([-1 1 -1 1 -.5 1.5]);
title('The true function');
closeIHDRT(tid);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -