分类预测 | MATLAB实现基于Attention-GRU的数据多特征分类预测(门控循环单元融合注意力机制分类预测,含混淆矩阵图、分类图)
目录
- 分类预测 | MATLAB实现基于Attention-GRU的数据多特征分类预测(门控循环单元融合注意力机制分类预测,含混淆矩阵图、分类图)
- 效果一览
- 基本介绍
- 程序设计
- 参考资料
效果一览
基本介绍
分类预测 | MATLAB实现基于Attention-GRU的数据多特征分类预测(门控循环单元融合注意力机制分类预测,含混淆矩阵图、分类图)
程序设计
- 完整程序和数据私信博主回复:Attention-GRU的数据多特征分类预测
%% 获取GRU网络权重
grubias = params.gru.bias;
gruweight = params.gru.weights;
%% 同一个epoch中,不同Batch间的state是传递的,但不学习
h0 = state.gru.h0;
[GRU_Y, h0] = gru(p_train, h0, gruweight, grurecurrentWeights, grubias);%% 注意力参数
Attentionweight = params.attention.weight; % 计算得分权重
Ht = GRU_Y(:, :, end); % 参考向量
num_time = size(GRU_Y, 3); % 时间尺度%% 注意力得分
socre = dlarray;
for i = 1: num_time - 1A = extractdata(squeeze(GRU_Y(:, :, i)));A = repmat(A, [1, 1, num_hidden]);end%% 注意力得分
a = sigmoid(socre);
Vt = 0;
for i = 1: num_time - 1Vt = Vt + a(i, :) .* GRU_Y(:, :, i);
end%% 注意力机制
bias1 = params.attenout.bias1;
bias2 = params.attenout.bias2;
weight1 = params.attenout.weight1;
weight2 = params.attenout.weight2;%% Attention输出
weight1 = params.attenout.weight1;
bias1 = params.attenout.bias1;
weight2 = params.attenout.weight2;
bias2 = params.attenout.bias2;
Hthat = fullyconnect(Vt,weight1,bias1) + fullyconnect(Ht,weight2,bias2);%% 全连接层前置层(降维)
LastWeight = params.fullyconnect.weight1;
LastBias = params.fullyconnect.bias1 ;
FullyconnectInput = fullyconnect(Hthat,LastWeight,LastBias);
FullyconnectInput = relu(FullyconnectInput);
参考资料
[1] https://blog.csdn.net/kjm13182345320/article/details/128163536?spm=1001.2014.3001.5502
[2] https://blog.csdn.net/kjm13182345320/article/details/128151206?spm=1001.2014.3001.5502