本文主要是介绍遗传算法(GA)优化后RBF神经网络优化分析(Matlab代码实现),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
1 遗传算法
2 RBF神经网络
3 Matlab代码实现
4 结果
1 遗传算法
*智能优化算法(持续更新中......)
2 RBF神经网络
RBF神将网络是一种三层神经网络,其包括输入层、隐层、输出层。从输入空间到隐层空间的变换是非线性的,而从隐层空间到输出层空间变换是线性的。流图如下:
RBF网络的基本思想是:用RBF作为隐单元的“基”构成隐含层空间,这样就可以将输入矢量直接映射到隐空间,而不需要通过权连接。当RBF的中心点确定以后,这种映射关系也就确定了。而隐含层空间到输出空间的映射是线性的,即网络的输出是隐单元输出的线性加权和,此处的权即为网络可调参数。其中,隐含层的作用是把向量从低维度的p映射到高维度的h,这样低维度线性不可分的情况到高维度就可以变得线性可分了,主要就是核函数的思想。
这样,网络由输入到输出的映射是非线性的,而网络输出对可调参数而言却又是线性的。网络的权就可由线性方程组直接解出,从而大大加快学习速度并避免局部极小问题。
3 Matlab代码实现
GA.m
clear all
close allG = 15;
Size = 30;
CodeL = 10;for i = 1:3MinX(i) = 0.1*ones(1);MaxX(i) = 3*ones(1);
end
for i = 4:1:9MinX(i) = -3*ones(1);MaxX(i) = 3*ones(1);
end
for i = 10:1:12MinX(i) = -ones(1);MaxX(i) = ones(1);
endE = round(rand(Size,12*CodeL)); %Initial Code!BsJ = 0;for kg = 1:1:Gtime(kg) = kgfor s = 1:1:Sizem = E(s,:);for j = 1:1:12y(j) = 0;mj = m((j-1)*CodeL + 1:1:j*CodeL);for i = 1:1:CodeLy(j) = y(j) + mj(i)*2^(i-1);endf(s,j) = (MaxX(j) - MinX(j))*y(j)/1023 + MinX(j);end% ************Step 1:Evaluate BestJ *******************p = f(s,:);[p,BsJ] = RBF(p,BsJ);BsJi(s) = BsJ;end[OderJi,IndexJi] = sort(BsJi);BestJ(kg) = OderJi(1);BJ = BestJ(kg);Ji = BsJi+1e-10;fi = 1./Ji;[Oderfi,Indexfi] = sort(fi);Bestfi = Oderfi(Size);BestS = E(Indexfi(Size),:);% ***************Step 2:Select and Reproduct Operation*********fi_sum = sum(fi);fi_Size = (Oderfi/fi_sum)*Size;fi_S = floor(fi_Size);kk = 1;for i = 1:1:Sizefor j = 1:1:fi_S(i)TempE(kk,:) = E(Indexfi(i),:);kk = kk + 1;endend% ****************Step 3:Crossover Operation*******************pc = 0.60;n = ceil(20*rand);for i = 1:2:(Size - 1)temp = rand;if pc>tempfor j = n:1:20TempE(i,j) = E(i+1,j);TempE(i+1,j) = E(i,j);endendendTempE(Size,:) = BestS;E = TempE;%*****************Step 4:Mutation Operation*********************pm = 0.001 - [1:1:Size]*(0.001)/Size;for i = 1:1:Sizefor j = 1:1:12*CodeLtemp = rand;if pm>tempif TempE(i,j) == 0TempE(i,j) = 1;elseTempE(i,j) = 0;endendendend%Guarantee TempE(Size,:) belong to the best individualTempE(Size,:) = BestS;E = TempE;%********************************************************************endBestfiBestSfiBest_J = BestJ(G)figure(1);plot(time,BestJ);xlabel('Times');ylabel('BestJ');save pfile p;
RBF.m
Test.m
clear all;
close all;load pfile;
alfa = 0.05;
xite = 0.85;
x = [0,0]';%M为1时
M = 2;
if M == 1b = [p(1);p(2);p(3)];c = [p(4) p(5) p(6);p(7) p(8) p(9)];w = [p(10);p(11);p(12)];
elseif M == 2b = 3*rand(3,1);c = 3*rands(2,3);w = rands(3,1);
endw_1 = w;w_2 = w_1;
c_1 = c;c_2 = c_1;
b_1 = b;b_2 = b_1;y_1 = 0;ts = 0.001;
for k = 1:1500time(k) = k*ts;u(k) = sin(5*2*pi*k*ts);y(k) = u(k)^3 + y_1/(1 + y_1^2);x(1) = u(k);x(2) = y(k);for j = 1:3h(j) = exp(-norm(x-c(:,j))^2/(2*b(j)*b(j)));endym(k) = w_1'*h';e(k) = y(k) - ym(k);d_w = 0*w;d_b = 0*b;d_c=0*c;for j = 1:1:3d_w(j) = xite*e(k)*h(j);d_b(j) = xite*e(k)*w(j)*h(j)*(b(j)^-3)*norm(x-c(:,j))^2;for i = 1:1:2d_c(i,j) = xite*e(k)*w(j)*h(j)*(x(i) - c(i,j))*(b(j)^-2);endendw = w_1 + d_w + alfa*(w_1 - w_2);b = b_1 + d_b + alfa*(b_1 - b_2);c = c_1 + d_c + alfa*(c_1 - c_2);y_1 = y(k);w_2 = w_1;w_1 = w;c_2 = c_1;c_1 = c;b_2 = b;end
figure(1);
plot(time,ym,'r',time,y,'b');
xlabel('times(s)');ylabel('y and ym');
pfile.mat
p: [2.9915 2.9008 2.4982 1.0059 1.1056 0.8006 0.4780 1.6100 -1.3460 -0.7204 0.4076 0.2786]
4 结果
这篇关于遗传算法(GA)优化后RBF神经网络优化分析(Matlab代码实现)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!