First, BP neural network prediction algorithm introduction

Description: Section 1.1 mainly summarizes and helps to understand the BP neural network algorithm principle considering the influencing factors, that is, the routine BP model training principle explanation (can be skipped according to their own knowledge). Section 1.2 begins with the BP neural network prediction model based on the influence of historical values.

When using BP neural network for prediction, there are mainly two types of models from the perspective of input indicators considered:

1.1 BP neural network algorithm principle influenced by relevant indicators

As shown in Figure 1, when USING NEWFF function of MATLAB to train BP, it can be seen that most cases are three-layer neural network (namely input layer, hidden layer and output layer). 1) Input layer: it is equivalent to the five senses of the human being. The five senses obtain external information and correspond to the process of the input port of the neural network model to receive input data. 2) Hidden Layer: corresponding to the human brain, the brain analyzes and thinks about the data transmitted by the five senses. The hiddenLayer of the neural network maps the data X from the input Layer, which can be simply understood as a formula hiddenLayer_output=F(w*x+b). Where, w and b are weight and threshold parameters, F() is a mapping rule, also known as activation function, and hiddenLayer_output is the output value of the hidden layer to the transmitted data map. In other words, the hidden layer maps the input influence factor data X and generates the mapping value. 3) Output layer: it can correspond to human limbs. After thinking about the information from the facial features (hidden layer mapping), the brain controls the limbs to perform actions (respond to the outside). Similarly, the output layer of the BP neural network maps hiddenLayer_output again, outputLayer_output=w *hiddenLayer_output+b. Where w and B are weight and threshold parameters, and outputLayer_output is the output value (also called simulation value and predicted value) of the output layer of the neural network (understood as the external execution of the human brain, such as the baby tapping the table). 4) Gradient descent algorithm: Calculate the deviation between outputLayer_output and the y value passed in by the neural network model, and use the algorithm to adjust parameters such as weight and threshold accordingly. And what happens is, you can think of it as the baby slaps the table, misses it, adjusts its body according to how far it misses it, so that the arm that moves again gets closer and closer to the table and hits it.

Here’s another example to further understand:

Figure 1 shows the BP neural network, which has input layer, hidden layer and output layer. How does BP realize the output value outputLayer_output of the output layer through the three-layer structure, constantly approaching the given y value, so as to train an accurate model?

From the ports strung together in the picture, you can think of a process: taking a subway. Imagine figure 1 as a subway line. One day on wang’s subway ride home: When getting on the bus at the starting point of input, he passes through many stops (hiddenLayer) and finds that he overrides (outputLayer corresponds to the current position), so Wang will be informed by the distance from home (Target) of his current position (Error). Return to the subway station in the middle (hiddenLayer) and take the subway again (error is transmitted in reverse, and the gradient descent algorithm is used to update W and B). If Mr. Wang makes another mistake, the adjustment process will be carried out again.

In the case of the baby beating the table and Wang Taking the subway, consider the following question: For the complete training of BP, data needs to be passed into the input first, and then through the mapping of the hidden layer, BP simulation value is obtained at the output layer. Parameters are adjusted according to the error between the simulation value and the target value, so that the simulation value is constantly approaching the target value. For example, (1) When an infant is subjected to an external interference factor (X), he/she reacts to clap the table (Y, Target). The brain constantly adjusts the position of his/her arms to control the accuracy of his/her limbs (Y, Target). (2) Wang xx gets on (X), goes through (predict), and keeps returning to the midway to adjust his position, then arrives home (Y, Target).

In these links, the influencing factor data X and the Target value data Y (Target) are involved. According to x and Y, BP algorithm is used to seek the law existing between X and Y, so as to realize the mapping of X to approximate y, which is the function of BP neural network algorithm. By the way, all the processes mentioned above are BP model training, so although the final model training is accurate, is the rule (BP network) found accurate and reliable? Therefore, we add X1 to the trained BP network to get the corresponding BP output value (predicted value), predict1. By plotting, calculating Mse, Mape, R square and other indicators, we can compare the proximity of PREDICT1 and Y1, so as to know whether the prediction of the model is accurate. This is the test process of THE BP model, that is, to realize the prediction of the data and verify the accuracy of the prediction against the actual value.



Figure 1. 3-layer BP neural network structure

1.2 BP neural network based on historical value

Taking the power load forecasting problem as an example, the two models are distinguished. In forecasting the power load over a period of time:

One method is to predict the load value at time T by considering the climate factors at time T, such as the influence of air humidity X1, temperature x2 and holiday x3. This is the model described in 1.1 above.

Another way is to think that the change of power load value is related to time. For example, the power load value at time T-1, T-2 and T-3 is related to the load value at time T, that is, the formula Y (t)=F(Y (t-1), Y (T-2),y(T-3)) is satisfied. When BP neural network is used for training model, the influence factor values input to neural network are the historical load values Y (T-1), Y (T-2),y(T-3). In particular, 3 is called the autoregressive order or delay. The target output value given to the neural network is y(t).

Second, seagull algorithm

The seagull algorithm mainly simulates the migratory behavior and aggressive behavior of seagulls. Migration behavior is that seagulls fly from one unsuitable place to another suitable place. Migration behavior affects the global exploration ability of SOA algorithms. Aggressive behavior refers to seagulls’ aggressive foraging for food on the ground and in the water during flight, which affects the local development ability of SOA algorithms.

2. SOA algorithm process

2.1 Migration behavior (Exploration ability)

2.2 Exploitation ability

2.3 SOA algorithm process

Three, part of the code

%%% Designed and Developed by Dr. Gaurav Dhiman (http://dhimangaurav.com/) %%% function[Score,Position,Convergence]=SOA(Search_Agents,Max_iterations,Lower_bound,Upper_bound,dimension,objective) Position=zeros(1,dimension); Score=inf; Positions=init(Search_Agents,dimension,Upper_bound,Lower_bound); Convergence=zeros(1,Max_iterations); l=0; while l<Max_iterations for i=1:size(Positions,1) Flag4Upper_bound=Positions(i,:)>Upper_bound; Flag4Lower_bound=Positions(i,:)<Lower_bound; Positions(i,:)=(Positions(i,:).*(~(Flag4Upper_bound+Flag4Lower_bound)))+Upper_bound.*Flag4Upper_bound+Lower_bound.*Flag4 Lower_bound; fitness=objective(Positions(i,:)); if fitness<Score Score=fitness; Position=Positions(i,:); end end Fc=2-l*((2)/Max_iterations); for i=1:size(Positions,1) for j=1:size(Positions,2) r1=rand(); r2=rand(); A1=2*Fc*r1-Fc; C1=2*r2; b=1; ll=(Fc-1)*rand()+1; D_alphs=Fc*Positions(i,j)+A1*((Position(j)-Positions(i,j))); X1=D_alphs*exp(b.*ll).*cos(ll.*2*pi)+Position(j); Positions(i,j)=X1; end end l=l+1; Convergence(l)=Score; endCopy the code

Iv. Simulation results

FIG. 2 Convergence curve of gull algorithm

Test statistics are shown in the following table

The test results

Test set accuracy

Training set accuracy

BP neural network

100%

95%

SOA-BP

100%

99.8%

Five, references and code private message blogger

Prediction of Water Resources Demand in Ningxia Based on BP Neural Network