【智能优化算法】基于分段权重和变异反向学习的蝴蝶优化算法求解单目标优化问题附matlab代码
1 简介
针对原始蝴蝶优化算法容易陷入局部最优解,收敛速度慢及寻优精度低等问题,提出分段权重和变异反向学习的蝴蝶优化算法.通过飞行引领策略来矫正邻域内蝴蝶的自身飞行,降低盲目飞行,增强算法跳出局部最优的能力;引入分段权重来平衡全局勘探及局部开发的能力,进而实现蝴蝶位置动态更新;使用变异反向学习对位置进行扰动,增加种群多样性以及提高算法的收敛速度.通过对9个测试函数和部分CEC2014函数及Wilcoxon秩和检验来评估改进算法的寻优能力,实验结果表明改进算法的收敛速度及寻优精度得到了极大改进.
2 部分代码
%% Monarch Butterfly Optimization (MBO)
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %%
%% Notes:
% Different run may generate different solutions, this is determined by
% the the nature of metaheuristic algorithms.
%%
function [MinCost] = MBO(ProblemFunction, DisplayFlag, RandSeed)
% Monarch Butterfly Optimization (MBO) software for minimizing a general function
% The fixed Function Evaluations (FEs) is considered as termination condition.
% INPUTS: ProblemFunction is the handle of the function that returns
% the handles of the initialization, cost, and feasibility functions.
% DisplayFlag = true or false, whether or not to display and plot results.
% ProbFlag = true or false, whether or not to use probabilities to update emigration rates.
% RandSeed = random number seed
% OUTPUTS: MinCost = array of best solution, one element for each generation
% Hamming = final Hamming distance between solutions
% CAVEAT: The "ClearDups" function that is called below replaces duplicates with randomly-generated
% individuals, but it does not then recalculate the cost of the replaced individuals.
tic
if ~exist('ProblemFunction', 'var')
ProblemFunction = @Ackley;
end
if ~exist('DisplayFlag', 'var')
DisplayFlag = true;
end
if ~exist('RandSeed', 'var')
RandSeed = round(sum(100*clock));
end
[OPTIONS, MinCost, AvgCost, InitFunction, CostFunction, FeasibleFunction, ...
MaxParValue, MinParValue, Population] = Init(DisplayFlag, ProblemFunction, RandSeed);
nEvaluations = OPTIONS.popsize;
% % % % % % % % % % % % Initial parameter setting % % % % % % % % % % % %%%%
%% Initial parameter setting
Keep = 2; % elitism parameter: how many of the best habitats to keep from one generation to the next
maxStepSize = 1.0; %Max Step size
partition = OPTIONS.partition;
numButterfly1 = ceil(partition*OPTIONS.popsize); % NP1 in paper
numButterfly2 = OPTIONS.popsize - numButterfly1; % NP2 in paper
period = 1.2; % 12 months in a year
Land1 = zeros(numButterfly1, OPTIONS.numVar);
Land2 = zeros(numButterfly2, OPTIONS.numVar);
BAR = partition; % you can change the BAR value in order to get much better performance
% % % % % % % % % % % % End of Initial parameter setting % % % % % % % % % % % %%
%%
% % % % % % % % % % % % Begin the optimization loop % % % % % % % % % %%%%
% Begin the optimization loop
GenIndex = 1;
% for GenIndex = 1 : OPTIONS.Maxgen
while nEvaluations< OPTIONS.MaxFEs
% % % % % % % % % % % % Elitism Strategy % % % % % % % % % % % %%%%%
%% Save the best monarch butterflis in a temporary array.
for j = 1 : Keep
chromKeep(j,:) = Population(j).chrom;
costKeep(j) = Population(j).cost;
end
% % % % % % % % % % % % End of Elitism Strategy % % % % % % % % % % % %%%%
%%
% % % % % % % % % % % % Divide the whole population into two subpopulations % % % %%%
%% Divide the whole population into Population1 (Land1) and Population2 (Land2)
% according to their fitness.
% The monarch butterflis in Population1 are better than or equal to Population2.
% Of course, we can randomly divide the whole population into Population1 and Population2.
% We do not test the different performance between two ways.
for popindex = 1 : OPTIONS.popsize
if popindex <= numButterfly1
Population1(popindex).chrom = Population(popindex).chrom;
else
Population2(popindex-numButterfly1).chrom = Population(popindex).chrom;
end
end
% % % % % % % % % % % End of Divide the whole population into two subpopulations % % %%%
%%
% % % % % % % % % % % %% Migration operator % % % % % % % % % % % %%%%
%% Migration operator
for k1 = 1 : numButterfly1
for parnum1 = 1 : OPTIONS.numVar
r1 = rand*period;
if r1 <= partition
r2 = round(numButterfly1 * rand + 0.5);
Land1(k1,parnum1) = Population1(r2).chrom(parnum1);
else
r3 = round(numButterfly2 * rand + 0.5);
Land1(k1,parnum1) = Population2(r3).chrom(parnum1);
end
end %% for parnum1
NewPopulation1(k1).chrom = Land1(k1,:);
end %% for k1
% % % % % % % % % % % %%% End of Migration operator % % % % % % % % % % % %%%
%%
% % % % % % % % % % % % Evaluate NewPopulation1 % % % % % % % % % % % %%
%% Evaluate NewPopulation1
SavePopSize = OPTIONS.popsize;
OPTIONS.popsize = numButterfly1;
% Make sure each individual is legal.
NewPopulation1 = FeasibleFunction(OPTIONS, NewPopulation1);
% Calculate cost
NewPopulation1 = CostFunction(OPTIONS, NewPopulation1);
% the number of fitness evaluations
nEvaluations = nEvaluations + OPTIONS.popsize;
OPTIONS.popsize = SavePopSize;
% % % % % % % % % % % % End of Evaluate NewPopulation1 % % % % % % % % % % % %%
%%
% % % % % % % % % % % % Butterfly adjusting operator % % % % % % % % % % % %%
%% Butterfly adjusting operator
for k2 = 1 : numButterfly2
scale = maxStepSize/(GenIndex^2); %Smaller step for local walk
StepSzie = ceil(exprnd(2*OPTIONS.Maxgen,1,1));
delataX = LevyFlight(StepSzie,OPTIONS.numVar);
for parnum2 = 1:OPTIONS.numVar,
if (rand >= partition)
Land2(k2,parnum2) = Population(1).chrom(parnum2);
else
r4 = round(numButterfly2*rand + 0.5);
Land2(k2,parnum2) = Population2(r4).chrom(1);
if (rand > BAR) % Butterfly-Adjusting rate
Land2(k2,parnum2) = Land2(k2,parnum2) + scale*(delataX(parnum2)-0.5);
end
end
end %% for parnum2
NewPopulation2(k2).chrom = Land2(k2,:);
end %% for k2
% % % % % % % % % % % % End of Butterfly adjusting operator % % % % % % % % % % % %
%%
% % % % % % % % % % % % Evaluate NewPopulation2 % % % % % % % % % % % %%
%% Evaluate NewPopulation2
SavePopSize = OPTIONS.popsize;
OPTIONS.popsize = numButterfly2;
% Make sure each individual is legal.
NewPopulation2 = FeasibleFunction(OPTIONS, NewPopulation2);
% Calculate cost
NewPopulation2 = CostFunction(OPTIONS, NewPopulation2);
% the number of fitness evaluations
nEvaluations = nEvaluations + OPTIONS.popsize;
OPTIONS.popsize = SavePopSize;
% % % % % % % % % % % % End of Evaluate NewPopulation2 % % % % % % % % % % % %%
%%
% % % % % % % Combine two subpopulations into one and rank monarch butterflis % % % % % %
%% Combine Population1 with Population2 to generate a new Population
Population = CombinePopulation(OPTIONS, NewPopulation1, NewPopulation2);
% Sort from best to worst
Population = PopSort(Population);
% % % % % % End of Combine two subpopulations into one and rank monarch butterflis % %% % %
%%
% % % % % % % % % % % % Elitism Strategy % % % % % % % % % % % %%% %% %
%% Replace the worst with the previous generation's elites.
n = length(Population);
for k3 = 1 : Keep
Population(n-k3+1).chrom = chromKeep(k3,:);
Population(n-k3+1).cost = costKeep(k3);
end % end for k3
% % % % % % % % % % % % End of Elitism Strategy % % % % % % % % % % % %%% %% %
%%
% % % % % % % % % % Precess and output the results % % % % % % % % % % % %%%
% Sort from best to worst
Population = PopSort(Population);
% Compute the average cost
[AverageCost, nLegal] = ComputeAveCost(Population);
% Display info to screen
MinCost = [MinCost Population(1).cost];
AvgCost = [AvgCost AverageCost];
if DisplayFlag
disp(['The best and mean of Generation # ', num2str(GenIndex), ' are ',...
num2str(MinCost(end)), ' and ', num2str(AvgCost(end))]);
end
% % % % % % % % % % % End of Precess and output the results %%%%%%%%%% %% %
%%
%% Update generation number
GenIndex = GenIndex+1;
end % end for GenIndex
Conclude2(DisplayFlag, OPTIONS, Population, nLegal, MinCost, AvgCost);
toc
% % % % % % % % % % End of Monarch Butterfly Optimization implementation %%%% %% %
%%
function [delataX] = LevyFlight(StepSize, Dim)
%Allocate matrix for solutions
delataX = zeros(1,Dim);
%Loop over each dimension
for i=1:Dim
% Cauchy distribution
fx = tan(pi * rand(1,StepSize));
delataX(i) = sum(fx);
end
3 仿真结果
4 参考文献
[1]李守玉,何庆,杜逆索. 分段权重和变异反向学习的蝴蝶优化算法[J]. 计算机工程与应用, 2021, 57(22):10.
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。
【智能优化算法】基于分段权重和变异反向学习的蝴蝶优化算法求解单目标优化问题附matlab代码相关推荐
- 【配电网】基于遗传算法实现三相单目标配电网重构附matlab代码
✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信.
- 【智能优化算法】基于矮猫鼬优化算法求解单目标优化问题附matlab代码
1 简介 基于矮猫鼬优化算法求解单目标优化问题 2 部分代码 %___________________________________________________________________ ...
- 【单目标优化求解】基于matlab增强型黑猩猩优化器算法求解单目标优化问题【含Matlab源码 2013期】
⛄一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[单目标优化求解]基于matlab增强型黑猩猩优化器算法求解单目标优化问题[含Matlab源码 2013期] 点击上面蓝色字体,直接付费下 ...
- 【单目标优化求解】基于matlab黑猩猩算法求解单目标问题【含Matlab源码 1413期】
一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[单目标优化求解]基于matlab黑猩猩算法求解单目标问题[含Matlab源码 1413期] 点击上面蓝色字体,直接付费下载,即可. 获取代 ...
- 【优化算法】基于matlab量子粒子群算法求解单目标优化问题【含Matlab源码 2203期】
⛄一.获取代码方式 获取代码方式1: 完整代码已上传我的资源:[优化算法]基于matlab量子粒子群算法求解单目标优化问题[含Matlab源码 2203期] 点击上面蓝色字体,直接付费下载,即可. 获 ...
- 【智能优化算法】基于融合改进 Logistics 混沌和正弦余弦算子的自适应 t 分布海鸥算法求解单目标优化问题附matlab代码
1 简介 针对基本海鸥算法存在的缺陷,提出一种融合改进Logistics混沌和正弦余弦算子的自适应t分布海鸥算法(ISOA).首先,采用改进Logistics混沌映射初始化种群,使海鸥更加均匀地分布于 ...
- 【智能优化算法】基于全局优化的改进鸡群算法求解单目标优化问题(ECSO)附matlab代码
1 简介 智能算法分为两种,一种是群体智能算法(swarmintelligencealgorithm),该算法大多模拟自然界中动植物的特有行为,并将其表达成数学语言,从而进行迭代寻优,如模拟蝙蝠回声定 ...
- 【蚁狮算法】基于柯西变异的蚁狮优化算法求解单目标优化问题matlab代码
1 简介 针对蚁狮优化算法较易陷入局部最优停滞,收敛精度低以及收敛速度较慢等问题,将自适应t分布的柯西变异融入到蚁狮优化算法中,提出了基于柯西变异的蚁狮优化算法(CALO).该算法采用轮盘赌的方法挑选 ...
- 【智能优化算法】基于免疫算法求解单目标优化问题附matlab代码
1 简介 自Farmer在1986年提出免疫机理可以在机器学习等工程问题中得到应用之后,相关人员就一直在探索免疫机理在工程实际中的应用技术.而De Castro等完善了算法结构和算法模型后,更为人工免 ...
最新文章
- input 选择框改变背景小技巧
- AI 通过眼睛的反光度,来识别是否 Deepfake 换脸
- ES6-const注意
- PS 图像尺寸|点阵格式图像|矢量格式图像|图像格式的选择
- ECCV 2018 MemTrack:《Learning Dynamic Memory Networks for Object Tracking》论文笔记
- USB主机是如何检测到设备的插入的呢?
- Android动画的实现 上
- 在加拿大读大学被开除了,以后该怎么办?
- 上位机与1200组态步骤_西门子1200的HSC的应用实例!
- 设备报废鉴定怎么做?
- 2021年美容师(中级)考试题及美容师(中级)模拟考试
- xp大容量u盘补丁_u盘128g 个性 大容量电脑系统修复
- Fail to open the referenced table
- 【小狗钱钱】—— 送人生一份理财
- 华为鸿蒙OS摄像头,首款华为鸿蒙OS摄像头开售:分布式看家新神器 无需SD卡
- gazebo的bumper使用
- Transformer Fusion for Indoor RGB-D Semantic Segmentation非官方自己实现的代码
- 熔断器Hystrix作用
- 清华大学刘知远组:文本分类任务中,将知识融入Prompt-tuning过程
- 计算机上m键mm代表什么意思,M与MM分别代表什么?What does M and MM stand for?