www.gusucode.com > 《MATLAB神经网络仿真与应用》[张德丰]的所有[程序源代码] > 第5章/li5_10.m
P=[+1.0 -1.2]; T=[+0.5 +1.0]; w_range=-2:0.4:2; b_range=-2:0.4:2; ES=errsurf(P,T,w_range,b_range,'purelin'); plotes(w_range,b_range,ES); maxlr=maxlinlr(P,'bias'); net=newlin([-2 2],1,[0],maxlr*2.25); net.trainParam.epochs=20; net.trainParam.epochs=1; net.trainParam.show=NaN; h=plotep(net.IW{1},net.b{1},mse(T-sim(net,P))); [net,tr]=train(net,P,T); r=tr; epoch=1; while epoch<20 epoch=epoch+1; [net,tr]=train(net,P,T); if length(tr.epoch)>1 h=plotep(net.IW{1,1},net.b{1},tr.perf(2),h); r.epoch=[r.epoch epoch]; r.perf=[r.perf tr.perf(2)]; v.vperf=[r.vperf NaN]; r.tperf=[r.tperf NaN]; else break end end tr=r; solvednet=newlind(P,T); hold on; plot(solvednet.IW{1},solvednet.b{1},'ro') hold off; subplot(1,2,2); plotperf(tr,net.trainParam.goal); p=-1.2; a=sim(net,p)