24小时热门版块排行榜    

Znn3bq.jpeg
汕头大学海洋科学接受调剂
查看: 409  |  回复: 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的回帖
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 327求调剂 +23 Xxjc1107. 2026-04-13 25/1250 2026-04-14 18:48 by 逍遥三郎
[考研] 调剂 +12 月@163.com 2026-04-11 12/600 2026-04-14 15:37 by zs92450
[考研] 求调剂 +20 MAX怅惘 2026-04-09 22/1100 2026-04-14 14:57 by 独醉梦孤城
[考研] 085408光电信息工程专硕355一志愿长春光机所调剂 +6 王ymaa 2026-04-13 13/650 2026-04-14 11:33 by 王ymaa
[考研] B区0809 ,数一英一,290 求调剂 +3 泠潍1111 2026-04-12 4/200 2026-04-13 20:35 by 学员JpLReM
[基金申请] 2026 WR青拔 +3 冬日阳光CAS 2026-04-09 6/300 2026-04-13 18:40 by liuchb715
[基金申请] 有爆料,一个青年教师卖房得400万,然后换了一个四青帽子 +11 babu2015 2026-04-08 11/550 2026-04-13 16:33 by probebill
[考研] 070300化学279求调剂 +19 哈哈哈^_^ 2026-04-08 20/1000 2026-04-11 20:43 by stoner78
[考研] 086003调剂求助 +21 苏弋万 2026-04-09 22/1100 2026-04-11 20:25 by dongdian1
[考研] 359求调剂 +5 胃痉挛累了 2026-04-11 5/250 2026-04-11 19:55 by lbsjt
[考研] 求调剂 +3 胃痉挛累了 2026-04-11 5/250 2026-04-11 14:13 by luhong1990
[考研] 调剂 +4 电气300求调剂不 2026-04-08 7/350 2026-04-11 10:44 by 紫曦紫棋
[考研] 283求调剂,工科! +12 苏打水7777 2026-04-08 12/600 2026-04-11 10:28 by 逆水乘风
[考研] 机械专硕270求调剂,接受跨专业 +12 老师看看我吧aba 2026-04-09 14/700 2026-04-11 10:21 by laoshidan
[考研] 调剂 +12 卷卷卷心菜_ 2026-04-09 13/650 2026-04-10 22:36 by Ftglcn90
[考研] 263能源动力专硕求调剂 +3 加大号饭盒袋 2026-04-10 3/150 2026-04-10 22:23 by 286640313
[考研] 293调剂 +25 yj1221 2026-04-08 26/1300 2026-04-10 15:02 by 柴小白
[考研] 344求调剂 +7 丶风雪夜归人丶 2026-04-09 7/350 2026-04-10 12:05 by pengliang8036
[考研] 材料专硕(0856) 339分求调剂 +9 哈哈哈鹅哈哈哈 2026-04-09 10/500 2026-04-09 20:01 by Orcid
[考研] 求调剂,现在还能填的 +3 上岸小莹加油 2026-04-08 3/150 2026-04-08 14:30 by zhq0425
信息提示
请填处理意见