p=p1';t=t1';
[pn,minp,maxp,tn,mint,maxt]=premnmx(p,t); %原始数据归一化
%premnmx Preprocesses data so that minimum is -1 and maximum is 1.
net=newff(minmax(pn),[5,1],{'tansig','purelin'},'traingdx');%设置网络,建立相应的BP网络
%minmax returns the Rx2 matrix PR of minimum and maximum values for each row of P. net.trainParam.show=2000; % 训练网络
net.trainParam.lr=0.01;
net.trainParam.epochs=100000;
net.trainParam.goal=1e-5;
[net,tr]=train(net ,pn,tn); %调用TRAINGDM算法训练BP网络pnew=pnew1';
pnewn=tramnmx(pnew,minp,maxp);
% tramnmx TRAMNMX transforms the network input set using
% minimum and maximum values that were previously
% computed by PREMNMX. This function needs to be
%used when a network has been trained using data normalized
%by PREMNMX. All subsequent inputs to the network need to
%be transformed using the same normalization.
anewn=sim(net,pnewn); %对BP网络进行仿真
anew=postmnmx(anewn,mint,maxt); %还原数据
y=anew';
% Postprocesses data which has been preprocessed by PREMNMX. POSTMNMX postprocesses %the network training
% set which was preprocessed by PREMNMX. It converts
% the data back into unnormalized units.
1、BP网络构建
(1)生成BP网络
=
net newff PR S S SNl TF TF TFNl BTF BLF PF
(,[1 2...],{ 1 2...},,,)
R?维矩阵。
PR:由R维的输入样本最小最大值构成的2
S S SNl:各层的神经元个数。
[1 2...]
TF TF TFNl:各层的神经元传递函数。
{ 1 2...}
BTF:训练用函数的名称。
(2)网络训练
net tr Y E Pf Af train net P T Pi Ai VV TV
=
[,,,,,] (,,,,,,)
(3)网络仿真
=
[,,,,] (,,,,)
Y Pf Af E perf sim net P Pi Ai T
{'tansig','purelin'},'trainrp'