Time series prediction | MATLAB implements WOA-CNN-LSTM whale algorithm to optimize convolutional long short-term memory neural network time series prediction

Time series prediction | MATLAB implements WOA-CNN-LSTM whale algorithm to optimize convolutional long short-term memory neural network 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-LSTM whale algorithm to optimize convolutional long short-term memory neural network 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-LSTM whale algorithm to optimize convolutional long-term short-term memory neural network time series prediction;
2. Univariate time series prediction;
3. Multi-index evaluation, evaluation indicators include: R2, MAE, MSE, RMSE, etc., The code quality is extremely high;
4. The optimization parameters of the whale algorithm are: learning rate, hidden layer nodes, and regularization parameters;
5. Excel data, easy to replace, and the operating environment is 2020 and above.

Model description

Whale Optimization Algorithm (WOA) is an optimization algorithm based on the behavior of whale groups in nature, which can be used to solve optimization problems. The convolutional long-short-term memory neural network (CNN-LSTM) is a network structure that combines a convolutional neural network (CNN) and a long-term short-term memory neural network (LSTM), which can process sequence data and spatial data. Multiple-input single-output regression prediction refers to a regression problem in which multiple features are input and a single value is output.
The following are the steps to use the whale algorithm to optimize the CNN-LSTM network for multiple-input single-output regression prediction:
First, you need to determine the structure of the network, including convolutional layers, LSTM layers, fully connected layers, etc.
Then, a fitness function needs to be defined, which is the prediction error of the network on the training set. Here root mean square error (RMSE) can be chosen as the fitness function.
Next, the whale algorithm can be used for parameter optimization. Specifically, the parameters of the CNN-LSTM network can be used as optimization variables, the fitness function can be used as the objective function, and the whale algorithm can be used for iterative optimization until the objective function converges or reaches the preset number of iterations.
In the optimization process, it is necessary to set the parameters of the whale algorithm, including optimizing the regularization rate, learning rate, and the number of hidden layer units.
Finally, the optimized CNN-LSTM network can be used for multiple-input single-output regression prediction.
It should be noted that although the whale algorithm can be used to optimize the neural network, it is not a panacea and has limitations. When using the whale algorithm for optimization, it is necessary to adjust parameters and optimize according to specific problems to obtain better optimization results.

programming

  • Complete source code and data acquisition method 1: Private message bloggers reply to WOA-CNN-LSTM whale algorithm to optimize convolutional long-term short-term memory neural network time series prediction , and exchange programs of equal value;
  • 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, and private message me to get the data after subscription): WOA-CNN-LSTM Whale Algorithm Optimized Convolutional Long Short-Term Memory Neural network time series forecasting , only this program can be obtained outside the column.
%%  获取最优种群
   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');                    % 画出曲线

summarize

The flow of the algorithm is as follows:
data preprocessing. Preprocess the input data, such as converting card type data into numbers, normalizing, filling missing values, etc. convolutional network. The input data is processed by convolutional neural network (CNN) to extract its feature representation. LSTM network. The feature sequence extracted by the convolutional network is input into a long short-term memory neural network (LSTM) to convert it into a single output. Output the prediction results of the LSTM network.
In this algorithm, the convolutional network is used to extract the features of the input data, and the LSTM network converts the feature sequence extracted by the convolutional network into a single output and retains its time series information, so that it can better predict future results. The optimization method of this algorithm mainly focuses on two stages of convolutional network and LSTM network: convolutional network optimization. By increasing the depth and width of the convolutional network, its expressive ability can be increased, and the feature extraction ability of the input sequence can be improved. At the same time, better activation functions and regularization methods, such as ReLU and Dropout, can be used to increase the nonlinear ability and generalization ability of the network.
LSTM network optimization. By increasing the hidden layer size and number of layers of the LSTM network, its expression ability and memory ability can be increased, and the modeling ability of the input sequence can be improved. At the same time, better gating mechanism and gradient clipping methods, such as LSTM and Clip Gradient, can be used to increase the stability and generalization ability of the network.
In short, through the combination of convolutional neural network and long short-term memory neural network, the regression prediction task with multiple input and single output can be modeled and predicted. Its optimization methods mainly include adjusting model structure, optimizing loss function and optimization algorithm, fusing multiple data sources, increasing data preprocessing and enhancement, and adjusting model hyperparameters. Through these optimization methods, the predictive performance and generalization ability of the model can be improved to adapt to a wider range of application scenarios.

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/132287526