BP Neural Network Based on Yin-Yang Pair Algorithm Optimization (Forecasting Application) - with Code

BP Neural Network Based on Yin-Yang Pair Algorithm Optimization (Forecasting Application) - with Code


Abstract: This article mainly introduces how to optimize the BP neural network with the Yin-Yang algorithm and apply it to prediction.

1. Data introduction

There are 2000 sets of data in this case, of which 1900 sets are used for training and 100 sets are used for testing. The input of the data is 2-dimensional data, and the predicted output is 1-dimensional data

2. Yin-yang pairs optimize BP neural network

2.1 BP neural network parameter setting

The neural network parameters are as follows:

%% 构造网络结构
%创建神经网络
inputnum = 2;     %inputnum  输入层节点数 2维特征
hiddennum = 10;     %hiddennum  隐含层节点数
outputnum = 1;     %outputnum  隐含层节点数

2.2 Application of Yin-Yang Algorithm

Please refer to the principle of Yin-Yang Pair Algorithm: https://blog.csdn.net/u011835903/article/details/108295616

The parameters of the Yin-Yang algorithm are set as follows:

popsize = 20;%种群数量
Max_iteration = 20;%最大迭代次数
lb = -5;%权值阈值下边界
ub = 5;%权值阈值上边界
%  inputnum * hiddennum + hiddennum*outputnum 为阈值的个数
%  hiddennum + outputnum 为权值的个数
dim =  inputnum * hiddennum + hiddennum*outputnum + hiddennum + outputnum ;%  inputnum * hiddennum + hiddennum*outputnum维度

It should be noted here that the threshold number of the neural network is calculated as follows:

This network has 2 layers:

The number of thresholds in the first layer is: 2*10 = 20; ie inputnum * hiddennum;

The number of weights in the first layer is: 10; namely hiddennum;

The threshold number of the second layer is: 10*1 = 10; namely hiddennum * outputnum;

The number of weights in the second layer is: 1; namely outputnum;

So we can see that our optimized dimension is: inputnum * hiddennum + hiddennum*outputnum + hiddennum + outputnum = 41;

Fitness function value setting:

In this paper, the fitness function is set as follows:
fitness = argmin ( mse ( T rain Data Error ) + mes ( T est Data Error ) ) fitness = argmin(mse(TrainDataError) + mes(TestDataError))fitness=argmin(mse(TrainDataError)+m es ( T es t D a t a Error )) where TrainDataError and TestDataError are
the prediction errors of the training set and test set respectively. mse is to find the mean square error function, and the fitness function shows that the network we finally want is a network that can get better results on both the test set and the training set.

4. Test results:

From the convergence curve of the yin-yang pair algorithm, we can see that the overall error is continuously decreasing, indicating that the yin-yang pair has optimized the algorithm:

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

5. Matlab code

Guess you like

Origin blog.csdn.net/u011835903/article/details/132436477