⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gasysiden.asv

📁 这是一个遗传算法的优化软件
💻 ASV
字号:
global yout time 
%系统辨识遗传主程序
a_1=subplot(3,1,1);
set(a_1,'XColor','white','YColor','white');
a_2=subplot(3,1,2);
set(a_2,'XColor','white','YColor','white');
pause(0.1);
if popsize<2
    popsize=2;
end
if maxgen<1
    maxgen=1;
end
codeL=6*lchrom;
%initial
bestTi=zeros(1,6);
code=round(rand(codeL,popsize));
bestobj=0;
pamax=2^lchrom-1;
for i=1:1:maxgen
    timef(i)=i;
    %select save cross num to indexobj
    for t=1:1:popsize
        m1=code(1:lchrom,t);
        y1=0;
        for j=1:1:lchrom
            y1=y1+m1(j)*2^(j-1);%转化为10进制
        end
        T(t,1)=(MaxX(1)-MinX(1))*y1/pamax+MinX(1);
        y2=0;
        m2=code(lchrom+1:2*lchrom,t);
        for j=1:1:lchrom
            y2=y2+m2(j)*(2^j-1);
        end
        T(t,2)=(MaxX(2)-MinX(2))*y2/pamax+MinX(2);
        y3=0;
        m3=code(2*lchrom+1:3*lchrom,t);
        for j=1:1:lchrom
            y3=y3+m3(j)*2^(j-1);
        end
        T(t,3)=(MaxX(3)-MinX(3))*y3/1023+MinX(3);
        y4=0;
        m4=code(3*lchrom+1:4*lchrom,t);
        for j=1:1:lchrom
            y3=y3+m3(j)*2^(j-1);
        end
        T(t,4)=(MaxX(4)-MinX(4))*y4/pamax+MinX(4);
        y5=0;
        m5=code(4*lchrom+1:5*lchrom,t);
        for j=1:1:lchrom
            y5=y5+m5(j)*2^(j-1);
        end
        T(t,5)=(MaxX(5)-MinX(5))*y5/pamax+MinX(5);
        y6=0;
        m6=code(5*lchrom+1:6*lchrom,t);
        for j=1:1:lchrom
            y6=y6+m6(j)*2^(j-1);
        end
        T(t,6)=(MaxX(6)-MinX(6))*y6/pamax+MinX(6);
        
        obj(t)=sysidenobj(T(t,:),popsize,lchrom,ts,rin,rout);
    end
    [orderobj,indexobj]=sort(obj);
    if(bestobj<obj(indexobj(popsize)))
        bestobj=obj(indexobj(popsize));
        bestTi=T(indexobj(popsize),:);
    end;
    beobj(i)=bestobj;
    obj_sum=sum(obj);
    for j=1:1:popsize
        select_rand=rand;
        select_p=0;
        k=0;
        while select_rand>select_p
            k=k+1;
            select_p=select_p+obj(k)/obj_sum;
        end
        cindex(j)=k;
    end
    %cross
    tempcode=code(:,cindex);
    for j=1:2:popsize-1
        cross_rand=rand;
        n=ceil(codeL*rand);
        if cross_rand<pcross
            tempcode(n:codeL,j)=code(n:codeL,cindex(j+1));
            tempcode(n:codeL,j+1)=code(n:codeL,cindex(j));
        end
    end
    %mutate
    for j=1:1:popsize
      for k=1:1:codeL
         mumate_rand=rand;
         if pmutate>mumate_rand               %Mutation Condition
            if tempcode(k,j)==0
               tempcode(k,j)=1;
            else
               tempcode(k,j)=0;
            end
        end
      end
   end
   code=tempcode;
end
sysidenobj(bestTi,popsize,lchrom,ts,rin,rout);

a_1=subplot(3,1,1);plot(timef,beobj);
set(a_1,'XColor','white','YColor','white');
xlabel('遗传代数');ylabel('最大适应度');

a_2=subplot(3,1,2);plot(time,rout,'r',time,yout,'b');
set(a_2,'XColor','white','YColor','white');
xlabel('时间');ylabel('实际输出,预测值');


t_s3 = uicontrol( 'Style','text','Position',[0.05 0.3 0.15 0.04],'String','[k,z1,z2,p1,p2,p3]',...
	'BackgroundColor',[0.3 0.3 0.3], 'ForegroundColor','white');
t_s8 = uicontrol( 'Style','text','Position',[0.21 0.3 0.6 0.04],'String',mat2str(bestTi),...
	'BackgroundColor',[0.3 0.3 0.3], 'ForegroundColor','white');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -