24小时热门版块排行榜    

查看: 398  |  回复: 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 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 307求调剂 +11 冷笙123 2026-03-17 11/550 2026-03-22 20:16 by edmund7
[考研] 一志愿武理材料工程348求调剂 +5  ̄^ ̄゜汗 2026-03-19 7/350 2026-03-22 19:44 by 公瑾逍遥
[考研] 求调剂 +6 十三加油 2026-03-21 6/300 2026-03-22 17:00 by i_cooler
[考研] 319求调剂 +4 小力气珂珂 2026-03-20 4/200 2026-03-22 15:53 by ColorlessPI
[考研] 311求调剂 +3 26研0 2026-03-20 3/150 2026-03-22 14:46 by ColorlessPI
[考研] 求调剂 +5 Zhangbod 2026-03-21 7/350 2026-03-22 13:13 by Zhangbod
[考研] 考研调剂 +4 来好运来来来 2026-03-21 4/200 2026-03-22 12:15 by 星空星月
[考研] 285求调剂 +6 ytter 2026-03-22 6/300 2026-03-22 12:09 by 星空星月
[考研] 297求调剂 +11 戏精丹丹丹 2026-03-17 12/600 2026-03-21 17:47 by ColorlessPI
[考研] 311求调剂 +3 勇敢的小吴 2026-03-20 3/150 2026-03-21 17:40 by ColorlessPI
[考研] 307求调剂 +3 余意卿 2026-03-18 3/150 2026-03-21 17:31 by ColorlessPI
[考研] 332求调剂 +3 凤凰院丁真 2026-03-20 3/150 2026-03-21 10:27 by luoyongfeng
[考研] 299求调剂 +6 △小透明* 2026-03-17 6/300 2026-03-21 02:42 by JourneyLucky
[考研] 265求调剂 +9 梁梁校校 2026-03-17 9/450 2026-03-21 02:17 by JourneyLucky
[考研] 085600材料与化工 +8 安全上岸! 2026-03-16 8/400 2026-03-20 22:13 by luoyongfeng
[考研] 290求调剂 +7 ^O^乜 2026-03-19 7/350 2026-03-20 21:43 by JourneyLucky
[考研] 材料学求调剂 +4 Stella_Yao 2026-03-20 4/200 2026-03-20 20:28 by ms629
[考研] 0703化学调剂 +4 18889395102 2026-03-18 4/200 2026-03-19 16:13 by 30660438
[考研] 一志愿福大288有机化学,求调剂 +3 小木虫200408204 2026-03-18 3/150 2026-03-19 13:31 by houyaoxu
[考研] 308求调剂 +4 是Lupa啊 2026-03-16 4/200 2026-03-17 17:12 by ruiyingmiao
信息提示
请填处理意见