# GWO-BP regression prediction | Matlab gray wolf optimization algorithm optimizes BP neural network regression prediction

?About the author: A Matlab simulation developer who loves scientific research. He cultivates his mind and improves his technology simultaneously. For cooperation on MATLAB projects, please send a private message.

Personal homepage: Matlab Research Studio

Personal credo: Investigate things to gain knowledge.

For more complete Matlab code and simulation customization content, click

Intelligent optimization algorithm Neural network prediction Radar communication Wireless sensor Power system

Signal processing Image processing Path planning Cellular automaton Drone

### Content introduction

In today’s information age, data prediction has become an integral part of many fields. From predictions of financial markets to weather forecasts, data predictions can help us make smarter decisions. As a commonly used data prediction model, BP neural network has achieved success in many fields.

However, BP neural network also has some problems, such as easy to fall into the local optimal solution and slow convergence speed. In order to solve these problems, we can use the gray wolf algorithm to optimize the BP neural network.

The gray wolf algorithm is an optimization algorithm based on the behavior of gray wolf groups in nature. It simulates the behavior of gray wolves in finding the best prey during hunting. By simulating the social behavior and hunting strategies of gray wolves, the gray wolf algorithm can help us find the optimal solution of the BP neural network.

Before using the gray wolf algorithm to optimize the BP neural network, we first need to build a basic BP neural network model. BP neural network is a feedforward neural network with a backpropagation algorithm, which can minimize the error between the predicted output and the actual output by adjusting weights and biases.

Once we have built the BP neural network model, we can start to optimize it using the gray wolf algorithm. First, we need to initialize a group of gray wolves and assign each gray wolf a position and a fitness value. The fitness value can be obtained by calculating the error of the BP neural network, that is, the difference between the predicted output and the actual output.

Then, we need to determine the search range of each gray wolf based on its fitness value. The higher the fitness value of the gray wolf, the larger its search range. This ensures that the gray wolf is more likely to find the optimal solution during the search process.

Next, we needed to model the social behavior and prey-finding strategies of gray wolves. The gray wolf will adjust its search direction and speed based on its location and fitness value. Through continuous iteration, the gray wolves can gradually approach the optimal solution and finally find the optimal weights and biases of the BP neural network.

During the optimization process, we can also introduce some parameters to control the search behavior of the gray wolf algorithm, such as the number of iterations, the number of gray wolf groups, etc. The selection of these parameters will directly affect the quality and efficiency of the optimization results.

By optimizing the BP neural network with the gray wolf algorithm, we can improve the accuracy and efficiency of data prediction. The gray wolf algorithm’s social behavior and prey-finding strategy can help us avoid falling into local optimal solutions, speed up convergence, and find the global optimal solution.

However, it should be noted that the gray wolf algorithm is not a universal optimization algorithm suitable for all problems. Before using the gray wolf algorithm to optimize the BP neural network, we need to conduct reasonable modeling and analysis of the problem to ensure the applicability of the gray wolf algorithm.

In short, optimizing the BP neural network based on the gray wolf algorithm can help us achieve more accurate and efficient data prediction. By simulating the social behavior and hunting strategies of gray wolves, the gray wolf algorithm can help us find the optimal solution of the BP neural network. However, before using the gray wolf algorithm to optimize the BP neural network, we need to conduct reasonable modeling and analysis of the problem to ensure the applicability of the algorithm. Only in the right problem domain can the gray wolf algorithm exert its advantages and bring us better data prediction results.

### Part of the code

```%_______________________________________________________________%
% Gray Wolf Optimizer (GWO) source codes version 1.0 %
% %
% Developed in MATLAB R2011b(7.13) %
% %
% Author and programmer: Seyedali Mirjalili %
% %
% e-Mail: [email protected] %
% [email protected] %
% %
% Homepage: http://www.alimirjalili.com %
% %
% Main paper: S. Mirjalili, S. M. Mirjalili, A. Lewis %
% Gray Wolf Optimizer, Advances in Engineering %
% Software, in press, %
% %
%____________________________________________________________%

% This function initializes the first population of search agents
function Positions=initialization(SearchAgents_no,dim,ub,lb)

Boundary_no= size(ub,2); % number of boundaries

% If the boundaries of all variables are equal and user enter a signle
% number for both ub and lb
if Boundary_no==1
Positions=rand(SearchAgents_no,dim).*(ub-lb) + lb;
end

% If each variable has a different lb and ub
if Boundary_no>1
for i=1:dim
ub_i=ub(i);
lb_i=lb(i);
Positions(:,i)=rand(SearchAgents_no,1).*(ub_i-lb_i) + lb_i;
end
end```

### References

[1] Yang Yang, Zhao Qing, Qi Lan, et al. Box culvert settlement prediction based on improved GWO-BP neural network model [J]. People’s Yellow River, 2021, 43(10):4.DOI:10.3969/j.issn. 1000-1379.2021.10.029.

[2] Yu Shuxiang, Wen Yijun. Software defect prediction model based on GWO-BP algorithm [J]. Journal of Anhui Electronic Information Vocational and Technical College, 2018, 17(6):5.DOI:CNKI:SUN:AHDJ. 0.2018-06-003.