Sparrow search algorithm optimization bilstm (time series forecasting)

1. Algorithm Thought of Sparrow Search Algorithm

1.1 Algorithm source

The Sparrow Search Algorithm (SSA) is a new type of swarm intelligence optimization algorithm, which was proposed in 2020 and is mainly inspired by the foraging behavior and anti-predation behavior of sparrows. Its journal is: A novel swarm intelligence optimization approach: sparrow search algorithm https://www.tandfonline.com/doi/full/10.1080/21642583.2019.1708830. The following content is explained and expanded based on this article.

Note (In the following pictures, @mu_54176616 is the name of this account before it was renamed)

1.2 Characteristics of bird populations

       Sparrows are generally gregarious birds and come in many species. They are found in most parts of the world and prefer to live where humans live. Furthermore, they are omnivorous birds that feed mainly on the seeds of grains or weeds. As we all know, sparrows are common resident birds. Compared to many other small birds, house sparrows are very intelligent and have a strong memory.

      Research has shown that individuals monitor the behavior of others in a group. At the same time, aggressors in flocks wanting to increase their own predation rates are used to compete for food resources from high-intake mates .

      Individual energy reserves may play an important role when sparrows choose different foraging strategies, with sparrows with low energy reserves searching more. It is worth mentioning that birds located on the outskirts of the population are more vulnerable to predators and are constantly trying to gain a better position. Note that animals in the center may move closer to their neighbors to minimize their danger zone. We also know that all sparrows display a natural instinct to be curious about all things, and at the same time they are always on the alert.

1.3 Six Principles

The original text gives six rules:

1. In the whole population, explorers usually have high energy reserves and are responsible for searching for food-rich areas, providing all followers with areas and directions for foraging. In the algorithm, the level of energy reserve is closely related to the individual fitness value of the sparrow.

2. Once the sparrow finds a natural enemy, it will make a chirp as an alarm signal. When the alarm value is greater than the safe value, the explorer will guide the followers to other safe areas for food.

3. The identity of the sparrow is defined in the algorithm according to whether it can find better food. Although the identity of the sparrow may change at any time, the proportion of explorers and followers in the population remains unchanged.

4. Sparrows with higher energy reserves will act as explorers. In order to gain more energy, it is possible for followers with lower energy to fly elsewhere to forage.

5. During the foraging process, followers can always follow the explorers with higher energy reserves to forage. In order to increase their predation rate, some individuals eat from the bowl and look into the pot. They may monitor the explorers and compete for more food resources.

6. When the natural enemy poses a certain threat, the sparrows at the edge of the group will quickly move to a safe area in order to obtain a better position, while the sparrows at the middle of the group will move randomly.

1.4 Mathematical Model

During each iteration, the finder's location updates are described as follows :

Among them, Xij  is the individual position of the sparrow, i  is the current iteration number, itermax  is the maximum iteration number; α is a random number in [0,1]; R 2 ( R 2 ∈ [0,1]) , ST  ( ST  ∈ [ 0.5,1]) are warning value and safety value respectively; Q  is a random number obeying normal distribution; is a 1×d matrix, in which each element is 1.

When R 2 < ST  , it means that there are no natural enemies around, and the explorer can conduct a global search. If R 2 ≥ ST  it means that some sparrows have found the predator, and all sparrows should take related actions. As mentioned earlier, during the foraging process, some followers will always monitor the explorer. Once the explorers find better food, they will immediately leave their current position to compete for food. The food is immediately available if they win the competition, and the follower's position is updated as follows:

Among them, Xp is the position of the optimal explorer, Xworst  is the current global worst position; n is the population size. A is a 1×d matrix, each element has a random amplitude of 1 or -1,and A += A T( AA T)-1,when > n/ 2, this indicates that the fitness value is low The i - th joiner has no food and is very hungry. At this time, he needs to fly to other places for food to obtain more energy.

When aware of danger, sparrow populations engage in anti-predation behavior:

2.bilstm neural network

       Due to the trend , periodicity, randomness or comprehensiveness of the time series, the traditional time series algorithm may not be able to perform well. The LSTM neural network has a memory function and is basically a recurrent neural network that can handle long-term dependencies . We can use bilstm for time series forecasting. The advantage of this process is that bilstm can handle the impact of the past on the future and the impact of the future on the future. At the same time, the neural network fitting process does not need to consider overly complicated factors such as difference, stability, etc. , because the network can adaptively adjust the weights.

       The full name of LSTM is Long Short-Term Memory, which is a type of RNN (Recurrent Neural Network). When calculating each h, three control switches are added inside the LSTM: forget gate, input gate, and output gate. Through the switch of these three gates, the information of the previous text can be selectively retained, which can solve the problem of gradient explosion and disappearance, and can process longer text data.

An LSTM cell

        bilstm can be regarded as a two-layer neural network. One layer performs forward training on the data, and the other layer performs reverse training on the data, and sums the results as vectors.

      Since the learning materials of bilstm are already very comprehensive on the Internet, here is only the code:

     In MATLAB, the bilstm neural network can be defined as the following structure:

numFeatures = size(XTrain,1);%输入节点数

    numResponses = size(YTrain,1);%输出节点数

    miniBatchSize  %batchsize

    numHiddenUnits1

    numHiddenUnits2

    maxEpochs

    learning_rate

    layers = [ ...

        sequenceInputLayer(numFeatures)

Bilstm的layer层

        fullyConnectedLayer(numResponses)

        regressionLayer];

    options = trainingOptions('adam', ...

        'MaxEpochs',maxEpochs, ...

        'MiniBatchSize',miniBatchSize, ...

        'InitialLearnRate',learning_rate, ...

        'GradientThreshold',1, ...

        'Shuffle','every-epoch', ...

        'Verbose',true,...

        'Plots','training-progress');

3. Time series

       The time series analysis method is to predict the future development according to the past change trend, and its premise is to assume that the past of things continues into the future.

       In practical applications, we will often encounter univariate time series: electricity consumption, steam emissions, stocks, etc. For univariate time series, we can use the past few node data (lag order) to predict.

4. Sparrow search algorithm optimization bilstm

      The maximum fitting degree of the network is achieved by minimizing the loss function of bilstm. Generally, rmse is used as the loss value to judge the situation of the network.

      In this paper, wind power generation is used to predict, and the predicted results are as follows: The results of sparrow search algorithm optimization:

In this paper, the number of hidden layers, learning rate, and maxepoch of two bilstm parameters are optimized, and the lag order of the time series is 10.

The prediction results are evaluated by the mean square error (MSE) of the training set, the mean absolute error (MAE) of the training set, the mean relative percentage error (MAPE) of the training set, and the goodness of fit (R2) of the training set.

4.1  The result of optimization without sparrow search algorithm

4.2 The result of optimization using sparrow search algorithm:

Ssa-bilstm

Optimization process:

forecast result:

Creation is not easy, please give a reward

Guess you like

Origin blog.csdn.net/m0_54176616/article/details/127641855