声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 847|回复: 0

[编程技巧] 人工智能的一段程序,老出问题,望专家指点

[复制链接]
发表于 2008-11-29 16:13 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
lear
clc
tic;
gen=500;N=65;L=22;n=10;pm=0.1;fat=0.2;
P=init(N,L);
xmin=0;xmax=9;
f='x+10*sin(x.*5)+7*cos(x.*4)';
vfx=[];vmfit=[];
it=0;
while it<gen
    it=it+1;
    x=decode(P(:,1:22),xmin,xmax);
    fit=eval(f);
    if it==1
        figure(1);fplot(f,[xmin,xmax]);grid on;hold on;
        plot(x,fit,'k*');title('(a)抗体的初始位置分布图');xlabel('x');ylabel('y');
    end
    if it==gen
        figure(2);fplot(f,[xmin,xmax]);grid on;hold on;
        plot(x,fit,'k*');title('(b)抗体的最终位置分布图');xlabel('x');ylabel('y');
    end
    T=[];
    [a,ind]=sort(fit);
    valx=x(ind(end-n+1:end));
    fx=a(end-n+1:end);
    vfx=[vfx fx(end)];
    [T,pcs]=reprod(n,fat,N,ind,P,T);
    T=Hypermutation(T,L,pm,xmax,xmin);
    T(pcs,:)=P(fliplr(ind(end-n+1:end)),:);
     x=decode(T(:,1:22),xmin,xmax);
     fit=eval(f);pcs=[0 pcs];vmfit=[vmfit mean(fit)];
     for i=1:n
         [out(i),bcs(i)]=max(fit(pcs(i)+1:pcs(i+1)));
         bcs(i)=bcs(i)+pcs(i);
     end
     P(fliplr(ind(end-n+1:end)),:)=T(bcs,:);
end
[aa,bb]=max(fit)
x(bb)
toc   


function ab=init(n,s)
ab=2.*rand(n,s)-1;
ab=hardlim(ab);  


function x=decode(v,xmin,xmax)
v=fliplr(v);
s=size(v);
aux=0:1:21;aux=ones(s(1),1)*aux;
x1=sum((v.*2.^aux)');
x=xmin+(xmax-xmin)*x1./4194303;
  .
  .
  .
  .
.
    end
end
----------------------------------------------------------------

这是出现的错误:Function definitions are not permitted at the prompt or in scripts.

好像脚本里面定义了函数,要重写另一个文件定义函数
由于是新手,具体怎么操作
谢谢
回复
分享到:

使用道具 举报

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-22 19:47 , Processed in 0.060704 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表