续写黑神话!原创首发!SLWCHOA-Transformer-BiLSTM混合改进策略的黑猩猩优化算法多变量时间序列预测
效果一览
基本介绍
1.续写黑神话!原创首发!SLWCHOA-Transformer-BiLSTM混合改进策略的黑猩猩优化算法优化Transformer结合双向长短期记忆神经网络多变量时间序列预测(程序可以作为SCI一区级论文代码支撑,目前尚未发表);
2.优化参数为:学习率,隐含层节点,正则化参数,运行环境为Matlab2023b及以上;
3.data为数据集,输入多个特征,输出单个变量,考虑历史特征的影响,多变量时间序列预测,main.m为主程序,运行即可,所有文件放在一个文件夹;
4.命令窗口输出R2、MSE、RMSE、MAE、MAPE、MBE等多指标评价;
混合策略改进的黑猩猩优化算法SLWCHOA可直接运行main出图提供23个基准函数对此与秩和检(Matlab完整源码)改进点如下:①利用Sobol序列初始化种群,增加种群的随机性和多样性,为算法全局寻优奠定基础;②其次,引入基于凸透镜成像的反向学习策略,将其应用到当前最优个体上产生新的个体,提高算法的收敛精度和速度;③最后,将水波动态自适应因子添加到攻击者位置更新处,增强算法跳出局部最优的能力。智能算法改进提供与原始CHOA、鲸鱼算法WOA、麻雀搜索算法SSA、灰狼算法GWO等算法的对比。
参考文献
程序设计
- 完整程序和数据获取方式私信博主回复SLWCHOA-Transformer-BiLSTM混合改进策略的黑猩猩优化算法多变量时间序列预测(Matlab)。
%% 清空环境变量
warning off % 关闭报警信息
close all % 关闭开启的图窗
clear % 清空变量
clc % 清空命令行
%% 导入数据
result = xlsread('data.xlsx');
%% 数据分析
num_samples = length(result); % 样本个数
or_dim = size(result, 2); % 原始特征+输出数目
kim = 2; % 延时步长(kim个历史数据作为自变量)
zim = 1; % 跨zim个时间点进行预测
%% 数据集分析
outdim = 1; % 最后一列为输出
num_size = 0.7; % 训练集占数据集比例
num_train_s = round(num_size * num_samples); % 训练集样本个数
f_ = size(res, 2) - outdim; % 输入特征维度
%% 划分训练集和测试集
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
%% 清除环境变量
clear
clc
close all
%% 参数设置
N = 30; % 种群规模
Function_name = 'F4'; % 从F1到F23的测试函数的名称(本文中的表1、2、3)
Max_iteration = 500; % 最大迭代次数
% 加载所选基准函数的详细信息
[lb, ub, dim, fobj] = Get_Functions_details(Function_name);
% 初始化种群位置
X = initialization(N, dim, ub, lb);
cnt_max =5;
for cnt = 1:cnt_max
[WOA_Best_score(cnt), WOA_Best_pos, WOA_Curve] = WOA(X, N, Max_iteration, lb, ub, dim, fobj);
[GWO_Best_score(cnt), GWO_Best_pos, GWO_Curve] = GWO(X, N, Max_iteration, lb, ub, dim, fobj);
[PSO_Best_score(cnt), PSO_Best_pos, PSO_Curve] = PSO(X, N, Max_iteration, lb, ub, dim, fobj);
[CHOA_Best_score(cnt), CHOA_Best_pos, CHOA_Curve] = CHOA(X, N, Max_iteration, lb, ub, dim, fobj);
[SSA_Best_score(cnt), SSA_Best_pos, SSA_Curve] = SSA(X, N, Max_iteration, lb, ub, dim, fobj);
[MPA_Best_score(cnt), MPA_Best_pos, MPA_Curve] = MPA(X, N, Max_iteration, lb, ub, dim, fobj);
[SLWChoA_Best_score(cnt), SLWChoA_Best_pos, SLWChoA_Curve] = SLWChoA(X, N, Max_iteration, lb, ub, dim, fobj);
end
%% 画图
% 画图迭代曲线图
figure
semilogy(SLWChoA_Curve,'r-','linewidth',1.5);
hold on
semilogy(SSA_Curve,'b--','linewidth',1.5);
hold on
semilogy(GWO_Curve,'y--','linewidth',1.5);
hold on
semilogy(PSO_Curve,'b-','linewidth',1.5);
hold on
semilogy(WOA_Curve,'k-','linewidth',1.5);
hold on
semilogy(CHOA_Curve,'m-','linewidth',1.5);
hold on
semilogy(MPA_Curve,'r-','linewidth',1.5);
hold on
title('Objective space')
xlabel('Iteration');
ylabel('Best score obtained so far');
set(gca,'fontname','Times New Roman')
axis tight
grid on
box on
legend('SLWChoA','SSA','GWO','PSO','WOA','CHOA','MPA')
% 画出所选基准函数的三维立体图形
figure;
func_plot(Function_name);
title(Function_name)
xlabel('x_1');
ylabel('x_2');
zlabel([Function_name,'( x_1 , x_2 )'])
set(gca,'fontname','Times New Roman')
% 2、画出目标函数值变化曲线图
figure;
t = 1:Max_iteration;
semilogy(t, SLWChoA_Curve, 'ro-',t, SSA_Curve, 'ko-', t, GWO_Curve, 'cs-', ...
t, PSO_Curve, 'k*-', t, WOA_Curve, 'gh-', t, CHOA_Curve, 'b^-', t, MPA_Curve, 'r*-', ...
'linewidth', 1.5, 'MarkerSize', 8, 'MarkerIndices', 1:50:Max_iteration);
title(Function_name)
xlabel('迭代次数');
ylabel('适应度值');
axis fill
grid on
box on
legend('SLWChoA','SSA','GWO','PSO','WOA','CHOA','MPA');
参考资料
[1] https://blog.csdn.net/kjm13182345320/article/details/127931217
[2] https://blog.csdn.net/kjm13182345320/article/details/127418340