神经网络训练终止的问题~~~~
clear,clc;global L;%输入的训练样本
global R;
global T;
for i=1:588
W(:,i)=;
end
%m=length(W)/2
%for j=1:2*m;
%W1=W(:,j);
%end
= premnmx(W,T);
m=1:(length(W)/2);
W1=Wn(:,2*m);
T1=Tn(:,2*m);
EPOCHS=4000;
GOAL=0.0002;
s=14:2:25;
res=zeros(size(s));
for i=1:length(s)
net=newff(minmax(W1),,{'tansig' 'purelin'},'trainlm');
net.iw{1,1}=zeros(size(net.iw{1,1}))+0.5;
net.lw{2,1}=zeros(size(net.lw{2,1}))+0.75;
net.b{1,1}=zeros(size(net.b{1,1}))+0.5;
net.b{2,1}=zeros(size(net.b{2,1}));
net.trainParam.epochs=EPOCHS;
net.trainParam.goal =GOAL;
net.trainParam.show=50;
net=train(net,W1,T1);
y=sim(net,W1);
e=T1-y;
error=mse(e,net);
res(i)=norm(error);
end
number=find(res==min(res));
if(length(number)>1) no=number(1)
else no=number
end
clear error,res
tic
net=newff(minmax(W1),,{'tansig','purelin'},'trainlm');
net.iw{1,1}=zeros(size(net.iw{1,1}))+0.5;
net.lw{2,1}=zeros(size(net.lw{2,1}))+0.75;
net.b{1,1}=zeros(size(net.b{1,1}))+0.5;
net.b{2,1}=zeros(size(net.b{2,1}));
net.trainParam.epochs=EPOCHS;
net.trainParam.goal =GOAL;
net=train(net,W1,T1);
y=sim(net,W1);
e=T1-y;
error=mse(e,net)%error为网络的误差向量
r=norm(error);%r为网络的整体误差
toc
save net
%预测
n=1:(length(W)/4);
W2=Wn(:,4*n-3);
T2=Tn(:,4*n-3);
y2=sim(net,W2);
%结果反归一化
Y2=postmnmx(y2,minT,maxT);
T_2=postmnmx(T2,minT,maxT);
%计算误差
wucha=abs(Y2-T_2)/T_2;
b=minmax(wucha);
average_wucha=mean(wucha);
请问各位大侠,这个程序若已经达到了训练的目标如何让它终止啊?我训练的目标达到了,但是接着又重新训练了,保存的数据就被clear了,是不是缺少了舍呢么条件啊?请各位帮忙看一下,等目标达到0.000005以后程序自动终止不再执行了~~~
先谢谢了~~
页:
[1]