JCR一区 | Matlab实现TTAO-CNN-BiLSTM-MATT多特征分类预测
目录
- JCR一区 | Matlab实现TTAO-CNN-BiLSTM-MATT多特征分类预测
- 分类效果
- 基本介绍
- 程序设计
- 参考资料
分类效果
基本介绍
1.Matlab实现TTAO-CNN-BiLSTM-MATT三角拓扑聚合优化器优化双向长短期记忆神经网络融合多头注意力机制多特征分类预测,TTAO-CNN-BiLSTM-Mutilhead-Attention;
多头自注意力层 (Multihead-Self-Attention):Multihead-Self-Attention多头注意力机制是一种用于模型关注输入序列中不同位置相关性的机制。它通过计算每个位置与其他位置之间的注意力权重,进而对输入序列进行加权求和。注意力能够帮助模型在处理序列数据时,对不同位置的信息进行适当的加权,从而更好地捕捉序列中的关键信息。
2.数据输入12个特征,输出4个类别,main.m是主程序,其余为函数文件,无需运行;
3.优化参数为:学习率,隐含层节点,正则化参数;
4.可视化展示分类准确率;
5.运行环境matlab2023b及以上。
程序设计
- 完整程序和数据获取方式私信博主回复Matlab实现TTAO-CNN-BiLSTM-MATT多特征分类预测。
warning off
clc;
clear
close all
%% Set the hyper parameters for unet training
options = trainingOptions('adam', ... % 优化算法Adam
'MaxEpochs', 1000, ... % 最大训练次数
'GradientThreshold', 1, ... % 梯度阈值
'InitialLearnRate', 0.001, ... % 初始学习率
'LearnRateSchedule', 'piecewise', ... % 学习率调整
'LearnRateDropPeriod',700, ... % 训练100次后开始调整学习率
'LearnRateDropFactor',0.01, ... % 学习率调整因子
'L2Regularization', 0.001, ... % 正则化参数
'ExecutionEnvironment', 'cpu',... % 训练环境
'Verbose', 1, ... % 关闭优化过程
'Plots', 'none'); % 画出曲线
% % start training
t0 = tic; %开始计时
[net,info] = trainNetwork(dsTrain, lgraph,options);
toc(t0); % 从t0开始到此处的执行时间
analyzeNetwork(net)
%% Accuracy assessment
pred = classify(net, dsTest);
accuracy=sum(test_Y==pred)/length(pred); %计算预测的确率
function [fbest,Xbest,Convergence_curve]=TTAO(PopSize,T,Low,Up,Dim,fobj)
N=floor(PopSize/3); % Initialize N/3 individuals.
X1=rand(N,Dim).*(Up-Low)+Low;
t=1;
while t<T+1
%% Formation of triangular topological units
l=9*exp(-t/T);% The size of a triangular topological unit.
for i=1:N
theta=rand(1,Dim)*pi;
h1=cos(theta);
h2=cos(theta+pi/3);
X2(i,:)=X1(i,:)+l*h1;
X3(i,:)=X1(i,:)+l*h2;
end
X2 = max(X2,Low);
X2 = min(X2,Up);
X3 = max(X3,Low);
X3 = min(X3,Up);
r1=rand;r2=rand;
X4=r1*X1+r2.*X2+(1-r1-r2)*X3;
X4 = max(X4,Low);
X4 = min(X4,Up);
for i=1:N
X1_fit(i)=fobj(X1(i,:));
X2_fit(i)=fobj(X2(i,:));
X3_fit(i)=fobj(X3(i,:));
X4_fit(i)=fobj(X4(i,:));
end
X=[X1 X2 X3 X4];
fit=[X1_fit;X2_fit;X3_fit;X4_fit];
[X_sort,index]=sort(fit);
%% Find the ptimial point and the suboptimial point in each triangular topological unit.
for i=1:N
X_best_1(i,:)=X(i,(index(1,i)-1)*Dim+1:index(1,i)*Dim);
X_best_2(i,:)=X(i,(index(2,i)-1)*Dim+1:index(2,i)*Dim);
end
best_fit_1=X_sort(1,:);
best_fit_2=X_sort(2,:);
%% Generic aggregation
for i=1:N
r=rand(1,Dim);
X_new=X_best_1;
X_new(i,:)=[];
l1=randi(N-1);
X_G(i,:)=(r.*X_best_1(i,:)+(ones(1,Dim)-r).*X_new(l1,:));
X_G(i,:) = max(X_G(i,:),Low);
X_G(i,:) = min(X_G(i,:),Up);
X_fit_G(i)=fobj(X_G(i,:));
if X_fit_G(i)<best_fit_1(i)
X_best_1(i,:)=X_G(i,:);
best_fit_1(i)=X_fit_G(i);
elseif X_fit_G(i)<best_fit_2(i)
X_best_2(i,:)=X_G(i,:);
end
end
%% Local aggregation
for i=1:N
a=(exp(1)-(exp(1))^3)/(T-1);
b=(exp(1))^3-a;
alpha=log(a*t+b);
X_C(i,1:Dim)=X_best_1(i,1:Dim)+alpha*(X_best_1(i,1:Dim)-X_best_2(i,1:Dim));
X_C(i,:) = max(X_C(i,:),Low);
X_C(i,:) = min(X_C(i,:),Up);
X_fit_C(i)=fobj(X_C(i,:));
if X_fit_C(i)<best_fit_1(i)
X_best_1(i,:)=X_C(i,:);
best_fit_1(i)=X_fit_C(i);
end
end
%%
N00=PopSize-N*3;
if N00~=0
X00=rand(PopSize-N*3,Dim).*(Up-Low)+Low;
for i=1:N00
X00_fit=fobj(X00(i,:));
end
X_1_0=[X_best_1;X00];
X_1_0_fit=[best_fit_1,X00_fit];
[~,index01]=sort(X_1_0_fit);
X_best_1=X_1_0(index01(1:N),:);
best_fit_1=X_1_0_fit(index01(1:N));
end
X1=X_best_1;
%% The first N/3 individuals serve as the initial population for the next iteration.
[~,index1]=min(best_fit_1);
Xbest=X1(index1,:);
fbest=best_fit_1(index1);
Convergence_curve(t)=fbest;
t = t + 1;
end
参考资料
[1] https://blog.csdn.net/kjm13182345320/category_11799242.html?spm=1001.2014.3001.5482
[2] https://blog.csdn.net/kjm13182345320/article/details/124571691