时序预测 | MATLAB实现BKA-XGBoost(黑翅鸢优化算法优化极限梯度提升树)时间序列预测
预测效果
基本介绍
Matlab实现BKA-XGBoost时间序列预测,黑翅鸢优化算法优化极限梯度提升树,优化最大迭代次数,深度,学习率;
1.data为数据集,单变量时间序列数据集。
2.main.m为主程序文件,其他为函数文件,无需运行;
3.评价指标R2、MAE、MAPE、MSE、MBE;
4.注意程序和数据放在一个文件夹,运行环境为Matlab2018及以上。
模型描述
黑翅鸢算法(Black-winged kite algorithm,BKA)由Wang Jun等人于2024年提出,该算法受黑翅鸢的迁徙和掠食行为启发而得。BKA集成了柯西突变策略和领导者策略,增强了算法的全局搜索能力,提高了算法的收敛速度。
程序设计
- 完整代码和数据下载:MATLAB实现SSA-XGBoost(麻雀算法优化极限梯度提升树)时间序列预测
--------------------------------------------------------------------------------
%%
%________________________________________________________ ________________%
% Black-winged Kite Algorithm (BKA) source codes %
% %
%%
%% Black-winged Kite Algorithm
function [Best_Fitness_BKA,Best_Pos_BKA,Convergence_curve]=BKA(pop,T,lb,ub,dim,fobj)
%% ----------------Initialize the locations of Blue Sheep------------------%
p=0.9;r=rand;
XPos=initialization(pop,dim,ub,lb);% Initial population
for i =1:pop
XFit(i)=fobj(XPos(i,:));
end
Convergence_curve=zeros(1,T);
%% -------------------Start iteration------------------------------------%
for t=1:T
[~,sorted_indexes]=sort(XFit);
XLeader_Pos=XPos(sorted_indexes(1),:);
XLeader_Fit = XFit(sorted_indexes(1));
%% -------------------Attacking behavior-------------------%
for i=1:pop
n=0.05*exp(-2*(t/T)^2);
if p<r
XPosNew(i,:)=XPos(i,:)+n.*(1+sin(r))*XPos(i,:);
else
XPosNew(i,:)= XPos(i,:).*(n*(2*rand(1,dim)-1)+1);
end
XPosNew(i,:) = max(XPosNew(i,:),lb);XPosNew(i,:) = min(XPosNew(i,:),ub);%%Boundary checking
%% ------------ Select the optimal fitness value--------------%
XFit_New(i)=fobj(XPosNew(i,:));
if(XFit_New(i)<XFit(i))
XPos(i,:) = XPosNew(i,:);
XFit(i) = XFit_New(i);
end
%% -------------------Migration behavior-------------------%
m=2*sin(r+pi/2);
s = randi([1,pop],1);
r_XFitness=XFit(s);
ori_value = rand(1,dim);cauchy_value = tan((ori_value-0.5)*pi);
if XFit(i)< r_XFitness
XPosNew(i,:)=XPos(i,:)+cauchy_value(:,dim).* (XPos(i,:)-XLeader_Pos);
else
XPosNew(i,:)=XPos(i,:)+cauchy_value(:,dim).* (XLeader_Pos-m.*XPos(i,:));
end
XPosNew(i,:) = max(XPosNew(i,:),lb);XPosNew(i,:) = min(XPosNew(i,:),ub); %%Boundary checking
%% -------------- Select the optimal fitness value---------%
XFit_New(i)=fobj(XPosNew(i,:));
if(XFit_New(i)<XFit(i))
XPos(i,:) = XPosNew(i,:);
XFit(i) = XFit_New(i);
end
end
%% -------Update the optimal Black-winged Kite----------%
if(XFit<XLeader_Fit)
Best_Fitness_BKA=XFit(i);
Best_Pos_BKA=XPos(i,:);
else
Best_Fitness_BKA=XLeader_Fit;
Best_Pos_BKA=XLeader_Pos;
end
Convergence_curve(t)=Best_Fitness_BKA;
disp(['BKA: At iteration ', num2str(t), ' ,the best fitness is ', num2str(Best_Fitness_BKA)])
end
end
参考资料
[1] https://blog.csdn.net/category_11833757.html?spm=1001.2014.3001.5482
[2] https://blog.csdn.net/article/details/125125787
[3] https://blog.csdn.net/article/details/124928579