【智能优化算法】一种改进的灰狼算法附matlab代码

简介: 【智能优化算法】一种改进的灰狼算法附matlab代码

 1 简介

Grey wolf optimization (GWO) algorithm is a new emerging algorithm that is based on the social hierarchy of grey wolves as well as their hunting and cooperation strategies. Introduced in 2014, this algorithm has been used by a large number of researchers and designers, such that the number of citations to the original paper exceeded many other algorithms. In a recent study by Niu et al., one of the main drawbacks of this algorithm for optimizing real﹚orld problems was introduced. In summary, they showed that GWO's performance degrades as the optimal solution of the problem diverges from 0. In this paper, by introducing a straightforward modification to the original GWO algorithm, that is, neglecting its social hierarchy, the authors were able to largely eliminate this defect and open a new perspective for future use of this algorithm. The efficiency of the proposed method was validated by applying it to benchmark and real﹚orld engineering problems.

2 部分代码

clcclearglobal NFENFE=0;nPop=30;    % Number of search agents (Population Number)MaxIt=1000; % Maximum number of iterationsnVar=30;    % Number of Optimization Variables nFun=1;     % Function No, select any integer number from 1 to 14CostFunction=@(x,nFun) Cost(x,nFun);        % Cost Function%% Problem DefinitionVarMin=-100;             % Decision Variables Lower Boundif nFun==7    VarMin=-600;             % Decision Variables Lower Boundendif nFun==8    VarMin=-32;             % Decision Variables Lower Boundendif nFun==9    VarMin=-5;             % Decision Variables Lower Boundendif nFun==10    VarMin=-5;             % Decision Variables Lower Boundendif nFun==11    VarMin=-0.5;             % Decision Variables Lower Boundendif nFun==12    VarMin=-pi;             % Decision Variables Lower Boundendif nFun==14    VarMin=-100;             % Decision Variables Lower BoundendVarMax= -VarMin;             % Decision Variables Upper Boundif nFun==13    VarMin=-3;             % Decision Variables Lower Bound    VarMax= 1;             % Decision Variables Upper Boundend%%   Grey Wold Optimizer (GWO)% Initialize Alpha, Beta, and DeltaAlpha_pos=zeros(1,nVar);Alpha_score=inf;Beta_pos=zeros(1,nVar);Beta_score=inf;Delta_pos=zeros(1,nVar);Delta_score=inf;%Initialize the positions of search agentsPositions=rand(nPop,nVar).*(VarMax-VarMin)+VarMin;BestCosts=zeros(1,MaxIt);fitness=nan(1,nPop);iter=0;  % Loop counter%% Main loopwhile iter<MaxIt    for i=1:nPop                % Return back the search agents that go beyond the boundaries of the search space        Flag4ub=Positions(i,:)>VarMax;        Flag4lb=Positions(i,:)<VarMin;        Positions(i,:)=(Positions(i,:).*(~(Flag4ub+Flag4lb)))+VarMax.*Flag4ub+VarMin.*Flag4lb;                % Calculate objective function for each search agent        fitness(i)= CostFunction(Positions(i,:), nFun);                % Update Alpha, Beta, and Delta        if fitness(i)<Alpha_score            Alpha_score=fitness(i);  % Update Alpha            Alpha_pos=Positions(i,:);        end                if fitness(i)>Alpha_score && fitness(i)<Beta_score            Beta_score=fitness(i);  % Update Beta            Beta_pos=Positions(i,:);        end                if fitness(i)>Alpha_score && fitness(i)>Beta_score && fitness(i)<Delta_score            Delta_score=fitness(i);  % Update Delta            Delta_pos=Positions(i,:);        end    end        a=2-(iter*((2)/MaxIt));  % a decreases linearly fron 2 to 0        % Update the Position of all search agents    for i=1:nPop        for j=1:nVar                        r1=rand;            r2=rand;                        A1=2*a*r1-a;            C1=2*r2;                        D_alpha=abs(C1*Alpha_pos(j)-Positions(i,j));            X1=Alpha_pos(j)-A1*D_alpha;                        r1=rand;            r2=rand;                        A2=2*a*r1-a;            C2=2*r2;                        D_beta=abs(C2*Beta_pos(j)-Positions(i,j));            X2=Beta_pos(j)-A2*D_beta;                        r1=rand;            r2=rand;                        A3=2*a*r1-a;            C3=2*r2;                        D_delta=abs(C3*Delta_pos(j)-Positions(i,j));            X3=Delta_pos(j)-A3*D_delta;                        Positions(i,j)=(X1+X2+X3)/3;                    end    end        iter=iter+1;    BestCosts(iter)=Alpha_score;        fprintf('Iter= %g,  NFE= %g,  Best Cost = %g\n',iter,NFE,Alpha_score); end

3 仿真结果

image.gif编辑

4 参考文献

[1] Akbari E ,  Rahimnejad A ,  Gadsden S A . A greedy non﹉ierarchical grey wolf optimizer for real﹚orld optimization[J]. Electronics Letters, 2021(1).

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

5 代码下载

相关文章
|
8天前
|
传感器 算法
ANC主动降噪理论及Matlab代码实现
ANC主动降噪理论及Matlab代码实现
|
12天前
|
搜索推荐 算法
【排序】数据结构——排序算法概念及代码详解(插入、冒泡、快速、希尔)
【排序】数据结构——排序算法概念及代码详解(插入、冒泡、快速、希尔)
|
4天前
|
人工智能 算法 Java
java中经典算法代码整理
java中经典算法代码整理
16 0
|
5天前
|
算法 IDE 开发工具
c语言的经典算法代码
c语言进阶11-经典算法代码
|
5天前
|
算法
数据结构和算法常见的问题和代码
数据结构和算法常见的问题和代码
|
9天前
|
存储 算法 Java
面试高频算法题汇总「图文解析 + 教学视频 + 范例代码」之 二分 + 哈希表 + 堆 + 优先队列 合集
面试高频算法题汇总「图文解析 + 教学视频 + 范例代码」之 二分 + 哈希表 + 堆 + 优先队列 合集
|
3天前
|
机器学习/深度学习 自然语言处理 算法
m基于深度学习的OFDM+QPSK链路信道估计和均衡算法误码率matlab仿真,对比LS,MMSE及LMMSE传统算法
**摘要:** 升级版MATLAB仿真对比了深度学习与LS、MMSE、LMMSE的OFDM信道估计算法,新增自动样本生成、复杂度分析及抗频偏性能评估。深度学习在无线通信中,尤其在OFDM的信道估计问题上展现潜力,解决了传统方法的局限。程序涉及信道估计器设计,深度学习模型通过学习导频信息估计信道响应,适应频域变化。核心代码展示了信号处理流程,包括编码、调制、信道模拟、降噪、信道估计和解调。
23 8
|
5天前
|
算法
基于GA遗传优化的混合发电系统优化配置算法matlab仿真
**摘要:** 该研究利用遗传算法(GA)对混合发电系统进行优化配置,旨在最小化风能、太阳能及电池储能的成本并提升系统性能。MATLAB 2022a用于实现这一算法。仿真结果展示了一系列图表,包括总成本随代数变化、最佳适应度随代数变化,以及不同数据的分布情况,如负荷、风速、太阳辐射、弃电、缺电和电池状态等。此外,代码示例展示了如何运用GA求解,并绘制了发电单元的功率输出和年变化。该系统原理基于GA的自然选择和遗传原理,通过染色体编码、初始种群生成、适应度函数、选择、交叉和变异操作来寻找最优容量配置,以平衡成本、效率和可靠性。
|
6天前
|
机器学习/深度学习 算法
基于鲸鱼优化的knn分类特征选择算法matlab仿真
**基于WOA的KNN特征选择算法摘要** 该研究提出了一种融合鲸鱼优化算法(WOA)与K近邻(KNN)分类器的特征选择方法,旨在提升KNN的分类精度。在MATLAB2022a中实现,WOA负责优化特征子集,通过模拟鲸鱼捕食行为的螺旋式和包围策略搜索最佳特征。KNN则用于评估特征子集的性能。算法流程包括WOA参数初始化、特征二进制编码、适应度函数定义(以分类准确率为基准)、WOA迭代搜索及最优解输出。该方法有效地结合了启发式搜索与机器学习,优化特征选择,提高分类性能。
|
1天前
|
机器学习/深度学习 存储 算法
基于SFLA算法的神经网络优化matlab仿真
**摘要:** 使用MATLAB2022a,基于SFLA算法优化神经网络,降低训练误差。程序创建12个神经元的前馈网络,训练后计算性能。SFLA算法寻找最优权重和偏置,更新网络并展示训练与测试集的预测效果,以及误差对比。SFLA融合蛙跳与遗传算法,通过迭代和局部全局搜索改善网络性能。通过调整算法参数和与其他优化算法结合,可进一步提升模型预测精度。