MATLAB实现贝叶斯优化CNN-LSTM(卷积双向长短期记忆神经网络)时间序列预测,Bayes-CNN-LSTM模型股票价格预测
%% 搭建CNN模型
rng('default');
inputSize = 1;
numEpochs = 200;
batchSize = 16;
nTraining = length(label);
% CONV -> ReLU -> MAXPOOL -> FC -> DROPOUT -> FC -> SOFTMAX
layers = [ ...
sequenceInputLayer(inputSize)
convolution1dLayer(5,100,'Padding',2,'Stride', 1) % 卷积层 1
batchNormalizationLayer;
reluLayer(); % ReLU 层 1
convolution1dLayer(5,70,'Padding',2,'Stride', 1); % 卷积层 2
batchNormalizationLayer;
maxPooling1dLayer(1,'Stride',1); % 最大池化 池化层 1
convolution1dLayer(3,50,'Padding',1,'Stride', 1); % 卷积层 3
reluLayer(); % ReLU 层 3
maxPooling1dLayer(1,'Stride',1);
convolution1dLayer(3,40,'Padding',1,'Stride', 1); % 卷积层 4
reluLayer(); % ReLU 层 2
maxPooling1dLayer(1,'Stride',1); % 最大池化 池化层 1
fullyConnectedLayer(1,'Name','fc1')
regressionLayer]
options = trainingOptions('adam',...
'InitialLearnRate',1e-3,...% 学习率
'MiniBatchSize', batchSize, ...
'MaxEpochs',numEpochs);
[net,info1] = trainNetwork(input_train,output_train,layers,options);
%% 提取特征
fLayer = 'fc1';
trainingFeatures = activations(net, input_train, fLayer, ...
'MiniBatchSize', 16, 'OutputAs', 'channels');
trainingFeatures=cell2mat(trainingFeatures);
for i=1:length(trainingFeatures)
TF{i}=double(trainingFeatures(:,i));
end
%% 搭建LSTM模型
inputSize = 1;
numHiddenUnits = 100;
layers = [ ...
sequenceInputLayer(inputSize)
lstmLayer(numHiddenUnits,'OutputMode','last')
lstmLayer(numHiddenUnits-30)
lstmLayer(numHiddenUnits-60)
fullyConnectedLayer(1)
regressionLayer]
options = trainingOptions('adam',...
'InitialLearnRate',1e-3,...% 学习率
'MiniBatchSize', 8, ...
'MaxEpochs',50, ...
'Plots','training-progress');
[net1,info1] = trainNetwork(TF,output_train',layers,options);
%% 测试集
% 测试集提取特征
testingFeatures = activations(net, input_test, fLayer, ...
'MiniBatchSize', 8, 'OutputAs', 'channels');
testingFeatures=cell2mat(testingFeatures);
for i=1:length(testingFeatures)
TFT{i}=double(testingFeatures(:,i));
end
YPred = predict(net1,TFT);
YPred=mapminmax('reverse',YPred,yopt);
贝叶斯优化可以充分利用历史调优信息,减少不必要的目标函数评估,并改进参数搜索效率。在模型训练过程中,使用ADAM优化算法进一步优化网络权重参数,使得预测结果更准确。提出的基于超参数的优化搜索方案结合股票预测应采用CNN-LSTM模型,选用的模型具有更高的预测精度和泛化能力。
[1] https://blog.csdn.net/kjm13182345320/article/details/127261869?spm=1001.2014.3001.5501
[2] https://blog.csdn.net/kjm13182345320/article/details/127261869?spm=1001.2014.3001.5501
[3] G. W. Jiao, and C. Hu, G: Gun barrel life evaluation and prediction, J. Ordnance Equip.Eng. 39, 66 (2018).
[4] M. T. Li et al., Barrel life prediction method based on inner surface melting layer theory,J.Gun Launch Control, 5–8 (2009).