基于OLS 的RBF 网设计算法
SamNum = 100; % 训练样本数TestSamNum = 101; % 测试样本数
SP = 0.6; % 隐节点扩展常数
ErrorLimit = 0.9; % 目标误差
% 根据目标函数获得样本输入输出
rand('state',sum(100*clock))
NoiseVar = 0.1;
Noise = NoiseVar*randn(1,SamNum);
SamIn = 8*rand(1,SamNum)-4;
SamOutNoNoise = 1.1*(1-SamIn+2*SamIn.^2).*exp(-SamIn.^2/2);
SamOut = SamOutNoNoise + Noise;
TestSamIn = -4:0.08:4;
TestSamOut = 1.1*(1-TestSamIn+2*TestSamIn.^2).*exp(-TestSamIn.^2/2);
figure
hold on
grid
plot(SamIn,SamOut,'k+')
plot(TestSamIn,TestSamOut,'k--')
xlabel('Input x');
ylabel('Output y');
= size(SamIn); % 样本输入维数和最大允许隐节点数
% 计算隐节点输出阵
Distance = dist(SamIn',SamIn);
HiddenUnitOut = radbas(Distance/SP);
PosSelected = [];
VectorsSelected = [];
HiddenUnitOutSelected = [];
ErrHistory = []; % 用于记录每次增加隐节点后的训练误差
VectorsSelectFrom = HiddenUnitOut;
dd = sum((SamOut.*SamOut)')';
for k = 1 : MaxUnitNum
% 计算各隐节点输出矢量与目标输出矢量的夹角平方值
PP = sum(VectorsSelectFrom.*VectorsSelectFrom)';
Denominator = dd * PP';
= size(PosSelected);
if SelectedNum>0,
= size(Denominator);
Denominator(:,PosSelected) = ones(lin,1);
end
Angle = ((SamOut*VectorsSelectFrom) .^ 2) ./ Denominator;
% 选择具有最大投影的矢量,得到相应的数据中心
= max(Angle);
PosSelected = ;
% 计算RBF 网训练误差
HiddenUnitOutSelected = ;
HiddenUnitOutEx = ;
W2Ex = SamOut*pinv(HiddenUnitOutEx); % 用广义逆求广义输出权值
W2 = W2Ex(:,1:k); % 得到输出权值
B2 = W2Ex(:,k+1); % 得到偏移
NNOut = W2*HiddenUnitOutSelected+B2; % 计算RBF 网输出
SSE = sumsqr(SamOut-NNOut)
% 记录每次增加隐节点后的训练误差
ErrHistory = ;
if SSE < ErrorLimit, break, end
% 作Gram-Schmidt 正交化
NewVector = VectorsSelectFrom(:,pos);
ProjectionLen = NewVector' * VectorsSelectFrom / (NewVector'*NewVector);
VectorsSelectFrom = VectorsSelectFrom - NewVector * ProjectionLen;
end
UnitCenters = SamIn(PosSelected);%%%%%%%%%%%
% 测试
TestDistance = dist(UnitCenters',TestSamIn);%%%%%%%%
TestHiddenUnitOut = radbas(TestDistance/SP);
TestNNOut = W2*TestHiddenUnitOut+B2;
plot(TestSamIn,TestNNOut,'k-')
k
UnitCenters
W2
B2
运行出错!
HiddenUnitOutEx = ;Error in ==> jiyuolsderbf at 46
HiddenUnitOutEx = ;
麻烦楼主看看!
楼上的朋友,你的程序有点小错
楼上的朋友,你的程序有点小错,HiddenUnitOutSelected = ;在这句话里HiddenUnitOut(pos,]是不是写的不全?麻烦你看看,是不是忘了写什么东西?谢谢 加上 :) 就可以了吧! :handshake
页:
[1]