1.算法运行效果图预览
2.算法运行软件版本
matlab2022a
3.算法理论概述
CNN-GRU-Attention模型结合了卷积神经网络(CNN)、门控循环单元(GRU)和注意力机制(Attention)来进行时间序列数据的回归预测。CNN用于提取时间序列的局部特征,GRU用于捕获时间序列的长期依赖关系,而注意力机制则用于在预测时强调重要的时间步。
3.1 CNN(卷积神经网络)部分
在时间序列回归任务中,CNN用于捕获局部特征和模式:
3.2 GRU(门控循环单元)部分
GRU用于捕捉时间序列的长期依赖关系:
3.3 Attention机制部分
最后,通过反向传播算法调整所有参数以最小化预测误差,并在整个训练集上迭代优化模型。
4.部分核心程序
layers = func_model(Dim);
%设置
%迭代次数
%学习率为0.001
options = trainingOptions('adam', ...
'MaxEpochs', 1500, ...
'InitialLearnRate', 1e-4, ...
'LearnRateSchedule', 'piecewise', ...
'LearnRateDropFactor', 0.1, ...
'LearnRateDropPeriod', 1000, ...
'Shuffle', 'every-epoch', ...
'Plots', 'training-progress', ...
'Verbose', false);
%训练
Net = trainNetwork(Nsp_train2, NTsp_train, layers, options);
figure
subplot(211);
plot(1: Num1, Tat_train,'-bs',...
'LineWidth',1,...
'MarkerSize',6,...
'MarkerEdgeColor','k',...
'MarkerFaceColor',[0.9,0.0,0.0]);
hold on
plot(1: Num1, T_sim1,'g',...
'LineWidth',2,...
'MarkerSize',6,...
'MarkerEdgeColor','k',...
'MarkerFaceColor',[0.9,0.9,0.0]);
legend('真实值', '预测值')
xlabel('预测样本')
ylabel('预测结果')
grid on
subplot(212);
plot(1: Num1, Tat_train-T_sim1','-bs',...
'LineWidth',1,...
'MarkerSize',6,...
'MarkerEdgeColor','k',...
'MarkerFaceColor',[0.9,0.0,0.0]);
legend('真实值', '预测值')
xlabel('预测样本')
ylabel('预测误差')
grid on
ylim([-50,50]);
figure
subplot(211);
plot(1: Num2, Tat_test,'-bs',...
'LineWidth',1,...
'MarkerSize',6,...
'MarkerEdgeColor','k',...
'MarkerFaceColor',[0.9,0.0,0.0]);
hold on
plot(1: Num2, T_sim2,'g',...
'LineWidth',2,...
'MarkerSize',6,...
'MarkerEdgeColor','k',...
'MarkerFaceColor',[0.9,0.9,0.0]);
legend('真实值', '预测值')
xlabel('测试样本')
ylabel('测试结果')
grid on
subplot(212);
plot(1: Num2, Tat_test-T_sim2','-bs',...
'LineWidth',1,...
'MarkerSize',6,...
'MarkerEdgeColor','k',...
'MarkerFaceColor',[0.9,0.0,0.0]);
legend('真实值', '预测值')
xlabel('预测样本')
ylabel('预测误差')
grid on
ylim([-50,50]);