BP neural network optimized based on war strategy algorithm (prediction application) - with code

BP neural network optimized based on war strategy algorithm (prediction application) - with code


Abstract: This article mainly introduces how to optimize BP neural network with war strategy 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. War strategy optimization 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 war strategy algorithm

For the principle of war strategy algorithm, please refer to: https://blog.csdn.net/u011835903/article/details/126599876

The parameters of the war strategy algorithm are set as:

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 war strategy algorithm, it can be seen that the overall error is continuously decreasing, indicating that the war strategy algorithm has played an optimized role:

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/132612697