资源简介

matlab实现粒子群算法优化RBF网络,代码有解释。可以跑通!!!

资源截图

代码片段和文件信息

%RBF网络,由chap10_3a调用,返回值B为误差的和,和越小,说明得到的权值越好

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Adaptive PID control based on Fuzzy RBF Identification
function [pBsJ] = rbf_gaf(pBsJ)
ts = 0.001;

xite=0.20;
alfa=0.02;

%c0=0.65*ones(25);
%b0=0.30*ones(51);
b0=[p(1);p(2);p(3);p(4);p(5)];
c0=[p(6) p(7) p(8) p(9) p(10);
    p(11) p(12) p(13) p(14) p(15)];
w0=[p(16) p(17) p(18);
    p(19) p(20) p(21);
    p(22) p(23) p(24);
    p(25) p(26) p(27);
    p(28) p(29) p(30);
    p(31) p(32) p(33);
    p(34) p(35) p(36);
    p(37) p(38) p(39);
    p(40) p(41) p(42);
    p(43) p(44) p(45);
    p(46) p(47) p(48);
    p(49) p(50) p(51);
    p(52) p(53) p(54);
    p(55) p(56) p(57);
    p(58) p(59) p(60);
    p(61) p(62) p(63);
    p(64) p(65) p(66);
    p(67) p(68) p(69);
    p(70) p(71) p(72);
    p(73) p(74) p(75);
    p(76) p(77) p(78);
    p(79) p(80) p(81);
    p(82) p(83) p(84);
    p(85) p(86) p(87);
    p(88) p(89) p(90)];
%w0=rands(51);

c=c0;c_1=c0;c_2=c0;
b=b0;b_1=b0;b_2=b0;
w4=w0;w4_1=w0;w4_2=w0;

x=[00]‘;
xc=[000]‘;

du_1=0;u_1=0;y_1=0;
e_1=0;e_2=0;e=0;

ts=0.001;
for k=1:1:400%500
   timef(k)=k*ts;
   %rin(k)=1.0;
   rin(k)=1.0*sign(sin(2*pi*k*ts));
   yout(k)=(-0.1*y_1+u_1)/(1+y_1^2);  %Nonlinear plant
   
   x(1)=rin(k);
   x(2)=yout(k);
   
   f1=x;                        
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:1:2                         % layer2:fuzzation
   for j=1:1:5
      net2(ij)=-(f1(i)-c_1(ij))^2/b_1(j)^2;
   end
end
for i=1:1:2
   for j=1:1:5
       f2(ij)=exp(net2(ij));
   end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for j=1:1:5                        % layer3:fuzzy inference(49 rules)
    m1(j)=f2(1j);
 m2(j)=f2(2j);
end

for i=1:1:5
for j=1:1:5
    ff3(ij)=m2(i)*m1(j);           
end
end
f3=[ff3(1:)ff3(2:)ff3(3:)ff3(4:)ff3(5:)];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

f4=w4‘*f3‘;                      % layer4:output

kp(k)=f4(1);
ki(k)=f4(2);
kd(k)=f4(3);

%----------Calculate error id between yout and ymout-----------%
e(k)=rin(k)-yout(k);

du(k)=kp(k)*xc(1)+kd(k)*xc(2)+ki(k)*xc(3); 
u(k)=u_1+du(k);

dyu(k)=sign((yout(k)-y_1)/(du(k)-du_1+0.0001));

d_w4=0*w4_1;
for i=1:1:25
   for j=1:1:3
      d_w4(ij)=xite*e(k)*dyu(k)*xc(j)*f3(i);
   end
end
w4=w4_1+ d_w4+alfa*(w4_1-w4_2);

%Return of parameters
du_1=du(k);
   u_1=u(k);
   y_1=yout(k);
   
   w4_2=w4_1;w4_1=w4;
   
   xc(1)=e(k)-e_1;             %Calculating P
   xc(2)=e(k);                     %Calculating I
   xc(3)=e(k)-2*e_1+e_2;   %Calculating D
   
   e_2=e_1;
   e_1=e(k);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


B = 0;
for i = 1:1:400
    Ji(i) = abs(e(i));
    B = B + 100*Ji(i);
end
BsJ = B;
    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件        2818  2011-05-12 20:28  粒子群算法优化RBF网络\PSO.m
     文件        3033  2011-05-12 21:59  粒子群算法优化RBF网络\chap10_3b.m
     文件        1397  2011-05-12 19:17  粒子群算法优化RBF网络\chap10_3c.m
     文件        3046  2011-05-12 17:08  粒子群算法优化RBF网络\chap4_10.m
     文件         348  2011-05-12 20:38  粒子群算法优化RBF网络\pfile1.mat
     文件        1872  2011-05-12 19:58  粒子群算法优化RBF网络\shuchu.asv
     文件        1883  2011-05-12 20:42  粒子群算法优化RBF网络\shuchu.m
     目录           0  2017-03-15 22:14  粒子群算法优化RBF网络\

评论

共有 条评论