rbfninterpolation.m
来自「THE ZIP FILE CONTAINS ALL THE PROGRAMS O」· M 代码 · 共 85 行
M
85 行
% ==========================================================
%
% Neural Networks A Classroom Approach
% Satish Kumar
% Copyright Tata McGraw Hill, 2004
%
% MATLAB code that implements RBFN regularized interpolation
% Reference: Table 8.11;Page 322
%
% ==========================================================
testpts = 100;
testx = linspace(-2*pi, 2*pi, testpts);
testy = 2*sin(testx) + testx;
Q = 10;
noise = 0.6;
sigma = 0.6;
x = linspace(-2*pi,2*pi,Q);
scatter = (2*rand(1,Q) - 1)*noise;
d = 2*sin(x) + scatter + x ;
lambda = 0;
for i = 1:Q
for j = 1:Q
phi(i,j) = exp(-(x(i)-x(j))^2/(2*sigma^2));
end
end
Wreg = inv(phi + (lambda * eye(Q))) * d';
for k = 1:testpts
for i = 1:Q
phitest(k,i) = exp(-(testx(k)-x(i))^2/(2*sigma^2));
phislope(k,i) = -exp(-(testx(k)-x(i))^2/(2*sigma^2)) * (testx(k)-x(i));
end
f(k) = phitest(k,:)*Wreg;
slope(k) = (phislope(k,:)*Wreg/sigma^2)^2;
end
figure(1)
subplot(2,2,1)
hold on
plot(testx, testy,'b')
plot(x, d, 'r^');
plot(testx, f, 'k','LineWidth',2);
axis([-2*pi 2*pi -7 7]);
grid on
title('(a)');
subplot(2,2,3)
hold on
plot(testx, slope, 'r','LineWidth',2);
area(testx, slope);
axis([-2*pi 2*pi 0 35]);
grid on
title('(c)');
lambda = 0.5;
W_reg = inv(phi + (lambda * eye(Q))) * d';
for k=1:testpts
f(k) = phitest(k,:)*W_reg;
slope(k) = (phislope(k,:)*W_reg/sigma^2)^2;
end
subplot(2,2,2)
hold on
plot(testx, testy,'b')
plot(x, d, 'r^');
plot(testx, f, 'k','LineWidth',2);
axis([-2*pi 2*pi -7 7]);
grid on
title('(b)');
subplot(2,2,4)
hold on
plot(testx, slope, 'r','LineWidth',2);
area(testx, slope);
axis([-2*pi 2*pi 0 35]);
grid on
title('(d)');
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?