SCI一区 | Matlab实现TSOA-CNN-GRU-Mutilhead-Attention凌日优化算法优化卷积门控循环单元融合多头注意力机制多特征分类预测
目录
- SCI一区 | Matlab实现TSOA-CNN-GRU-Mutilhead-Attention凌日优化算法优化卷积门控循环单元融合多头注意力机制多特征分类预测
- 效果一览
- 基本介绍
- 模型描述
- 程序设计
- 参考资料
效果一览
基本介绍
1.【SCI一区级】TSOA-CNN-GRU-Mutilhead-Attention凌日优化算法优化卷积门控循环单元融合多头注意力机制多特征分类预测,多特征输入模型,运行环境Matlab2023b及以上;
凌日优化算法(Transit Search Optimization Algorithm,TSOA)是20228月提出的一种新颖的元启发式算法,当一颗行星经过其恒星前方时,会导致恒星的亮度微弱地下降,这被称为凌日现象。该算法基于著名的系外行星探索方法,即凌日搜索(TS)。在凌日算法中,通过研究在一定间隔内从恒星接收到的光,检查亮度的变化,如果观察到接收到的光量减少,则表明行星从恒星锋面经过。
2.MATLAB程序,多特征输入,优化了学习率、卷积核大小及隐藏层单元数等。
3.多特征输入单输出的二分类及多分类模型。程序内注释详细,直接替换数据就可以用。程序语言为matlab,程序可出分类效果图,迭代图,混淆矩阵图.
4.data为数据集,输入12个特征,分四类;main为主程序,其余为函数文件,无需运行。
5.输出指标包括优化参数、精确度、召回率、精确率、F1分数。
数据集格式:
注:程序和数据放在一个文件夹
TSOA算法的优化过程包括以下几个阶段:
星系阶段:选择搜索空间内的随机点作为星系中心,确定可居住区域,选择有最佳生存潜力的区域。
凌日阶段:重新测量从星体接收到的光线量,检测光线信号是否减少以确定是否有行星通过。
行星阶段:如果检测到凌日,确定行星的初始位置,并更新行星位置。
邻居阶段:如果未检测到凌日,分析当前星体附近可能存在的行星。
开发阶段:分析行星的特性和条件,以评估其作为生命宿主的潜力。
每个阶段的数学细节涉及复杂的方程和概率计算,模拟了在天文观测中发现和评估行星的过程。该算法的数学创新主要在于它将天文物理学中的凌日法原理和信噪比概念引入到优化问题的求解中,这一独特方法在多个基准问题上显示出了优越的性能。
模型描述
多头注意力机制(Multi-Head Attention)是一种用于处理序列数据的注意力机制的扩展形式。它通过使用多个独立的注意力头来捕捉不同方面的关注点,从而更好地捕捉序列数据中的相关性和重要性。在多变量时间序列预测中,多头注意力机制可以帮助模型对各个变量之间的关系进行建模,并从中提取有用的特征。
- 通常,在模型训练过程中需要对超参数进行优化,为模型选择一组最优的超参数,以提高预测的性能和有效性。 凭经验设置超参数会使最终确定的模型超参数组合不一定是最优的,这会影响模型网络的拟合程度及其对测试数据的泛化能力。
程序设计
- 完整程序和数据获取方式私信博主回复Matlab实现TSOA-CNN-GRU-Mutilhead-Attention凌日优化算法优化卷积门控循环单元融合多头注意力机制多特征分类预测。
%% 清空环境变量
warning off % 关闭报警信息
close all % 关闭开启的图窗
clear % 清空变量
clc % 清空命令行
rng(0) % 使训练集、和测试集的随机划分与适应度函数一致
%% 读取数据
res = xlsread('data.xlsx');
%% 分析数据
num_class = length(unique(res(:, end))); % 类别数(Excel最后一列放类别)
Numfeatures = size(res, 2) - 1; % 特征维度
num_res = size(res, 1); % 样本数(每一行,是一个样本)
num_size = 0.7; % 训练集占数据集的比例
res = res(randperm(num_res), :); % 打乱数据集(不打乱数据时,注释该行)
flag_conusion = 1; % 标志位为1,打开混淆矩阵(要求2018版本及以上)
%% 设置变量存储数据
P_train = []; P_test = [];
T_train = []; T_test = [];
%% 划分数据集
for i = 1 : num_class
mid_res = res((res(:, end) == i), :); % 循环取出不同类别的样本
mid_size = size(mid_res, 1); % 得到不同类别样本个数
mid_tiran = round(num_size * mid_size); % 得到该类别的训练样本个数
P_train = [P_train; mid_res(1: mid_tiran, 1: end - 1)]; % 训练集输入
T_train = [T_train; mid_res(1: mid_tiran, end)]; % 训练集输出
P_test = [P_test; mid_res(mid_tiran + 1: end, 1: end - 1)]; % 测试集输入
T_test = [T_test; mid_res(mid_tiran + 1: end, end)]; % 测试集输出
end
%% 数据转置
P_train = P_train'; P_test = P_test';
T_train = T_train'; T_test = T_test';
%% 优化算法参数设置
function [Bests] = TransitSearch (ObjectiveFunction,Vmin,Vmax,nV,ns,SN,maxcycle)
%% 初始化
Empty.Location = [];
Empty.Cost = inf;
Empty.Value = {};
Empty.net = {};
Empty.info = {};
Galaxy_Center = repmat (Empty, 1, 1);
region = repmat (Empty, ns*SN, 1);
selected_regions = repmat (Empty, ns, 1);
Stars = repmat (Empty, ns, 1);
Stars_sorted = zeros(ns,1);
Ranks = 1:1:ns;
Stars_Ranks = zeros(ns,1);
Luminosity = zeros(ns,1);
Star_RanksNormal = zeros(ns,1);
Distance = zeros(ns,1);
Transit0 = zeros(ns,1);
SN_P = repmat (Empty, SN, 1);
Bests=region;
if length(Vmin) ~= nV
Vmin=Vmin*ones(1,nV);
Vmax=Vmax*ones(1,nV);
end
%% 银河系阶段
% 银河系中心的初始位置
Galaxy_Center.Location = unifrnd(Vmin,Vmax,1,nV);
Galaxy_Center.Cost = ObjectiveFunction(Galaxy_Center.Location);
% 银河系居住区
for l = 1:(ns*SN)
zone = randi(2);
if zone ==1
difference = rand().*(Galaxy_Center.Location)-(unifrnd(Vmin,Vmax,1,nV));
else
difference = rand().*(Galaxy_Center.Location)+(unifrnd(Vmin,Vmax,1,nV));
end
Noise = ((rand(1,nV)).^3).*(unifrnd(Vmin,Vmax,1,nV));
region(l).Location = Galaxy_Center.Location + difference - Noise;
region(l).Location = max(region(l).Location, Vmin);
region(l).Location = min(region(l).Location, Vmax);
[region(l).Cost,region(l).Value,region(l).net,region(l).info] = ObjectiveFunction(region(l).Location);
end
% 从银河系的银河栖息区挑选恒星的百分比
[Sort,index]=sort([region.Cost]);
for i = 1:ns
selected_regions(i) = region(index(1,i));
for k = 1:SN
zone = randi(2);
if zone ==1
difference = rand().*(selected_regions(i).Location)-rand().*(unifrnd(Vmin,Vmax,1,nV));
else
difference = rand().*(selected_regions(i).Location)+rand().*(unifrnd(Vmin,Vmax,1,nV));
end
Noise = ((rand(1,nV)).^3).*(unifrnd(Vmin,Vmax,1,nV));
new.Location = selected_regions(i).Location + difference - Noise;
new.Location = max(new.Location, Vmin);
new.Location = min(new.Location, Vmax);
[new.Cost,new.Value,new.net,new.info] = ObjectiveFunction(new.Location);
if new.Cost < Stars(i).Cost
Stars(i) = new;
end
end
end
% 最佳行星的初始位置(起点:其恒星)
Best_Planets = Stars;
% 最佳星球的格式
[Sort,index]=sort([Best_Planets.Cost]);
Best_Planet = Best_Planets(index(1,1));
% 望远镜位置
Telescope.Location = unifrnd(Vmin,Vmax,1,nV);
%恒星光度的测定
for i = 1:ns
Stars_sorted(i,1) = Stars(i).Cost;
end
Stars_sorted = sort (Stars_sorted);
for i = 1:ns
for ii = 1:ns
if Stars(i).Cost == Stars_sorted(ii,1)
Stars_Ranks(i,1) = Ranks(1,ii);
Star_RanksNormal(i,1) = (Stars_Ranks(i,1))./ns;
end
end
Distance(i,1) = sum((Stars(i).Location-Telescope.Location).^2).^0.5;
Luminosity(i,1) = Star_RanksNormal(i,1)/((Distance(i,1))^2);
end
Luminosity_new = Luminosity;
Stars2 = Stars;
%% TS 算法循环
for it = 1:maxcycle
%% 过渡阶段
Transit = Transit0;
Luminosity = Luminosity_new;
for i = 1:ns
difference = (2*rand()-1).*(Stars(i).Location);
Noise = ((rand(1,nV)).^3).*(unifrnd(Vmin,Vmax,1,nV));
Stars2(i).Location = Stars(i).Location + difference - Noise;
Stars2(i).Location = max(Stars2(i).Location, Vmin);
Stars2(i).Location = min(Stars2(i).Location, Vmax);
[Stars2(i).Cost,Stars2(i).Value,Stars2(i).net,Stars2(i).info] = ObjectiveFunction(Stars2(i).Location);
end
for i = 1:ns
Stars_sorted(i,1) = Stars2(i).Cost;
end
Stars_sorted = sort (Stars_sorted);
for i = 1:ns
for ii = 1:ns
if Stars2(i).Cost == Stars_sorted(ii,1)
Stars_Ranks(i,1) = Ranks(1,ii);
Star_RanksNormal(i,1) = (Stars_Ranks(i,1))./ns;
end
end
Distance(i,1) = sum((Stars2(i).Location-Telescope.Location).^2).^0.5;
Luminosity_new(i,1) = Star_RanksNormal(i,1)/((Distance(i,1))^2);
if Luminosity_new(i,1) < Luminosity(i,1)
Transit (i,1) = 1; % Has transit been observed? 0 = No; 1 = Yes
end
end
Stars = Stars2;
%% 定位阶段(勘探)
for i = 1:ns
if Transit (i,1) == 1
% 确定行星位置
Luminosity_Ratio = Luminosity_new(i,1)/Luminosity(i,1);
Planet.Location = (rand().*Telescope.Location + Luminosity_Ratio.*Stars(i).Location)./2;
for k = 1:SN
zone = randi(3);
if zone ==1
new.Location = Planet.Location - (2*rand()-1).*(unifrnd(Vmin,Vmax,1,nV));
elseif zone ==2
new.Location = Planet.Location + (2*rand()-1).*(unifrnd(Vmin,Vmax,1,nV));
else
new.Location = Planet.Location + (2.*rand(1,nV)-1).*(unifrnd(Vmin,Vmax,1,nV));
end
new.Location = max(new.Location, Vmin);
new.Location = min(new.Location, Vmax);
SN_P(k) = new;
end
SUM = 0;
for k = 1:SN
SUM = SUM+SN_P(k).Location;
end
new.Location = SUM./SN;
[new.Cost,new.Value,new.net,new.info] = ObjectiveFunction(new.Location);
if new.Cost < Best_Planets(i).Cost
Best_Planets(i) = new;
end
else % 未观测到凌日: 邻近行星
Neighbor.Location = (rand().*Stars(i).Location + rand().*(unifrnd(Vmin,Vmax,1,nV)))./2;
for k = 1:SN
zone = randi(3);
if zone ==1
Neighbor.Location = Neighbor.Location - (2*rand()-1).*(unifrnd(Vmin,Vmax,1,nV));
elseif zone ==2
Neighbor.Location = Neighbor.Location + (2*rand()-1).*(unifrnd(Vmin,Vmax,1,nV));
else
Neighbor.Location = Neighbor.Location + (2.*rand(1,nV)-1).*(unifrnd(Vmin,Vmax,1,nV));
end
Neighbor.Location = max(Neighbor.Location, Vmin);
Neighbor.Location = min(Neighbor.Location, Vmax);
[Neighbor.Cost,Neighbor.Value,Neighbor.net,Neighbor.info] = ObjectiveFunction (Neighbor.Location);
SN_P(k) = Neighbor;
end
SUM = 0;
for k = 1:SN
SUM = SUM+SN_P(k).Location;
end
Neighbor.Location = SUM./SN;
[Neighbor.Cost,Neighbor.Value,Neighbor.net,Neighbor.info] = ObjectiveFunction (Neighbor.Location);
if Neighbor.Cost < Best_Planets(i).Cost
Best_Planets(i) = Neighbor;
end
end
end
%% 最佳行星的信号放大(探索)
for i = 1:ns
for k = 1:SN
RAND = randi(2 );
if RAND ==1
Power = randi(SN*ns);
Coefficient = 2*rand();
Noise = ((rand(1,nV)).^Power).*(unifrnd(Vmin,Vmax,1,nV));
else
Power = randi(SN*ns);
Coefficient = 2*rand();