SCI一区 | MFO-CNN-LSTM-Mutilhead-Attention多变量时间序列预测(Matlab)
目录
- SCI一区 | MFO-CNN-LSTM-Mutilhead-Attention多变量时间序列预测(Matlab)
- 预测效果
- 基本介绍
- 程序设计
- 参考资料
预测效果
基本介绍
1.Matlab实现MFO-CNN-LSTM-Mutilhead-Attention飞蛾扑火算法优化卷积长短期记忆神经网络融合多头注意力机制多变量时间序列预测,要求Matlab2023版以上;
2.输入多个特征,输出单个变量,考虑历史特征的影响,多变量时间序列预测;
3.data为数据集,main.m为主程序,运行即可,所有文件放在一个文件夹;
4.命令窗口输出R2、MSE、MAE、MAPE和RMSE多指标评价;
5.飞蛾扑火算法优化学习率,神经元个数,注意力机制的键值, 卷积核个数。
程序设计
- 完整源码和数据获取方式私信博主回复MFO-CNN-LSTM-Mutilhead-Attention多变量时间序列预测(Matlab)。
layers0 = [ ...% 输入特征sequenceInputLayer([numFeatures,1,1],'name','input') %输入层设置sequenceFoldingLayer('name','fold') %使用序列折叠层对图像序列的时间步长进行独立的卷积运算。% CNN特征提取convolution2dLayer([3,1],16,'Stride',[1,1],'name','conv1') %添加卷积层,64,1表示过滤器大小,10过滤器个数,Stride是垂直和水平过滤的步长batchNormalizationLayer('name','batchnorm1') % BN层,用于加速训练过程,防止梯度消失或梯度爆炸reluLayer('name','relu1') % ReLU激活层,用于保持输出的非线性性及修正梯度的问题% 池化层maxPooling2dLayer([2,1],'Stride',2,'Padding','same','name','maxpool') % 第一层池化层,包括3x3大小的池化窗口,步长为1,same填充方式% 展开层sequenceUnfoldingLayer('name','unfold') %独立的卷积运行结束后,要将序列恢复%平滑层flattenLayer('name','flatten')lstmLayer(25,'Outputmode','last','name','hidden1') selfAttentionLayer(2,2) %创建2个头,2个键和查询通道的自注意力层 dropoutLayer(0.1,'name','dropout_1') % Dropout层,以概率为0.2丢弃输入fullyConnectedLayer(1,'name','fullconnect') % 全连接层设置(影响输出维度)(cell层出来的输出层) %regressionLayer('Name','output') ];lgraph0 = layerGraph(layers0);
lgraph0 = connectLayers(lgraph0,'fold/miniBatchSize','unfold/miniBatchSize');
pNum = round( pop * P_percent ); % The population size of the producers for t=1:MaxIt%% 1- select_space [pop BestSol s1(t)]=select_space(fobj,pop,nPop,BestSol,low,high,dim);%% 2- search in space[pop BestSol s2(t)]=search_space(fobj,pop,BestSol,nPop,low,high);%% 3- swoop[pop BestSol s3(t)]=swoop(fobj,pop,BestSol,nPop,low,high);Convergence_curve(t)=BestSol.cost;disp(num2str([t BestSol.cost]))ed=cputime;timep=ed-st;
end
function [pop BestSol s1]=select_space(fobj,pop,npop,BestSol,low,high,dim)
Mean=mean(pop.pos);
% Empty Structure for Individuals
empty_individual.pos = [];
empty_individual.cost = [];
lm= 2;
s1=0;
for i=1:npopnewsol=empty_individual;newsol.pos= BestSol.pos+ lm*rand(1,dim).*(Mean - pop.pos(i,:));newsol.pos = max(newsol.pos, low);newsol.pos = min(newsol.pos, high);newsol.cost=fobj(newsol.pos);if newsol.cost<pop.cost(i)pop.pos(i,:) = newsol.pos;pop.cost(i)= newsol.cost;s1=s1+1;if pop.cost(i) < BestSol.costBestSol.pos= pop.pos(i,:);BestSol.cost=pop.cost(i); endend
end
参考资料
[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