Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 人工智能 > 进化计算
进化计算 A discussion board for Evolutionary Computation.
 
 
主题工具 显示模式
旧 2013-03-11, 09:43   #5
ai_hinemon
初级会员
 
注册日期: 2013-03-11
帖子: 9
声望力: 0
ai_hinemon 正向着好的方向发展
默认 回复: MATLAB实现遗传算法 如何画出进化代数和适应值的图?急求

引用:
作者: ai_hinemon 查看帖子
L=ceil(log2((b-a)/eps+1)); %根据离散精度,确定二进制编码需要的码长
x=zeros(NP,L);
for i=1:NP
x(i,=Initial(L);%种群初始化
fx(i)=fitness(Dec(a,b,x(i,,L)); %个体适应值
end
for k=1:NG
sumfx=sum(fx); %所有个体适应值之和
px=fx/sumfx; %所有个体适应值的平均值
ppx=0;
ppx(1)=px(1);
for i=2:NP %用于轮盘赌策略的累加
ppx(i)=ppx(i-1)+px(i);
end
for i=1:NP
sita=rand();
for n=1:NP
if sita<=ppx(n)
SelFather=n; %根据轮盘赌策略确定的父亲
break;
end
end
Selmother=floor(rand()*(NP-1))+1; %随机选择母亲
posCut=floor(rand()*(L-2))+1; %随机选择交叉点
r1=rand();
if r1<=pc %交叉
nx(i,1osCut)=x(SelFather,1osCut);
nx(i,(posCut+1):L)=x(Selmother,(posCut+1):L);
r2=rand();
if r2<=pm %变异
posMut=round(rand()*(L-1)+1);
nx(i,posMut)=~nx(i,posMut);
end
ai_hinemon 当前离线   回复时引用此帖
 


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛禁用 HTML 代码



所有时间均为北京时间。现在的时间是 19:56


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.