BP neural network matlab for deep learning

Experience, environment and heredity make you who you are, whether it is good or bad, you have to cultivate your own garden; whether it is good or bad, you have to play the strings of your life - Carnegie

1. Overview of BP neural network

The BP neural network is the backpropagation algorithm, which is a neural network in which the error backpropagates the input layer. BP neural network is an information processing system that simulates the structure and function of the human brain and is researched through mathematical and physical methods. The neural network has many nodes called neurons, each neuron has its own independent function and structure, each neuron is composed of multiple neurons, and these neurons are connected and interact with each other. When the data is input into the neural network, it will spread among the nodes, and then each node will process the data. Therefore, the BP neural network has a strong self-organization ability, and the network structure is simple and the convergence speed is fast.

A neural network is a complex mathematical model. A neural network is composed of many neurons, and the neurons are connected by weights. The model structure of the neurons is shown in the figure:

Each neuron has N inputs Xi, these inputs are transmitted by the weight W connection, and all the inputs received by the neuron

2. BP neural network topology

The BP neural network model can be regarded as a supervised self-learning training model. The training process mainly has three layers. The input and output layers obviously show a single-layer structure, while the other hidden layer will determine the structure according to the data characteristics and system requirements. . The neurons in the input layer, hidden layer, and output layer are all connected to each other. First, after the input layer gets the data samples, the number of neurons is determined, and then the information is passed to the hidden layer. The hidden layer will adjust and convert the incoming input parameters, and transfer the information to Input to the output layer, and finally output the comparison result of the layer. If it is not correct, it will return to adjust the weight and threshold of the neuron. If it is correct, it will output the result. The neural network topology is as follows:

There are two processes in the learning of neural networks, namely forward propagation and back propagation, which will not be introduced in detail here.

3. BP neural network algorithm flow

In order to successfully build a model of a mature BP neural network algorithm, we must first determine the number of neurons contained in the input layer and output layer. The number of input layers is generally the number of sample indicators in the data set, the number of output neurons is generally the number of output categories, and the number of hidden layers is determined according to some methods, such as empirical functions. The next step is to calculate the error. According to the calculated error between the predicted output value and the actual value, if the calculated error fails to meet the set requirements, it is required to return to the hidden layer for back propagation. According to the loss function calculation, the reverse Readjust the weights and thresholds until the error meets the requirements. The algorithm flow of BP neural network is as follows:

Note: Different weights and thresholds will affect the accuracy of the BP neural network algorithm.

4. Matlab code implementation

%%  导入数据
data1= xlsread('data.xlsx');
  • Import your own data first

%确定隐含层节点个数
%采用经验公式hid=sqrt(m+n)+a,m为输入层节点个数,n为输出层节点个数,a一般取为1-10之间的整数
mse=1e+5; %初始化最小误差
for hid=fix(sqrt(M+N))+1:fix(sqrt(M+N))+10 
end
  • Here is the definition for the hidden layer

%%  创建网络
net = newff(p_train, t_train,hiddennum
%%  设置训练参数
net.trainParam.epochs = 100;     % 迭代次数 
net.trainParam.goal = 1e-6;       % 误差阈值
net.trainParam.lr = 0.01;         % 学习率

%%  训练网络
net = train(net, p_train, t_train);
Finally, calculate the relevant evaluation indicators , see the link: http://t.csdn.cn/spqNh

Guess you like

Origin blog.csdn.net/a__12345_/article/details/129157806