目录
Matlab基于QRCNN-Attention多变量时序预测 基于分位数回归的卷积神经网络结合注意力机制的多变量时序预测
效果分析
基本介绍
QRCNN-Attention多变量时序预测 基于分位数回归的卷积神经网络结合注意力机制的多变量时序预测。运行环境matlab2021及以上
直接替换Excel数据即可用!注释清晰,适合新手小白~
订阅专栏只能获取专栏内一份代码。
程序设计
function pimwp = PINAW(T_sim, T_train)
%% 矩阵转置
if size(T_sim, 1) ~= size(T_train, 1)
T_sim = T_sim';
end
%% 区间平均宽度百分比
pimwp = 1 / length(T_train) * sum((T_sim(:, end) - T_sim(:, 1))...
./ (max(T_train)-min(T_train)));
end
function [in,out]=data_process(data,num)
% 采用1-num作为输入 第num+1作为输出
n=length(data)-num;
for i=1:n
x(i,:)=data(i:i+num);
end
in=x(:,1:end-1);
out=x(:,end);
function [mae,rmse,mape,error]=calc_error(x1,x2)
error=x2-x1; %计算误差
rmse=sqrt(mean(error.^2));
disp(['1.均方差(MSE):',num2str(mse(x1-x2))])
disp(['2.根均方差(RMSE):',num2str(rmse)])
mae=mean(abs(error));
disp(['3.平均绝对误差(MAE):',num2str(mae)])
mape=mean(abs(error)./x1);
disp(['4.平均相对百分误差(MAPE):',num2str(mape*100),'%'])
Rsq1 = 1 - sum((x1 - x2).^2)/sum((x1 - mean(x2)).^2);
disp(['5.R2:',num2str(Rsq1*100),'%'])
end
classdef spatialDropoutLayer < nnet.layer.Layer & nnet.layer.Formattable
% Example custom spatial dropout layer.
properties
DropoutFactor
end
methods
function layer = spatialDropoutLayer(dropoutFactor,NameValueArgs)
% layer = spatialDropoutLayer creates a spatial dropout layer
% with dropout factor 0.02;
%
% layer = spatialDropoutLayer(dropoutProb) creates a spatial
% dropout layer with the specified probability.
%
% layer = spatialDropoutLayer(__,Name=name) also specifies the
% layer name using any of the previous syntaxes.
% Parse input arguments.
arguments
dropoutFactor = 0.02;
NameValueArgs.Name = ""
end
name = NameValueArgs.Name;
% Set layer properties.
layer.Name = name;
layer.Description = "Spatial dropout with factor " + dropoutFactor;
layer.Type = "Spatial Dropout";
layer.DropoutFactor = dropoutFactor;
end
function Z = predict(layer, X)
% Forward input data through the layer at prediction time and
% output the result.
%
% Inputs:
% layer - Layer to forward propagate through
% X - Input data
% Output:
% Z - Output of layer forward function
% At prediction time, the output is unchanged.
Z = X;
end
function Z = forward(layer, X)
% Forward input data through the layer at training
% time and output the result and a memory value.
%
% Inputs:
% layer - Layer to forward propagate through
% X - Input data
% Output:
% Z - Output of layer forward function
dropoutFactor = layer.DropoutFactor;
% Mask dimensions.
fmt = dims(X);
maskSize = size(X);
maskSize(ismember(fmt,'ST')) = 1;
% Create mask.
dropoutScaleFactor = single(1 - dropoutFactor);
dropoutMask = (rand(maskSize,'like',X) > dropoutFactor) / dropoutScaleFactor;
% Dropout.
Z = X .* dropoutMask;
end
end
end
参考资料
标签:function,QRCNN,layer,end,变量,时序,data,dropoutFactor From: https://blog.csdn.net/m0_57362105/article/details/144669943[1] https://blog.csdn.net/m0_57362105/article/details/128364733?spm=1001.2014.3001.5501
[2] https://blog.csdn.net/m0_57362105/article/details/128327690?spm=1001.2014.3001.5502