尖叫!一区霜冰算法优化RIME-Transformer-LSTM多变量回归预测(Maltab)
效果一览
基本介绍
1.Matlab实现RIME-Transformer-LSTM多变量回归预测,霜冰算法(RIME)优化Transformer-LSTM组合模型(程序可以作为JCR一区级论文代码支撑,目前尚未发表);
2.优化参数为:学习率,隐含层节点,正则化参数,运行环境为Matlab2023b及以上;
3.data为数据集,输入多个特征,输出单个变量,多变量回归预测,main.m为主程序,运行即可,所有文件放在一个文件夹;
4.命令窗口输出R2、MSE、RMSE、MAE、MAPE、MBE等多指标评价;
5.模型只是提供一个衡量数据集精度的方法,因此无法保证替换数据就一定得到您满意的结果。
程序设计
- 完整程序和数据获取方式私信博主回复一区霜冰算法优化RIME-Transformer-LSTM多变量回归预测(Maltab)。
%% 清空环境变量
warning off % 关闭报警信息
close all % 关闭开启的图窗
clear % 清空变量
clc % 清空命令行
%% 划分训练集和测试集
P_train = res(1: num_train_s, 1: f_)';
T_train = res(1: num_train_s, f_ + 1: end)';
M = size(P_train, 2);
P_test = res(num_train_s + 1: end, 1: f_)';
T_test = res(num_train_s + 1: end, f_ + 1: end)';
N = size(P_test, 2);
%% 数据归一化
[P_train, ps_input] = mapminmax(P_train, 0, 1);
P_test = mapminmax('apply', P_test, ps_input);
[t_train, ps_output] = mapminmax(T_train, 0, 1);
t_test = mapminmax('apply', T_test, ps_output);
%% 数据平铺
P_train = double(reshape(P_train, f_, 1, 1, M));
P_test = double(reshape(P_test , f_, 1, 1, N));
t_train = t_train';
t_test = t_test' ;
%% 数据格式转换
for i = 1 : M
p_train{i, 1} = P_train(:, :, 1, i);
end
for i = 1 : N
p_test{i, 1} = P_test( :, :, 1, i);
end
function [Best_rime_rate,Best_rime,Convergence_curve]=RIME(N,Max_iter,lb,ub,dim,fobj)
% initialize position
Best_rime=zeros(1,dim);
Best_rime_rate=inf;%change this to -inf for maximization problems
Rimepop=initialization(N,dim,ub,lb);%Initialize the set of random solutions
Lb=lb.*ones(1,dim);% lower boundary
Ub=ub.*ones(1,dim);% upper boundary
it=1;%Number of iterations
Convergence_curve=zeros(1,Max_iter);
Rime_rates=zeros(1,N);%Initialize the fitness value
newRime_rates=zeros(1,N);
W = 5;%Soft-rime parameters, discussed in subsection 4.3.1 of the paper
%Calculate the fitness value of the initial position
for i=1:N
Rime_rates(1,i)=fobj(Rimepop(i,:));%Calculate the fitness value for each search agent
%Make greedy selections
if Rime_rates(1,i)<Best_rime_rate
Best_rime_rate=Rime_rates(1,i);
Best_rime=Rimepop(i,:);
end
end
% Main loop
while it <= Max_iter
it
RimeFactor = (rand-0.5)*2*cos((pi*it/(Max_iter/10)))*(1-round(it*W/Max_iter)/W);%Parameters of Eq.(3),(4),(5)
E =(it/Max_iter)^0.5;%Eq.(6)
newRimepop = Rimepop;%Recording new populations
normalized_rime_rates=normr(Rime_rates);%Parameters of Eq.(7)
for i=1:N
for j=1:dim
%Soft-rime search strategy
r1=rand();
if r1< E
newRimepop(i,j)=Best_rime(1,j)+RimeFactor*((Ub(j)-Lb(j))*rand+Lb(j));%Eq.(3)
end
%Hard-rime puncture mechanism
r2=rand();
if r2<normalized_rime_rates(i)
newRimepop(i,j)=Best_rime(1,j);%Eq.(7)
end
end
end
for i=1:N
%Boundary absorption
Flag4ub=newRimepop(i,:)>ub;
Flag4lb=newRimepop(i,:)<lb;
newRimepop(i,:)=(newRimepop(i,:).*(~(Flag4ub+Flag4lb)))+ub.*Flag4ub+lb.*Flag4lb;
newRime_rates(1,i)=fobj(newRimepop(i,:));
%Positive greedy selection mechanism
if newRime_rates(1,i)<Rime_rates(1,i)
Rime_rates(1,i) = newRime_rates(1,i);
Rimepop(i,:) = newRimepop(i,:);
if newRime_rates(1,i)< Best_rime_rate
Best_rime_rate=Rime_rates(1,i);
Best_rime=Rimepop(i,:);
end
end
end
Convergence_curve(it)=Best_rime_rate;
it=it+1;
end
参考资料
[1] https://blog.csdn.net/kjm13182345320/article/details/127931217
[2] https://blog.csdn.net/kjm13182345320/article/details/127418340