Multi-dimensional time series | MATLAB implements SSA-GRU Sparrow algorithm to optimize gated cyclic unit multi-variable time series prediction

Multi-dimensional time series | MATLAB implements SSA-GRU Sparrow algorithm to optimize gated cyclic unit multi-variable time series prediction

Prediction effect

Insert image description here
Insert image description here
Insert image description here

basic introduction

1. MATLAB implements SSA-GRU Sparrow algorithm to optimize gated cyclic unit multi-variable time series prediction (complete source code and data)
2. Sparrow algorithm optimization parameters are the number of hidden layer nodes, the maximum number of training times, and the initial learning rate parameter.
3. Code features: parametric programming, parameters can be easily changed, code programming ideas are clear, and comments are detailed.

The Sparrow Search Algorithm (SSA) was proposed in 2020. SSA was mainly inspired by the foraging behavior and anti-predation behavior of sparrows. This algorithm is relatively novel and has the advantages of strong optimization ability and fast convergence speed. To establish a mathematical model of the sparrow search algorithm, the main rules are as follows:
(1) The discoverer usually has a high energy reserve and is responsible for searching for an area with rich food in the entire population, providing a foraging area for all joiners. and direction. In the model establishment, the level of energy reserve depends on the fitness value (Fitness Value) of the sparrow individual.
(2) Once a sparrow detects a predator, the individual begins to chirp as an alarm signal. When the alarm value is greater than the safe value, the discoverer will take the joiner to other safe areas for foraging.
(3) The identities of discoverers and joiners change dynamically. As long as a better food source can be found, every sparrow can become a discoverer, but the proportion of discoverers and joiners in the entire population remains unchanged. In other words, if one sparrow becomes a discoverer, another sparrow will become a joiner.
(4) The lower the energy of the joiners, the worse their foraging position in the entire population. Some hungry joiners are more likely to fly elsewhere to forage for more energy.
(5) During the foraging process, the joiner can always search for the discoverer that provides the best food, and then obtain food from the best food or forage around the discoverer. At the same time, some joiners may constantly monitor the finder and compete for food resources in order to increase their predation rate.
(6) When aware of danger, sparrows on the edge of the group will quickly move to a safe area to obtain a better position, while sparrows in the middle of the group will move randomly to get closer to other sparrows.

programming

%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
clc;clear;close all;format compact
%%

%% 采用ssa优化
[x ,fit_gen,process]=ssaforbilstm(XTrain,YTrain,XTest,YTest);%分别对隐含层节点 训练次数与学习率寻优
%% 参数设置
pop=5; % 种群数
M=20; % 最大迭代次数
dim=4;%一共有4个参数需要优化
lb=[1   1   1  0.001];%分别对两个隐含层节点 训练次数与学习率寻优
ub=[100 100 50  0.01];%这个分别代表4个参数的上下界,比如第一个参数的范围就是1-100
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
layers = [ ...
    sequenceInputLayer(numFeatures)
    bilstmLayer(numHiddenUnits)
    fullyConnectedLayer(numResponses)
    regressionLayer];
options = trainingOptions('adam', ...
    'MaxEpochs',250, ...
    'GradientThreshold',1, ...
    'InitialLearnRate',0.005, ...
    'LearnRateSchedule','piecewise', ...
    'LearnRateDropPeriod',125, ...
    'LearnRateDropFactor',0.2, ...
    'ExecutionEnvironment','cpu', ...
    'Verbose',0, ...
    'Plots','training-progress');
%-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------   
net = trainNetwork(XTrain,YTrain,layers,options);
dataTestStandardized = (dataTest - mu) / sig;
XTest = dataTestStandardized(1:end-1);
net = predictAndUpdateState(net,XTrain);
[net,YPred] = predictAndUpdateState(net,YTrain(end));
numTimeStepsTest = numel(XTest);

References

[1] https://blog.csdn.net/article/details/126072792?spm=1001.2014.3001.5502
[2] https://blog.csdn.net/article/details/126044265?spm=1001.2014.3001.5502
[3] https://blog.csdn.net/article/details/126043107?spm=1001.2014.3001.5502

Guess you like

Origin blog.csdn.net/kjm13182345320/article/details/135258226