bp神经网络matlab设计实例,bp神经网络matlab实例(bp神经网络matlab实例).doc
bp神经网络matlab实例(bp神经网络matlab实例).doc
bp神经网络matlab实例(bp神经网络matlab实例)Case 1 training BP network by momentum gradient descent algorithm.
Training samples are defined as follows:
Input vector as
P =[-1 -2 31
-1 15 -3]
The target vector is t = [-1 -1 1 1]
Solution: the MATLAB program of this example is as follows:
Close all
Clear
Echo on
CLC
% NEWFF - generating a new feedforward neural network
% TRAIN -- training BP neural network
% SIM -- Simulation of BP neural network
Pause
Start by hitting any key
CLC
Percent defines training samples
% P as input vector
P=[-1, -2, 3, 1; -1, 1, 5, -3];
% T is the target vector
T=[-1, -1, 1, 1];
Pause;
CLC
% create a new feedforward neural network
Net=newff (minmax (P), [3,1], {'tansig','purelin'},'traingdm')
The current input layer weights and thresholds
InputWeights=net.IW{1,1}
Inputbias=net.b{1}
The current network layer weights and thresholds
LayerWeights=net.LW{2,1}
Layerbias=net.b{2}
Pause
CLC
% set training parameters
Net.trainParam.show = 50;
Net.trainParam.lr = 0.05;
Net.trainParam.mc = 0.9;
Net.trainParam.epochs = 1000;
Net.trainParam.goal = 1e-3;
Pause
CLC
% call TRAINGDM algorithm to train BP network
[net, tr]=train (net, P, T);
Pause
CLC
Simulation of BP network by%
A = sim (net, P)
Calculate the simulation error
E = T - A
MSE=mse (E)
Pause
CLC
Echo off
Example 2 adopts Bayesian regularization algorithm to improve the generalization ability of BP network. In this case, we used two kinds of training methods, namely L-M algorithm (trainlm) and the Bias regularization algorithm (trainbr), is used to train the BP network, so that it can fit attached to a white noise sine sample data. Among them, the sample data can be generated as follows MATLAB statements:
Input vector: P = [-1:0.05:1];
Target vector: randn ('seed',;
T = sin (2piP) +0.1*randn (size (P));
Solution: the MATLAB program of this example is as follows:
Close all
Clear
Echo on
CLC
% NEWFF - generating a new feedforward neural network
% TRAIN -- training BP neural network
% SIM -- Simulati
