1 简介
SSA是一种模仿麻雀捕猎与反捕猎动作的新型智能优化算法,种群成员包括发现者、跟随者和侦察者。种群中适应度较好的发现者将会在搜寻过程中最先收集到食物;有一部分跟随者始终监视发现者,若有跟随者发现种群中有麻雀已经找到更好的食物,这部分跟随者会立即去争夺食物;若负责侦察的麻雀一直处在当前的最优预测位置上,那么只需逃离到当前区域周围的某个地方;若侦察的麻雀并不处在当前最优预测位置上,则寻找当前最优预测区域周围的地方停靠。
2 部分代码
? function [FoodFitness,FoodPosition,Convergence_curve]=SSA(N,Max_iter,lb,ub,dim,fobj) if size(ub,1)==1 ub=ones(dim,1)*ub; lb=ones(dim,1)*lb; end Convergence_curve = zeros(1,Max_iter); %Initialize the positions of salps SalpPositions=initialization(N,dim,ub,lb); FoodPosition=zeros(1,dim); FoodFitness=inf; %calculate the fitness of initial salps for i=1:size(SalpPositions,1) SalpFitness(1,i)=fobj(SalpPositions(i,:)); end [sorted_salps_fitness,sorted_indexes]=sort(SalpFitness); for newindex=1:N Sorted_salps(newindex,:)=SalpPositions(sorted_indexes(newindex),:); end FoodPosition=Sorted_salps(1,:); FoodFitness=sorted_salps_fitness(1); %Main loop l=2; % start from the second iteration since the first iteration was dedicated to calculating the fitness of salps while l<Max_iter+1 c1 = 2*exp(-(4*l/Max_iter)^2); % Eq. (3.2) in the paper for i=1:size(SalpPositions,1) SalpPositions= SalpPositions'; if i<=N/2 for j=1:1:dim c2=rand(); c3=rand(); %%%%%%%%%%%%% % Eq. (3.1) in the paper %%%%%%%%%%%%%% if c3<0.5 SalpPositions(j,i)=FoodPosition(j)+c1*((ub(j)-lb(j))*c2+lb(j)); else SalpPositions(j,i)=FoodPosition(j)-c1*((ub(j)-lb(j))*c2+lb(j)); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end elseif i>N/2 && i<N+1 point1=SalpPositions(:,i-1); point2=SalpPositions(:,i); SalpPositions(:,i)=(point2+point1)/2; % % Eq. (3.4) in the paper end SalpPositions= SalpPositions'; end for i=1:size(SalpPositions,1) Tp=SalpPositions(i,:)>ub';Tm=SalpPositions(i,:)<lb';SalpPositions(i,:)=(SalpPositions(i,:).*(~(Tp+Tm)))+ub'.*Tp+lb'.*Tm; SalpFitness(1,i)=fobj(SalpPositions(i,:)); if SalpFitness(1,i)<FoodFitness FoodPosition=SalpPositions(i,:); FoodFitness=SalpFitness(1,i); end end Convergence_curve(l)=FoodFitness; l = l + 1; end ?
3 仿真结果
4 参考文献
[1]陈彩虹,王诚. 基于CNN深度算法改进及故障预测研究[J]. 计算机技术与发展, 2020, 30(10):6.
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。
?
|