24小时热门版块排行榜    

查看: 392  |  回复: 1

s20090281

银虫 (小有名气)

[求助] 遗传算法求助指点需要改进的地方

function [out]=my_function(input)
clear all;
clc;
size=50;
codel=4;
G=100;
T1=clock;
s=sprintf('程序正在运行中,请稍等......');
disp(s);
popu=2*rand(size,codel)-1;
for kg=1:G
    time(kg)=kg;
    for i=1:size
        xi=popu(i,;
        x1=xi(1);
        x2=xi(2);
        x3=xi(3);
        x4=xi(4);
        a=load('C:\testresult\控制.txt');
        b=load('C:\testresult\反馈.txt');
        c=0;
        for k=3:360
            f=[b(k)-x1*b(k-1)-x2*b(k-2)-x3*a(k-1)-x4*a(k-2)]^2;
            c=c+f;
            Msum(i,k)=c;
            Mfit(i,k)=1/c;
        end
        fitness=Mfit(:,k);
    end
    [Oderfi,Indexfi]=sort(fitness);
     Bestfi=Oderfi(size);
     BestS=popu(Indexfi(size),;
     bfi(kg)=Bestfi
     fi_sum=sum(fitness);
     fi_size=(Oderfi/fi_sum)*size;
     fi_s=floor(fi_size);
     r=size-sum(fi_s);
     for i=size:-1:size-r+1
         fi_s(Indexfi(i))=fi_s(Indexfi(i))+1; %Adding rest to equal Size
     end
     k=1;
     for i=size:-1:1
         for j=1:fi_s(i)
             newpopu(k,=popu(Indexfi(i),; %Selecting and Reproduce
             k=k+1;                           %k is used to reproduce
         end
     end
     popu=newpopu;
     pc=0.9;
     for i=1:2:size-1
         temp=rand;
         if pc>temp
             alfa=rand;
             newpopu(i,=alfa*popu(i+1,+(1-alfa)*popu(i,;
             newpopu(i+1,=alfa*popu(i,+(1-alfa)*popu(i+1,;
         end
     end
     A(size,=BestS;
     popu=newpopu;
     
     pm=0.1;
     minx=[-1 -1 -1 -1];
     maxx=[1 1 1 1];
     Dif=maxx-minx;
     for i=1:size
         for j=1:codel
             if pm>rand(i,j)
                 mean=(minx+maxx)/2
                 newpopu(i,j)=mean(j)+Dif(j)*(rand-0.5);
             end
         end
     end
    B(size,=BestS;
    popu=newpopu;
end
fmin=1/Bestfi
BestS
%观测终了代数的极小值(解)
figure(1)                         %画每代适应度最小值fmin、平均值
t=1:G;                 
plot(t,1./bfi,'r')
xlabel('t');
ylabel('每代适应度最小值fmin');
T2=clock;
%计算运行时间
elapsed_time=T2-T1;
if elapsed_time(6)<0
    elapsed_time(6)=elapsed_time(6)+60; elapsed_time(5)=elapsed_time(5)-1;
end  %秒
if elapsed_time(5)<0
    elapsed_time(5)=elapsed_time(5)+60;elapsed_time(4)=elapsed_time(4)-1;
end  %分
if elapsed_time(4)<0
    elapsed_time(4)=elapsed_time(4)+24;elapsed_time(3)=elapsed_time(3)-1;
end %时
str2=sprintf('程序运行耗时 %d 小时 %d 分钟 %.f 秒',elapsed_time(4),elapsed_time(5),elapsed_time(6));
disp(str2);
end
这是我最近根据其他人改进的适合自己的遗传算法,运行速度是6、7分钟,存在以下问题,结果每次相差太大,有时候就是100代都保持相同的值不变,有时候值特别的大,若是收敛值也不理想,请教有什么地方不合适需要改进的地方,请指点,谢谢
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

s20090281

银虫 (小有名气)

请大家帮个忙,谢谢
2楼2011-07-01 15:18:29
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 s20090281 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 求调剂 +3 Ma_xt 2026-03-17 3/150 2026-03-21 02:05 by JourneyLucky
[考研] 085700资源与环境308求调剂 +12 墨墨漠 2026-03-18 13/650 2026-03-21 01:42 by JourneyLucky
[考研] 294求调剂材料与化工专硕 +15 陌の森林 2026-03-18 15/750 2026-03-20 23:28 by JourneyLucky
[考研] 085600材料与化工 +8 安全上岸! 2026-03-16 8/400 2026-03-20 22:13 by luoyongfeng
[考研] 招收调剂硕士 +4 lidianxing 2026-03-19 12/600 2026-03-20 12:25 by lidianxing
[考研] 081700化工学硕调剂 +3 【1】 2026-03-16 3/150 2026-03-19 23:40 by edmund7
[考研] 0703化学调剂 +10 妮妮ninicgb 2026-03-15 14/700 2026-03-19 22:59 by 学员8dgXkO
[考研] 生物学调剂招人!!! +3 山海天岚 2026-03-17 4/200 2026-03-19 21:34 by 怎么释怀
[考研] 266求调剂 +5 阳阳哇塞 2026-03-14 10/500 2026-03-19 15:08 by 阳阳哇塞
[考研] 一志愿西安交通大学材料工程专业 282分求调剂 +5 枫桥ZL 2026-03-18 7/350 2026-03-19 14:52 by 功夫疯狂
[考研] 化学工程321分求调剂 +15 大米饭! 2026-03-15 18/900 2026-03-18 14:52 by haxia
[考研] 303求调剂 +4 睿08 2026-03-17 6/300 2026-03-18 11:01 by Iveryant
[考研] 293求调剂 +11 zjl的号 2026-03-16 16/800 2026-03-18 08:10 by zhukairuo
[考研] 考研求调剂 +3 橘颂. 2026-03-17 4/200 2026-03-17 21:43 by 有只狸奴
[考研] 277调剂 +5 自由煎饼果子 2026-03-16 6/300 2026-03-17 19:26 by 李leezz
[考研] 材料专硕326求调剂 +6 墨煜姒莘 2026-03-15 7/350 2026-03-17 17:10 by ruiyingmiao
[考研] 一志愿,福州大学材料专硕339分求调剂 +3 木子momo青争 2026-03-15 3/150 2026-03-17 07:52 by laoshidan
[考研] 中科院材料273求调剂 +4 yzydy 2026-03-15 4/200 2026-03-16 15:59 by Gaodh_82
[考研] 求老师收留调剂 +4 jiang姜66 2026-03-14 5/250 2026-03-15 20:11 by Winj1e
[考研] 085601材料工程315分求调剂 +3 yang_0104 2026-03-15 3/150 2026-03-15 10:58 by peike
信息提示
请填处理意见