MATLAB实现BO-CNN-LSTM贝叶斯优化卷积神经网络-长短期记忆网络时间序列预测。基于贝叶斯(bayes)优化卷积神经网络-长短期记忆网络(CNN-LSTM)时间序列预测,BO-CNN-LSTM/Bayes-CNN-LSTM时间序列预测模型。
1.优化参数为:学习率,隐含层节点,正则化参数。
2.评价指标包括:R2、MAE、MSE、RMSE和MAPE等。
3.运行环境matlab2020b及以上。
%% 优化算法参数设置
%参数取值上界(学习率,隐藏层节点,正则化系数)
%% 贝叶斯优化参数范围
optimVars = [
optimizableVariable('NumOfUnits', [10, 50], 'Type', 'integer')
optimizableVariable('InitialLearnRate', [1e-3, 1], 'Transform', 'log')
optimizableVariable('L2Regularization', [1e-10, 1e-2], 'Transform', 'log')];
%% 创建混合CNN-LSTM网络架构
% 输入特征维度
numFeatures = f_;
% 输出特征维度
numResponses = 1;
FiltZise = 10;
% 创建"CNN-LSTM"模型
layers = [...
% 输入特征
sequenceInputLayer([numFeatures 1 1],'Name','input')
sequenceFoldingLayer('Name','fold')
% CNN特征提取
convolution2dLayer([FiltZise 1],32,'Padding','same','WeightsInitializer','he','Name','conv','DilationFactor',1);
batchNormalizationLayer('Name','bn')
eluLayer('Name','elu')
averagePooling2dLayer(1,'Stride',FiltZise,'Name','pool1')
% 展开层
sequenceUnfoldingLayer('Name','unfold')
% 平滑层
flattenLayer('Name','flatten')
% LSTM特征学习
lstmLayer(50,'Name','lstm1','RecurrentWeightsInitializer','He','InputWeightsInitializer','He')
% LSTM输出
lstmLayer(optVars.NumOfUnits,'OutputMode',"last",'Name','bil4','RecurrentWeightsInitializer','He','InputWeightsInitializer','He')
dropoutLayer(0.25,'Name','drop3')
% 全连接层
fullyConnectedLayer(numResponses,'Name','fc')
regressionLayer('Name','output') ];
layers = layerGraph(layers);
layers = connectLayers(layers,'fold/miniBatchSize','unfold/miniBatchSize');
%% CNNLSTM训练选项
% 批处理样本
MiniBatchSize =128;
% 最大迭代次数
MaxEpochs = 500;
options = trainingOptions( 'adam', ...
'MaxEpochs',500, ...
'GradientThreshold',1, ...
'InitialLearnRate',optVars.InitialLearnRate, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropPeriod',400, ...
'LearnRateDropFactor',0.2, ...
'L2Regularization',optVars.L2Regularization,...
'Verbose',false, ...
'Plots','none');
%% 训练混合网络
net = trainNetwork(XrTrain,YrTrain,layers,options);
[1] https://blog.csdn.net/kjm13182345320/article/details/129036772?spm=1001.2014.3001.5502
[2] https://blog.csdn.net/kjm13182345320/article/details/128690229