| 查看: 358 | 回复: 3 | |||
| 当前主题已经存档。 | |||
[交流]
【求助】谁帮忙看下我编写的进化规划算法(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) 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; |
» 猜你喜欢
有没有人能给点建议
已经有5人回复
假如你的研究生提出不合理要求
已经有12人回复
实验室接单子
已经有7人回复
全日制(定向)博士
已经有5人回复
萌生出自己或许不适合搞科研的想法,现在跑or等等看?
已经有4人回复
Materials Today Chemistry审稿周期
已经有4人回复
参与限项
已经有3人回复
对氯苯硼酸纯化
已经有3人回复
所感
已经有4人回复
要不要辞职读博?
已经有7人回复
suton
金虫 (正式写手)
- 应助: 1 (幼儿园)
- 贵宾: 0.614
- 金币: 1340.5
- 散金: 19
- 红花: 1
- 帖子: 950
- 在线: 292.6小时
- 虫号: 497554
- 注册: 2008-02-02
- 性别: GG
- 专业: 计算机应用技术
2楼2009-07-01 11:42:48
3楼2009-07-01 13:01:44
4楼2009-09-11 23:14:14












回复此楼