Time series prediction | MATLAB implements WOA-CNN-GRU whale algorithm to optimize convolution gated recurrent unit time series prediction

Time series prediction | MATLAB implements WOA-CNN-GRU whale algorithm to optimize convolution gated recurrent unit time series prediction

predictive effect

insert image description here
insert image description here

insert image description here
insert image description here
insert image description here
insert image description here

insert image description here
insert image description here
insert image description here

basic introduction

Time series prediction | MATLAB implements WOA-CNN-GRU whale algorithm to optimize convolution gated recurrent unit time series prediction, and the operating environment is Matlab2020b and above. Optimize regularization rate, learning rate, number of hidden layer units.
1. MATLAB implements WOA-CNN-GRU whale algorithm to optimize convolution gated recurrent unit time series prediction
2. Univariate time series prediction;
3. Multi-index evaluation, evaluation indicators include: R2, MAE, MSE, RMSE, etc., code quality Extremely high;
4. Whale algorithm optimization parameters are: learning rate, hidden layer nodes, regularization parameters;
5. Excel data, easy to replace, operating environment 2020 and above.

Model description

The WOA-CNN-GRU Whale Algorithm is a predictive method for optimizing convolutional gated recurrent unit (CNN-GRU) models. CNN-GRU is a model that combines a convolutional neural network (CNN) and a gated recurrent unit (GRU).
Whale Optimization Algorithm (Whale Optimization Algorithm, WOA) is an optimization algorithm based on whale behavior, which simulates the behavior of whales looking for food in the ocean, and has the advantages of global search ability and high convergence speed. Applying the WOA algorithm to the optimization of the CNN-GRU model can improve the prediction accuracy and robustness of the model. The basic steps of the algorithm are as follows:

  • Initialize model parameters and WOA algorithm parameters.
  • For each whale individual, the fitness value is calculated according to the current position, and the WOA algorithm parameters are updated according to the current optimal individual.
  • According to the updated parameters of the WOA algorithm, the parameters of the CNN-GRU model are optimized, and the prediction error of the model is calculated.
  • Adjust the parameters of the WOA algorithm according to the model prediction error, and optimize the parameters of the CNN-GRU model again. Repeat steps 2 to 4 until the preset stop condition is reached.
  • The advantage of this algorithm is that it combines the global search ability and high convergence speed of the WOA algorithm with the sequence modeling ability of the CNN-GRU model, which can effectively improve the prediction accuracy and robustness of the model. At the same time, the algorithm can also be applied to regression prediction problems with multiple inputs and single outputs, such as image sequence prediction and time sequence prediction.

programming

  • Complete source code and data acquisition method 1: Private message bloggers reply to WOA-CNN-GRU whale algorithm to optimize convolution gated recurrent unit time series prediction ;
  • Complete program and data download method 2 (subscribe to the "Combined Optimization" column, and at the same time get any 8 programs included in the "Combined Optimization" column, private message me after the data is subscribed): WOA-CNN-GRU Whale Algorithm Optimized Convolution Gating Loop Unit Time Series Forecasting
%%  获取最优种群
   for j = 1 : SearchAgents
       if(fitness_new(j) < GBestF)
          GBestF = fitness_new(j);
          GBestX = X_new(j, :);
       end
   end
   
%%  更新种群和适应度值
   pop_new = X_new;
   fitness = fitness_new;

%%  更新种群 
   [fitness, index] = sort(fitness);
   for j = 1 : SearchAgents
      pop_new(j, :) = pop_new(index(j), :);
   end

%%  得到优化曲线
   curve(i) = GBestF;
   avcurve(i) = sum(curve) / length(curve);
end

%%  得到最优值
Best_pos = GBestX;
Best_score = curve(end);

%%  得到最优参数
NumOfUnits       =abs(round( Best_pos(1,3)));       % 最佳神经元个数
InitialLearnRate =  Best_pos(1,2) ;% 最佳初始学习率
L2Regularization = Best_pos(1,1); % 最佳L2正则化系数
% 
inputSize = k;
outputSize = 1;  %数据输出y的维度  
%  参数设置
opts = trainingOptions('adam', ...                    % 优化算法Adam
    'MaxEpochs', 20, ...                              % 最大训练次数
    'GradientThreshold', 1, ...                       % 梯度阈值
    'InitialLearnRate', InitialLearnRate, ...         % 初始学习率
    'LearnRateSchedule', 'piecewise', ...             % 学习率调整
    'LearnRateDropPeriod', 6, ...                     % 训练次后开始调整学习率
    'LearnRateDropFactor',0.2, ...                    % 学习率调整因子
    'L2Regularization', L2Regularization, ...         % 正则化参数
    'ExecutionEnvironment', 'gpu',...                 % 训练环境
    'Verbose', 0, ...                                 % 关闭优化过程
    'SequenceLength',1,...
    'MiniBatchSize',10,...
    'Plots', 'training-progress');                    % 画出曲线

References

[1] https://blog.csdn.net/kjm13182345320/article/details/128577926?spm=1001.2014.3001.5501
[2] https://blog.csdn.net/kjm13182345320/article/details/128573597?spm=1001.2014.3001.5501

Guess you like

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