www.gusucode.com > bp网络实现0~9数字识别系统matlab源码程序 > exampleTr.m
%NN1T,Training of BP network %============== %BP网络训练 %============== figure('name','训练过程图示','numbertitle','off'); S(:,1)=nn1f('00.bmp'); S(:,2)=nn1f('10.bmp'); S(:,3)=nn1f('20.bmp'); S(:,4)=nn1f('30.bmp'); S(:,5)=nn1f('40.bmp'); S(:,6)=nn1f('50.bmp'); S(:,7)=nn1f('60.bmp'); S(:,8)=nn1f('70.bmp'); S(:,9)=nn1f('80.bmp'); S(:,10)=nn1f('90.bmp'); T=[0 1 2 3 4 5 6 7 8 9]; %训练样本的期望输出 1个输出神经元 % T=[ 0 0 0 0 0 0 0 0 0 1; % 0 0 0 1 1 1 2 2 2 0; % 0 1 2 0 1 2 0 1 2 0]; [R,Q]=size(S);[S2,Q]=size(T); S1=str2num(S1); %隐层神经元个数 %W1=rands(R,S1); [W1,B1]=rands(S1,R); [W2,B2]=rands(S2,S1); A2=purelin(W2*tansig(W1*S,B1),B2); %initialize the parameters disp_freq=20; max_epoch=str2num(max_epoch); err_goal=str2num(err_goal); lr=str2num(lr); %学习步长 TP=[disp_freq max_epoch err_goal lr]; %training begins [W1,B1,W2,B2,epochs,errors]=trainbp(W1,B1,'tansig',W2,B2,'purelin',S,T,TP); %ploterr(errors); out=purelin(W2*tansig(W1*S,B1),B2); %实际输出 SSE=sumsqr(T-out); fprintf('Trained network operates:'); if SSE < err_goal disp('Adequately.') else disp('Inadequately.') end