24小时热门版块排行榜    

查看: 466  |  回复: 3
当前主题已经存档。
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

angry

金虫 (小有名气)

[交流] 【求助】谁帮忙看下我编写的进化规划算法(EP),优化结果总是不对

在matlab中编写了基本的进化规划算法,用测试函数试了一下,但总是不正确,自己找不出毛病,哪位高手帮忙看下,谢过了!
%EP program  主程序
%initial population
clc;clear;
pop_size = 100;
dimension = 30;
MaxIteration = 2000;
xmax = 100; xmin = -100;
score = zeros(1,2*pop_size);
p = 10;
for k = 1:dimension
    X(:,k)= unifrnd(xmin,xmax,pop_size,1);
end
ETA = 3*ones(pop_size,dimension);
% begin iteration
for iter = 1:MaxIteration
    % calculate function value
    for i = 1 : pop_size
        Funcvalue(i) = f1(X(i,: ));
    end
    min(Funcvalue)
    %create offspring
   
    for i = 1 : pop_size
%         rnd = rand(1);      
        rnd = normrnd(0,1,1,1);
        rnd2 = normrnd(0,1,1,dimension);
        rnd3 = normrnd(0,1,1,dimension);
        exponent = rnd./(sqrt(2*dimension)) + rnd2./sqrt(2*sqrt(dimension));
        NewETA(i, : ) = ETA(i,: ).*exp(exponent);
        NewX(i,: ) = X(i,: ) + rnd3.*NewETA(i,: );
    end
    ETA = NewETA;
%calculate offspring's fitness   
    for i = 1 : pop_size
        NewFuncvalue(i) = f1(NewX(i,: ));
    end
    % put parent's and offspring's fitness into a variable
    compFunValue = [Funcvalue, NewFuncvalue];
    UnitX = [X;NewX];
    compIndex = floor(rand(1,p).*2*pop_size);
    for i = 1 : p
        while compIndex(i) == 0
            compIndex(i) =  floor(rand*2*pop_size);
        end
    end
    score = zeros(1,2*pop_size);
    % condult the pair comparison
    for i = 1 : 2*pop_size
        for j = 1 : p
            if compFunValue(i) < compFunValue(compIndex(j))
                score(i) = score(i) + 1;
            end
        end;
    end
    id(1:2*pop_size) = 1 : 2*pop_size;
    [Y, ID] = BiDirectionBubble(score,id);  %sort the parent and offspring
    for i = 1 : pop_size
        X(i,: ) = UnitX(ID(i),: );
    end
end;

% f1.m 测试函数
function y=f1(x)
% This is sphere function
% x is a vector
d=length(x);
y=0;
for k=1:d
    y=y+x(k)^2;
end

% sort function
function [Y3,ID]=BiDirectionBubble(x,id)
runtimes=size(x,2);
low=1;up=runtimes;
while up>low
    t=low;
    for i=low:up-1;
        if x(i)             temp=x(i);
            x(i)=x(i+1);
            x(i+1)=temp;
            idtemp=id(i);
            id(i)=id(i+1);
            id(i+1)=idtemp;
            t=i;
        end;        
    end;
    up=t;
    for i=up:-1:low+1;
        if x(i)>x(i-1);
            temp=x(i);
            x(i)=x(i-1);
            x(i-1)=temp;
            idtemp=id(i);
            id(i)=id(i-1);
            id(i-1)=idtemp;           
            t=i;
        end;
    end;
    low=t;
end;
Y3=x;
ID=id;
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

leidm

银虫 (正式写手)


小木虫(金币+0.5):给个红包,谢谢回帖交流
反复调调,总会发现问题
4楼2009-09-11 23:14:14
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 4 个回答

suton

金虫 (正式写手)

★ ★
小木虫(金币+0.5):给个红包,谢谢回帖交流
bslt(金币+1,VIP+0):赞一个。。。 7-5 10:02
代码发一份给我, 有空帮你调调
stxie@126.com
2楼2009-07-01 11:42:48
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

angry

金虫 (小有名气)

兄弟  已经发了一份了。
3楼2009-07-01 13:01:44
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[硕博家园] 售SCI一区T0P文章,我:8O.55.1.O.54,科目全,可伽急 +3 G6APbkg8SA6w 2026-08-29 3/150 2026-08-30 02:18 by ZPa0EcMwuECS
[考博] 售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急 +3 gy1nBQXYQJqL 2026-08-29 4/200 2026-08-30 01:58 by ZPa0EcMwuECS
[考博] 售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急 +3 gy1nBQXYQJqL 2026-08-29 4/200 2026-08-30 01:34 by ZPa0EcMwuECS
[公派出国] 售SCI文章,我:8O.5.5.1O.54,科目全,可十急 +5 ASdOkHsho7FD 2026-08-28 7/350 2026-08-30 01:12 by ZPa0EcMwuECS
[论文投稿] 售SCI一区文章,我:8.O.551.O.5.4,科目全,可伽急 +4 ASdOkHsho7FD 2026-08-28 5/250 2026-08-30 01:03 by ZPa0EcMwuECS
[教师之家] 售SCI一区T0P文章,我:8.O.55.1.O54,科目全,可伽急 +5 ASdOkHsho7FD 2026-08-28 6/300 2026-08-30 01:03 by ZPa0EcMwuECS
[基金申请] 投票:  有多少人是今天查系统知道结果的? +16 爱看书的可乐 2026-08-26 18/900 2026-08-30 00:59 by winsaint
[公派出国] 售SCI一区T0P文章,我:8.O.55.1.O.5.4,科目全,可+急 +4 ASdOkHsho7FD 2026-08-28 5/250 2026-08-30 00:52 by ZPa0EcMwuECS
[考研] 售SCI一区文章,我:8.O.55.1.O.54,科目齐全,可伽急 +7 ASdOkHsho7FD 2026-08-28 10/500 2026-08-30 00:41 by ZPa0EcMwuECS
[硕博家园] 售SCI一区T0P文章,我:8.O55.1.O.54,科目全,可十急 +6 ASdOkHsho7FD 2026-08-28 12/600 2026-08-30 00:31 by ZPa0EcMwuECS
[基金申请] 面上意见出来了 +8 黄鸟于飞Chao 2026-08-29 16/800 2026-08-29 20:45 by 黄鸟于飞Chao
[基金申请] 有没有仍没收到信息的 +5 德尚中行 2026-08-27 6/300 2026-08-29 18:10 by manplx
[基金申请] 为什么到现在没收到通知? +4 tannykie 2026-08-29 4/200 2026-08-29 17:14 by lmz0216
[教师之家] 导师吐槽:我怎么摊上了这么个极品研究生! +9 苏东坡二世 2026-08-23 9/450 2026-08-29 14:41 by hustersqt
[基金申请] 基金不中,共勉 +11 eulota 2026-08-26 11/550 2026-08-28 14:22 by 火星超人xi
[基金申请] 基金未中,这种答复是模板吗? +5 zhaosm1982 2026-08-27 6/300 2026-08-27 16:00 by lfy8008
[基金申请] 看板上这么多中的,有点像50人群里49个人都是骗子的那种感觉…… +5 a089 2026-08-26 6/300 2026-08-27 14:05 by jonewore
[基金申请] 为什么 国际(地区)合作与交流项目 没有放榜? 10+3 majunge000 2026-08-26 11/550 2026-08-27 08:42 by 北京莱茵编辑
[基金申请] 项目信息和经费信息在系统里都可以看到了 +6 wittyboy 2026-08-26 14/700 2026-08-26 10:55 by wittyboy
[基金申请] 在坚冰还盖着北海的时候,我看到了怒放的梅花。 (金币+10) +6 ziyangfang 2026-08-25 9/450 2026-08-25 20:26 by huagongfeihu
信息提示
请填处理意见