24小时热门版块排行榜    

查看: 394  |  回复: 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的回帖

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的回帖

leidm

银虫 (正式写手)


小木虫(金币+0.5):给个红包,谢谢回帖交流
反复调调,总会发现问题
4楼2009-09-11 23:14:14
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 angry 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 311求调剂 +4 南迦720 2026-02-28 4/200 2026-02-28 16:31 by etapple
[考研] 0856材料求调剂 +8 hyf hyf hyf 2026-02-28 9/450 2026-02-28 16:27 by etapple
[考研] 285求调剂 +3 满头大汗的学生 2026-02-28 3/150 2026-02-28 16:22 by 无际的草原
[考研] 265分求调剂不调专业和学校有行学上就 +4 礼堂丁真258 2026-02-28 6/300 2026-02-28 16:18 by 求调剂zz
[考研] 312求调剂 +4 吃宵夜1 2026-02-28 5/250 2026-02-28 16:11 by gjm133
[考博] 26申博 +3 想申博! 2026-02-26 3/150 2026-02-28 16:07 by nxgogo
[考研] 材料类求调剂 +3 wana_kiko 2026-02-28 3/150 2026-02-28 15:03 by lature00
[考研] 295求调剂 +4 19171856320 2026-02-28 4/200 2026-02-28 13:39 by ms629
[考研] 290求调剂 +4 材料专硕调剂; 2026-02-28 5/250 2026-02-28 13:32 by houyaoxu
[考研] 0856调剂 +3 刘梦微 2026-02-28 3/150 2026-02-28 13:22 by houyaoxu
[考研] 寻找调剂 +3 LYidhsjabdj 2026-02-28 3/150 2026-02-28 12:59 by miniwendy
[考研] 304求调剂 +5 曼殊2266 2026-02-28 6/300 2026-02-28 12:44 by 迷糊CCPs
[硕博家园] 博士自荐 +6 科研狗111 2026-02-26 9/450 2026-02-28 12:32 by seaskyy
[考研] 272求调剂 +3 田智友 2026-02-28 3/150 2026-02-28 12:31 by 王加浩to
[考研] 298求调剂 +4 axyz3 2026-02-28 4/200 2026-02-28 11:21 by wang_dand
[考研] 280求调剂 +6 Qq206./ 2026-02-21 6/300 2026-02-28 11:20 by 我!要一战成硕
[高分子] 求环氧树脂研发1名 +3 孙xc 2026-02-25 10/500 2026-02-27 13:22 by ichall
[基金申请] 面上可以超过30页吧? +12 阿拉贡aragon 2026-02-22 13/650 2026-02-26 22:09 by Hahaxia
[教师之家] 版面费该交吗 +14 苹果在哪里 2026-02-22 17/850 2026-02-26 11:55 by AGI智创机器人
[硕博家园] 【博士招生】太原理工大学2026化工博士 +4 N1ce_try 2026-02-24 8/400 2026-02-26 08:40 by N1ce_try
信息提示
请填处理意见