✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。
🍎个人主页:Matlab科研工作室
🍊个人信条:格物致知。
更多Matlab仿真内容点击👇
⛄ 内容介绍
为了提高极限学习机(ELM)数据分类的精度,提出了松鼠算法(SSA)的ELM分类器参数优化方法(SSA-ELM),将CV训练所得多个模型的平均精度作为SSA的适应度评价函数,为ELM的参数优化提供评价标准,用获得SSA优化最优参数的ELM算法进行数据分类.利用UCI中数据集进行仿真.
⛄ 部分代码
% Differential Squirrel Search Algorithm (DSSA) source Code Version 1.0
%
% Developed in MATLAB R2018b
%
% Programmers:
% Bibekananda Jena and Dr Manoj Kumar Naik
% _____________________________________________________________________________________________________
% Please cite to the main paper:
% ******************************
% B. Jena, M. K. Naik, A. Wunnava, and R. Panda,
% 揂 Differential Squirrel Search Algorithm,?
% S. Das and M. N. Mohanty, Eds. Singapore: Springer Singapore, 2021, pp. 143?52.
% https://doi.org/10.1007/978-981-16-0695-3_15
%_____________________________________________________________________________________________________
%%
function [Destination_fitness,bestPositions,Convergence_curve]=SSA(NP,Max_iter,lb,ub,npar,fobj)
% Constant initialization and memory initialization
Gc=1.9; % Gliding constant
Cr=0.5; % crossover rate
dg=0.8; %Random gliding distance
Pdp=0.1; %predator presence probability
Convergence_curve=zeros(1,Max_iter);
Fitness=ones(1,NP)*inf;
% Initialization of the Squirrel初始化
Pos=initialization(NP,npar,ub,lb);
% Fitness evalaution of each Squirrel
%每只松鼠的适合度评估
for i=1:NP
Fitness(i)=fobj(Pos(i,:));
end
% Segregating the Squirrel into hickory, acorn and normal tree
%将松鼠分为山核桃树、橡子树和普通树
[Sorted_fitness,Sort_index]=sort(Fitness);
Pos_hickory=Pos(Sort_index(1),:); % best solution (hickory tree)
Pos_acorn=Pos(Sort_index(2:4),:); % acorn tree
Pos_normal=Pos(Sort_index(5:end),:); % normal tree
L=size(Pos_normal,1);
L1=randperm(L);
% Squirrels in normal tree splitted into two sets randomly
%正常树上的松鼠随机分成两组
Pnormal_1=Pos_normal(L1(1:end-10),:);
Pnormal_2=Pos_normal(L1(end-10+1:end),:);
G=Sorted_fitness(1); % best fitness
Convergence_curve(1)=Sorted_fitness(1);
for itr=2:Max_iter
Pos_avg=mean(Pos,1); % average of all squirrels position in the current population所有松鼠在当前种群中的平均位置
%Temporary new location of squirrels in acorn and normal trees松鼠在橡树和正常的树临时的新位置
Pacorn_tree=[];
Pnormal_1_tree=[];
Pnormal_2_tree=[];
%New locations of squirrels present in the acorn trees松鼠出现在橡子树上的新位置
for i=1:3
if rand>Pdp
Pacorn_tree(i,:)=Pos_acorn(i,:)+dg*Gc*(Pos_hickory-Pos_acorn(i,:)-Pos_avg); %Eq(1)
else
Xrand=initialization(1,npar,ub,lb);
Pacorn_tree(i,:)=Xrand-rand(1,npar).*abs(Xrand-2*rand*Pos_acorn(i,:));
end
end
%New locations of some of the squirrels present in the normal trees一些松鼠的新位置出现在正常的树上
for i=1:size(Pnormal_1,1)
if rand>Pdp
k=randi(3,1);
Pnormal_1_tree(i,:)=Pnormal_1(i,:)+dg*Gc*(Pos_acorn(k,:)-Pnormal_1(i,:)); %Eq(3)
else
Xrand=initialization(1,npar,ub,lb);
Pnormal_1_tree(i,:)=Xrand-rand(1,npar).*abs(Xrand-2*rand*Pnormal_1(i,:));
end
end
%New locations of remaining squirrels present in the normal trees现存松鼠的新位置出现在正常的树上
for i=1:size(Pnormal_2,1)
if rand>Pdp
Pnormal_2_tree(i,:)=Pnormal_2(i,:)+dg*Gc*(Pos_hickory-Pnormal_2(i,:)); %Eq(4)
else
Xrand=initialization(1,npar,ub,lb);
Pnormal_2_tree(i,:)=Xrand-rand*abs(Xrand-2*rand*Pnormal_2(i,:));
end
end
Pnt=[Pnormal_1_tree; Pnormal_2_tree];
Ph1=Pos_hickory+dg*Gc*(Pos_hickory-mean(Pos_acorn,1)); %Eq(6)
if fobj(Ph1)<fobj(Pos_hickory)
Pos_hickory=Ph1;
end
Pnew=[Pos_hickory; Pacorn_tree; Pnt];
FTnew=[];
% Updating the population
for i=1:NP
FTnew(i)=fobj(Pnew(i,:));
if FTnew(i)<Fitness(i)
Fitness(i)=FTnew(i);
Pos(i,:)=Pnew(i);
else
Pos(i,:)=Pos(i,:);
Fitness(i)=Fitness(i);
end
end
[Sorted_fitness,Sort_index]=sort(Fitness);
% Update Best squirrel positions in hickory tree更新山核桃树上最好的松鼠位置
if Sorted_fitness(1)<G(itr-1)
Pos_hickory=sort(Pos(Sort_index(1),:),2);
G(itr)=Sorted_fitness(1);
else
G(itr)=G(itr-1);
end
%Updated locations of squirrels in acorn trees更新了橡子树上松鼠的位置
Pos_acorn=Pos(Sort_index(2:4),:);
%Updated locations of squirrels in normal trees更新松鼠在正常树上的位置
Pos_normal=Pos(Sort_index(5:end),:);
L=size(Pos_normal,1);
L1=randperm(L);
Pnormal_1=Pos_normal(L1(1:end-10),:);
Pnormal_2=Pos_normal(L1(end-10+1:end),:);
% Keeping all iteration best fitness value保持所有迭代的最佳适应度值
Convergence_curve(itr)=G(itr);
end
Destination_fitness=Convergence_curve(end);
bestPositions=Pos_hickory;
end
⛄ 运行结果
⛄ 参考文献
❤️ 关注我领取海量matlab电子书和数学建模资料
❤️部分理论引用网络文献,若有侵权联系博主删除