1 概述
RBF神经网络结构一般包含输入层、隐含层和神经网络的输出层11。RBF神经网络将复杂的非线性问题转化为高维特征空间,使问题转化为线性可分,避免了局部最小的问题,需要更多的隐层神经元。RBF神经网络结构如图1所示。
2 运行结果
2.1 BP神经网络
2.2 RBF
2.3 PSO-RBF
部分代码:
粒子群算法中的两个参数 c1 = 1.49445; c2 = 1.49445; popcount=10; %粒子数 poplength=6; %粒子维数 Wstart=0.9;%初始惯性权值 Wend=0.2;%迭代次数最大时惯性权值 %个体和速度最大最小值 Vmax=1; Vmin=-1; popmax=4; popmin=-4; %粒子位置速度和最优值初始化 for i=1:popcount pop(i,:)=rand(1,9);%初始化粒子位置 V(i,:)=rand(1,9);%初始化粒子速度 %计算粒子适应度值 Center=pop(i,1:3); SP=pop(i,4:6); W=pop(i,7:9); Distance=dist(Center',SamIn); SPMat=repmat(SP',1,SamNum);%repmat具体作用 UnitOut=radbas(Distance./SPMat);%径向基函数 NetOut=W*UnitOut;%网络输出 Error=SamOut-NetOut;%网络误差 %SSE=sumsqr(Error); %fitness(i)=SSE; RMSE=sqrt(sumsqr(Error)/SamNum); fitness(i)=RMSE; %fitness(i)=fun(pop(i,:)); end %适应度函数(适应度值为RBF网络均方差) [bestfitness bestindex]=min(fitness); gbest=pop(bestindex,:);%全局最优值 pbest=pop;%个体最优值 pbestfitness=fitness;%个体最优适应度值 gbestfitness=bestfitness;%全局最优适应度值 %迭代寻优 for i=1:MaxEpoch Vmax=1.00014^(-i); Vmin=-1.00014^(-i); for j=1:popcount % if (fitness(j)<gbestfitness|fitness==gbestfitness) % S(j)=0; %end %S(j)=1-(fitness(j)/100)^2; % GW(j)=Wstart-S(j)*(Wstart-Wend); % GW(j)=Wend+(GW(j)-Wend)*(MaxEpoch-i)/MaxEpoch; GW=Wstart-(Wstart-Wend)*i/MaxEpoch; %速度更新(第一种方法精度最高) V(j,:) = 1.000009^(-i)*(gbestfitness/fitness(j)+2)*rand*V(j,:) + c1*rand*(pbest(j,:) - pop(j,:)) + c2*rand*(gbest - pop(j,:)); %V(j,:) = GW*((fitness(j)/2000)^2+1)*rand*V(j,:) + c1*rand*(pbest(j,:) - pop(j,:)) + c2*rand*(gbest - pop(j,:)); %V(j,:) = GW*V(j,:) + c1*rand*(pbest(j,:) - pop(j,:)) + c2*rand*(gbest - pop(j,:)); %V(j,:) = 0.9*V(j ,:) + c1*rand*(pbest(j,:) - pop(j,:)) + c2*rand*(gbest - pop(j,:)); %V(j,:) = 0.9*1.0003^(-j)* V(j,:) + c1*rand*(pbest(j,:) - pop(j,:)) + c2*rand*(gbest - pop(j,:)); %V(j,:) = (gbestfitness/(exp(-fitness(j))+1)+0.5)*rand*V(j,:) + c1*rand*(pbest(j,:) - pop(j,:)) + c2*rand*(gbest - pop(j,:)); V(j,find(V(j,:)>Vmax))=Vmax; V(j,find(V(j,:)<Vmin))=Vmin; %粒子更新 pop(j,:)=pop(j,:)+0.5*V(j,:); pop(j,find(pop(j,:)>popmax))=popmax; pop(j,find(pop(j,:)<popmin))=popmin; %计算粒子适应度值 Center=pop(j,1:3); SP=pop(j,4:6); W=pop(j,7:9); Distance=dist(Center',SamIn); SPMat=repmat(SP',1,SamNum);%repmat具体作用 UnitOut=radbas(Distance./SPMat); NetOut=W*UnitOut;%网络输出 Error=SamOut-NetOut;%网络误差 %SSE=sumsqr(Error); %fitness(j)=SSE; RMSE=(sumsqr(Error)/SamNum); fitness(j)=RMSE; % Center=pop(j,1:10); % SP=pop(j,11:20); % W=pop(j,21:30); % fitness(j)=fun(pop(j,:)); end for j=1:popcount %个体最优更新 if fitness(j) < pbestfitness(j) pbest(j,:) = pop(j,:); pbestfitness(j) = fitness(j); end %群体最优更新 if fitness(j) < gbestfitness gbest = pop(j,:); gbestfitness = fitness(j); end end gbesthistory=[gbesthistory,gbest]; %mse(i)=gbestfitness; %将群体最优值赋给RBF参数 Center=gbest(1,1:3); SP=gbest(1,4:6); W=gbest(1,7:9); %Center=gbest(1,1:5); %SP=gbest(1,11:20); % W=gbest(1,21:30); Distance=dist(Center',SamIn); SPMat=repmat(SP',1,SamNum);%repmat具体作用 UnitOut=radbas(Distance./SPMat); NetOut=W*UnitOut;%网络输出 Error=SamOut-NetOut;%网络误差 %sse(i)=sumsqr(Error); mse(i)=(sumsqr(Error)/SamNum); % sse(i)=fun(gbest); %if sse(i)<E0,break,end end toc; % 测试 Center=gbest(1,1:3); SP=gbest(1,4:6); W=gbest(1,7:9); TestDistance=dist(Center',TargetIn); TesatSpreadsMat=repmat(SP',1,TargetSamNum); TestHiddenUnitOut=radbas(TestDistance./TesatSpreadsMat); TestNNOut=W*TestHiddenUnitOut; %作图 分别在训练集和测试集上 subplot(1,2,1) plot(1:length(NetOut),NetOut,'*',1:length(NetOut),SamOut,'o') title('In Train data') subplot(1,2,2) plot(1:3,TestNNOut,'*',1:3,TargetOut,'o') title('In Test data') %求出误差 训练集和测试集 train_error=sum(abs(SamOut-NetOut))/length(SamOut); test_error=sum(abs(TargetOut-TestNNOut))/length(TargetOut);
3 参考文献
[1]王媛媛.基于改进PSO优化RBF神经网络的温室温度预测研究[J].计算机与数字工程,2016,44(07):1210-1215.
[2]向昭君. 群智能算法优化RBF神经网络的研究与应用[D].兰州大学,2016.DOI:10.27204/d.cnki.glzhu.2016.000078.