bp网络训练演示

 

bp网络训练演示





 

 

 

%bp网络训练演示 %初始值 P=-1:0.1:1; %目标值 T=[0:0.314:6.28]; T=sin(T); %%创建两层前向回馈网络 net=newcf(minmax(P),[5,1],{'tansig','purelin'},'traingd'); % 初始化网络 net = initnw(net,1); % initnw is a layer initialization function % that initializes a layer's weights and biases % according to the Nguyen-Widrow initialization algorithm. % This algorithm chooses values in order to distribute % the active region of each neuron in the layer approximately evenly across the layer's input space. % initnw(net,i) takes two arguments, % net -- Neural network % i -- Index of a layer % and returns the network with layer i's weights and biases updated. w0 = net.iw{1,1}; b0 = net.b{1}; w1 = net.lw{2,1}; b1 = net.b{2}; %仿真,模拟结果 y=sim(net,P); %初始值,目标值 plot(P,T,'ro') hold on %画出初始目标值 plot(P,y) hold off %初始化训练参数 net.trainParam.epochs=7000; net.trainParam.goal=9.5238e-004; net.iw{1,1}=w0*0.5; net.b{1}=b0*0.5; net.trainParam.lr = 0.15; %训练网络 [net tr]=train(net,P,T); %计算结果 Y=sim(net,P); %画出最后的训练结果 figure(2) plot(P,T,'ro') hold on plot(P,Y) hold off

你可能感兴趣的:(Algorithm,网络,NetWork,layer,initialization,plot)