A brief introduction of BP neural network prediction algorithm
Note: Section 1.1 mainly summarizes and helps to understand the principle of BP neural network algorithm considering the influence factors, that is, the conventional TRAINING principle of BP model is explained (whether to skip according to their own knowledge). Section 1.2 begins with the BP neural network prediction model based on the influence of historical values.
When BP neural network is used for prediction, there are mainly two types of models from the perspective of input indexes to be considered:
1.1 BP neural network algorithm principle affected by relevant indicators
As shown in Figure 1, when BP is trained with the newff function of MATLAB, it can be seen that most cases are three-layer neural networks (namely, input layer, hidden layer and output layer). 1) Input layer: the input layer is equivalent to the human five senses. The five senses obtain external information, which corresponds to the input port of the neural network model in the process of receiving 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 transmitted by 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 mapping rule, also called activation function, and hiddenLayer_output is the output value of the hidden layer for the transmitted data mapping. In other words, the hidden layer maps the input influence factor data X to produce the mapped value. 3) Output layer: it can correspond to human limbs. After thinking about the information from the five senses (hidden layer mapping), the brain controls the limbs to perform actions (responding externally). Similarly, output layer of 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 neural network output layer (understood as the external execution action of human brain, such as the baby tapping the table). 4) Gradient descent algorithm: by calculating the deviation between outputLayer_output and the y value passed in by the neural network model, the algorithm is used to adjust parameters such as weight and threshold accordingly. This process, you can think of it as the baby slaps the table, misses it, adjusts its body depending on how far it misses so that the arm that is swinging again gets closer and closer to the table and hits.
Here’s another example to deepen your understanding:
The BP neural network shown in Figure 1 has an input layer, a hidden layer and an 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 obtain an accurate model by training?
From the ports strung together in the picture, one can think of a process: taking the subway. Imagine figure 1 as a subway line. One day wang went home by subway: Get on the bus at the input starting station, pass through many stations (hiddenLayer), and then find that the seat is too far (outputLayer corresponds to the current position), then Wang xx will be based on the distance from home (Target) (Error) of the current position, Return to the hiddenLayer and take the subway again (error reverse transmission, using the gradient descent algorithm to update w and b). If wang makes a mistake again, the adjustment process will be carried out again.
From the example of baby beating the table and Wang taking the subway, consider the problem: the complete training of BP needs to first input data to input, and then through the mapping of the hidden layer, the output layer gets the BP simulation value. According to the error between the simulation value and the target value, adjust the parameters, so that the simulation value constantly approaches the target value. For example, (1) infants react to external interference factors (X) and thus predict. The brain continuously adjusts the position of arms and controls the accuracy of limbs (Y and Target). (2) Wang got on the bus (X), passed through the station (predict), and kept returning to the halfway station to adjust his position and arrived home (Y and Target).
In these links, influencing factor data X and Target value data Y (Target) are involved. According to x and y, BP algorithm is used to find the rule between X and Y, and x is mapped to approximate Y. This is the role of BP neural network algorithm. One more word, all the processes mentioned above are BP model training, so though the model finally obtained is accurate in training, is the BP network found accurate and reliable? Then, we put X1 into the trained BP network to obtain the corresponding BP output value (predicted value) predicT1. By drawing and calculating the indicators such as Mse, Mape and R square, we can compare the closeness of predicT1 and Y1, so as to know whether the prediction of the model is accurate. This is the testing process of BP model, that is, to realize the prediction of data and verify the accuracy of the prediction by comparing with the actual value.
FIG. 1 structure diagram of 3-layer BP neural network
1.2 BP neural network based on the influence of historical values
Taking the power load forecasting problem as an example, the two models are distinguished. When predicting the power load within a certain period of time:
One way is to predict the load value at time T by considering the climatic factors at time T, such as the influence of air humidity X1, temperature X2 and holidays X3, etc. This is the model described in 1.1 above.
Another approach is to think that the change of power load value is related to time. For example, the power load value at t-1, T-2 and T-3 is related to the load value at t, which satisfies the formula Y (t)=F(y(t-1), Y (t-2),y(t-3)). When BP neural network is used to train the model, the influencing factor values input into the neural network are historical load values Y (t-1), Y (T-2),y(t-3). In particular, 3 is called autoregressive order or delay. The output value given to the target in the neural network is y(t).
Second, bat algorithm
Bat Algorithm (BA) is a heuristic search algorithm based on swarm intelligence proposed by Professor Yang in 2010. It is an effective method to search for global optimal solutions. The algorithm is an iterative optimization technique, which initializes into a group of random solutions, searches for the optimal solution through iteration, and generates new local solutions around the optimal solution by random flight, thus strengthening the local search. Compared with other algorithms,BA is far superior in accuracy and effectiveness, and there are not many parameters to be adjusted.
BA algorithm is a random search algorithm that simulates bats using sonar to detect prey and avoid obstacles in nature. That is, it simulates bats’ basic detection and positioning ability of obstacles or prey by using ultrasonic wave and connects it with target optimization function. The bionic principle of BA algorithm maps bat individuals with population size to NP feasible solutions in the D-dimensional problem space, simulates the optimization process and search as the movement process of bat individuals in the population and search for prey, and uses the fitness function value of solving the problem to measure the advantages and disadvantages of bat positions. The process of survival of the fittest is analogous to an iterative process in which the good feasible solution replaces the bad feasible solution in the optimization and search process. In the bat search algorithm, in order to simulate the bat to detect prey and avoid obstacles, the following three approximate or idealized rules should be assumed:
1) All bats use echolocation to sense distance, and they have an ingenious way of distinguishing between prey and background obstacles. 2) Bats fly randomly at position Xi at speed VI and search for prey with fixed frequency fmin, variable wavelength λ and volume A0. The bat automatically adjusts the pulse wavelength (or frequency) and the pulse emissivity according to its proximity to the target. R belongs to [0,1]. 3) although the volume changes in various ways, in the bat algorithm, it is assumed that the volume A changes from A maximum A0(integer) to A fixed minimum Amin:
Three, part of the code
function [best,fmin,N_iter]=bat_algorithm(para) % Display help help bat_algorithm.m % Default parameters if nargin<1, Para = 0.25 0.5 [10]; end n=para(1); % Population size, typically 10 to 25 A=para(2); % Loudness (constant or decreasing) r=para(3); % Pulse rate (constant or decreasing) % This frequency range determines the scalings Qmin=0; % Frequency minimum Qmax=2; % Frequency maximum % Iteration parameters tol=10^(-5); % Stop tolerance N_iter=0; % Total number of function evaluations % Dimension of the search variables d=5; % Initial arrays Q=zeros(n,1); % Frequency v=zeros(n,d); % Velocities % Initialize the population/solutions for i=1:n, Sol(i,:)=randn(1,d); Fitness(i)=Fun(Sol(i,:)); end % Find the current best [fmin,I]=min(Fitness); best=Sol(I,:); % ====================================================== % % Note: As this is a demo, here we did not implement the % % reduction of loudness and increase of emission rates. % % Interested readers can do some parametric studies % % and also implementation various changes of A and r etc % % ====================================================== % % Start the iterations -- Bat Algorithm while (fmin>tol) % Loop over all bats/solutions for i=1:n, Q(i)=Qmin+(Qmin-Qmax)*rand; v(i,:)=v(i,:)+(Sol(i,:)-best)*Q(i); S(i,:)=Sol(i,:)+v(i,:); % Pulse rate if rand>r S(I,:)=best+0.01*randn(1,d); end % Evaluate new solutions Fnew=Fun(S(i,:)); % If the solution improves or not too loudness if (Fnew<=Fitness(i)) & (rand<A) , Sol(i,:)=S(i,:); Fitness(i)=Fnew; end % Update the current best if Fnew<=fmin, best=S(i,:); fmin=Fnew; end end N_iter=N_iter+n; end % Output/display disp(['Number of evaluations: ',num2str(N_iter)]); disp(['Best =',num2str(best),' fmin=',num2str(fmin)]); % Objective function -- Rosenbrock's 3D function function z=Fun(u) Z = (1 - u (1)) ^ 2 + 100 * (u (2), u (1) ^ 2) ^ 2 + (1 - u (3)) ^ 2 + (u (4) - 2) ^ 2 + (u (5) - 0.4) ^ 2; %%%%% ============ end ====================================Copy the code
4. Simulation results
FIG. 2 Convergence curve of bat algorithm
The following table shows the test statistics
The test results
Test set accuracy rate
Correct rate of training set
BP neural network
100%
95%
BA-BP
100%
99.8%
Five, reference and code private message blogger
- (^) (wc) yooooo) us/d2lraS8lRTg…) X. S. Yang, A New Metaheuristic Bat-Inspired Algorithm, in: Nature Inspired Cooperative Strategies for Optimization (NISCO 2010), Studies in Computational Intelligence, Springer Berlin, 284, Springer, 65-74 (2010). arxiv.org/abs/1004.41…
- (^) (wc) yooooo) us/d2lraS8lRTg…) J. D. Altringham, Bats: Biology and Behaviour, Oxford University Press, (1996).
- (^) (wc) yooooo) us/d2lraS8lRTg…) P. Richardson, Bats. Natural History Museum, London, (2008)
- (^) (wc) yooooo) us/d2lraS8lRTg…) X. S. Yang and A. H. Gandomi, Bat algorithm: a novel approach for global engineering optimization, Engineering Computations, Vol. 29, No. 5, pp. 464-483 (2012).
- (^) (wc) yooooo) us/d2lraS8lRTg…) S. Mishra, K. Shaw, D. Mishra, A new metaheuristic classification approach for microarray data,Procedia Technology, Vol. 4, pp. 802-806 (2012).
- (^) (wc) yooooo) us/d2lraS8lRTg…) K. Khan and A. Sahai, A comparison of BA, GA, PSO, BP and LM for training feed forward neural networks in e-learning context, Int. J. Intelligent Systems and Applications (IJISA), Vol. 4, No. 7, pp. 23-29 (2012).