这个GA优化BP的程序错误怎么改啊
我编了个程序用GA优化BP,不是优化BP的结构,是以BP的输出作为适应度函数,优化BP的输入得到最大的输出,程序、适应度函数fitness及出现的问题如下,请大家帮我看看啊,谢谢!p=[ 40 21 2.5 6 5;
40 25 3 6.5 10;
40 30 3.5 7 20;
45 21 2.5 6.5 10;
45 25 3 7 20;
45 30 3.5 6 5;
50 21 3 6 20;
50 25 3.5 6.5 5;
50 30 2.5 7 10;
40 21 3.5 7 10;
40 25 2.5 6 20;
40 30 3 6.5 5;
45 21 3 7 5;
45 25 3.5 6 10;
45 30 2.5 6.5 20;
50 21 3.5 6.5 20;
50 25 2.5 7 5;
50 30 3 6 10];
t=;
T=t';
P=p';
net=newff(minmax(P),,{'tansig','purelin'},'trainlm');
%训练网络
net.trainParam.show=10;
%net.trainParam.lr=0.05;
%net.trainParam.lr_inc=1.05;
net.trainParam.epochs=10000;
net.trainParam.goal=1e-5;
% net=init(net);
=train(net,P,T);
minmax_var=minmax(P);
minmax_target=minmax(T);
save('result','net','minmax_var','minmax_target');
load('result','net','minmax_var','minmax_target');
%生成初始种群,大小为20
initPop=initializega(20,minmax(P),'fitness');
%100次遗传迭代
=ga(minmax(P),...
'fitness',[],...
initPop,,...
'maxGenTerm',100,...
'normGeomSelect',,...
['arithXover'],,...
'nonUnifMutation',);
figure(1)
plot(endPop(:,1),endPop(:,2),'y*')
figure(2)
plot(trace(:,1),trace(:,2),'r*')
xlabel('Generation');
ylabel('Fitness');
legend('解的变化','种群平均值的变化')
错误提示如下:
??? Error using ==> network.sim
Inputs are incorrectly sized for network.
Matrix must have 5 rows.
Error in ==> fitness at 7
eval=sim(net,P);
Error in ==> initializega at 41
eval(estr);
%这是适应度函数
function =fitness(P,options)
global net;global isformax;
global minmax_target;
load('result');
min_target=minmax_target(1);
max_target=minmax_target(2);
eval=sim(net,P);
if isformax
eval=eval-min_target+(max_target-min_target);
else
eval=-eval+max_target+(max_target-min_target);
end
[ 本帖最后由 eight 于 2007-6-20 17:15 编辑 ] 原帖由 yiumao 于 2007-6-20 16:19 发表 http://www.chinavib.com/forum/images/common/back.gif
我编了个程序用GA优化BP,不是优化BP的结构,是以BP的输出作为适应度函数,优化BP的输入得到最大的输出,程序、适应度函数fitness及出现的问题如下,请大家帮我看看啊,谢谢!
p=[ 40 21 2.5 6 5;
40 25 3 6 ...
请就内容表述的问题先看看置顶贴:聚宝盆
页:
[1]