【智能算法】人工水母搜索算法(JS)原理及实现

本文介绍了Chou等人提出的基于水母行为的人工水母搜索算法(ArtificialJellyfishSearchOptimizer,JS),包括算法的灵感来源、搜索过程中的洋流模拟、时间控制机制和群体运动模型。详细描述了算法的数学原理及其实现过程,并展示了如何通过代码模拟这种优化方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在这里插入图片描述


1.背景

2020年,Chou 等人受到水母运动行为启发,提出了人工水母搜索算法(Artificial Jellyfish Search Optimizer, JS)。

2.算法原理

2.1算法思想

JS模拟了水母的搜索行为,包括追随海流、水母群内的主动和被动运动、时间控制机制以及群聚过程。
在这里插入图片描述

2.2算法过程

洋流
海洋中蕴含着大量的营养物质,这些物质会吸引水母。洋流的方向是通过对每个水母到处于最佳位置的水母(适应度度量)所有向量进行平均。
t r e n d → = 1 n P o p ∑ t r e n d → i = 1 n P o p ∑ ( X ∗ − e c X i ) = X ∗ − e c ∑ X i n P o p = X ∗ − e c μ \overrightarrow{\mathrm{trend}}=\frac{1}{\mathrm{n}_{\mathrm{Pop}}}\sum\overrightarrow{\mathrm{trend}}_{\mathrm{i}}=\frac{1}{\mathrm{n}_{\mathrm{Pop}}}\sum\left(X^{*}-\mathrm{e}_{\mathrm{c}}X_{\mathrm{i}}\right)=X^{*}-\mathrm{e}_{\mathrm{c}}\frac{\sum X_{\mathrm{i}}}{\mathrm{n}_{\mathrm{Pop}}}=X^{*}-\mathrm{e}_{\mathrm{c}}\mu trend =nPop1trend i=nPop1(XecXi)=XecnPopXi=Xecμ
这里,令 d f = e c μ \mathbf{df}=\mathbf{e}_{\mathbf{c}}\mu df=ecμ,则洋流方向可以描述为:
t r e n d → = X ∗ − d f \overrightarrow{\mathrm{trend}}=\mathrm{X}^{*}-\mathrm{df} trend =Xdf
假设水母在所有维度上分布服从正态空间分布:
在这里插入图片描述
因此,可以进行简化:
d f = β × r a n d ( 0 , 1 ) × μ \mathrm{df}=\beta\times\mathrm{rand}(0,1)\times\mu df=β×rand(0,1)×μ
每只水母位置更新:
X i ( t + 1 ) = X i ( t ) + r a n d ( 0 , 1 ) × ( X ∗ − β × r a n d ( 0 , 1 ) × μ \mathrm{X_i(t+1)=X_i(t)+rand(0,1)\times(X^*-\beta\times rand(0,1)\times\mu} Xi(t+1)=Xi(t)+rand(0,1)×(Xβ×rand(0,1)×μ
水母群体运动
在群集中,水母分别表现出被动(类型A)和主动(类型B)的运动 。最初,当群集刚形成时,大多数水母表现出类型A的运动。随着时间的推移,它们逐渐表现出类型B的运动。类型A运动是水母围绕自身位置的运动(全局探索),每个水母的相应更新位置由:
X i ( t + 1 ) = X i ( t ) + γ × r a n d ( 0 , 1 ) × ( U b − L b ) \mathrm{X_i(t+1)=X_i(t)+\gamma\times rand(0,1)\times(U_b-L_b)} Xi(t+1)=Xi(t)+γ×rand(0,1)×(UbLb)
B类型运动可以看作种群间根据食物数量(适应度衡量)进行互相迁移,比如当水母 i i i处食物数量大于水母 j j j处,则水母 j j j向水母 i i i移动,反之亦然。(此阶段为局部探索)
S t e p = X i ( t + 1 ) − X i ( t ) Direction → = X j ( t ) − X i ( t )   i f   f ( X i ) ≥ f ( X j ) X i ( t ) − X j ( t )   i f   f ( X i ) < f ( X j ) \mathrm{Step}=\mathrm{X_i(t+1)-X_i(t)} \\ \overrightarrow{\text{Direction}}=\begin{matrix}\mathsf{X_j(t)-X_i(t)~if~f(X_i)\geq f(X_j)}\\\mathsf{X_i(t)-X_j(t)~if~f(X_i)<f(X_j)}\end{matrix} Step=Xi(t+1)Xi(t)Direction =Xj(t)Xi(t) if f(Xi)f(Xj)Xi(t)Xj(t) if f(Xi)<f(Xj)
其中, S t e p → = r a n d ( 0 , 1 ) × D i r e c t i o n → \overrightarrow{\mathrm{Step}}=\mathrm{rand}(0,1)\times\overrightarrow{\mathrm{Direction}} Step =rand(0,1)×Direction ,因此整体可表述为:
X i ( t + 1 ) = X i ( t ) + S t e p → \mathrm{X_i(t+1)=X_i(t)+\overrightarrow{Step}} Xi(t+1)=Xi(t)+Step
时间控制机制
海洋流富含营养食物,吸引了水母的聚集形成水母群。随着温度或风向变化,水母群会转移至新的海洋流形成新的群体。水母群内的水母表现出被动和主动两种运动,其偏好会随着时间变化。引入时间控制机制来调节水母在海洋流和群内移动之间的转换。(这里是对全局与局部平衡,收敛性考虑)
在这里插入图片描述

c ( t ) = ∣ ( 1 − t M a x i t e r ) × ( 2 × r a n d ( 0 , 1 ) − 1 ) ∣ \mathbf{c(t)}=\left|\left(1-\frac{\mathbf{t}}{\mathbf{Max}_{\mathrm{iter}}}\right)\times(2\times\mathrm{rand}(0,1)-1)\right| c(t)= (1Maxitert)×(2×rand(0,1)1)
伪代码
在这里插入图片描述

3.代码实现

% 水母搜索算法
function [Best_pos, Best_fitness, Iter_curve, History_pos, History_best] = JS(pop, maxIter,lb,ub,dim,fobj)
%input
%pop 种群数量
%dim 问题维数
%ub 变量上边界
%lb 变量下边界
%fobj 适应度函数
%maxIter 最大迭代次数
%output
%Best_pos 最优位置
%Best_fitness 最优适应度值
%Iter_curve 每代最优适应度值
%History_pos 每代种群位置
%History_best 每代最优个体位置
%% 初始化种群
X = initialization(pop,dim,ub,lb);
VarSize = [1 dim];
%% 计算适应度
popCost = zeros(1,pop);
for i=1:pop
    popCost(i) = fobj(X(i,:));
end
%% 迭代
for it=1:maxIter
    Meanvl=mean(X,1);
    [value,index]=sort(popCost);
    Best_pos=X(index(1),:);
    BestCost=popCost(index(1));
    for i=1:pop
        % Calculate time control c(t) using Eq. (17);
        Ar=(1-it*((1)/maxIter))*(2*rand-1);
        if abs(Ar)>=0.5
            %% Folowing to ocean current using Eq. (11)
            newsol = X(i,:)+ rand(VarSize).*(Best_pos - 3*rand*Meanvl);
            % Check the boundary using Eq. (19)
            newsol = simplebounds(newsol,lb,ub);
            % Evaluation
            newsolCost = fobj(newsol);
            % Comparison
            if newsolCost<popCost(i)
                X(i,:) = newsol;
                popCost(i)=newsolCost;
                if popCost(i) < BestCost
                    BestCost=popCost(i);
                    Best_pos = X(i,:);
                end
            end
        else
            %% Moving inside swarm
            if rand<=(1-Ar)
                % Determine direction of jellyfish by Eq. (15)
                j=i;
                while j==i
                    j=randperm(pop,1);
                end
                Step = X(i,:) - X(j,:);
                if popCost(j) < popCost(i)
                    Step = -Step;
                end
                % Active motions (Type B) using Eq. (16)
                newsol = X(i,:) + rand(VarSize).*Step;
            else
                % Passive motions (Type A) using Eq. (12)
                newsol = X(i,:) + 0.1*(ub-lb)*rand;
            end
            % Check the boundary using Eq. (19)
            newsol = simplebounds(newsol, lb,ub);
            % Evaluation
            newsolCost = fobj(newsol);
            % Comparison
            if newsolCost<popCost(i)
                X(i,:) = newsol;
                popCost(i)=newsolCost;
                if popCost(i) < BestCost
                    BestCost=popCost(i);
                    Best_pos = X(i,:);
                end
            end
        end
    end
    %% Store Record for Current Iteration
    Iter_curve(it)=BestCost;
    Best_fitness = BestCost;
    History_best{it} = Best_pos;
    History_pos{it} = X;
end
end
%% This function is for checking boundary by using Eq. 19
function s=simplebounds(s,Lb,Ub)
ns_tmp=s;
I=ns_tmp<Lb;
% Apply to the lower bound
while sum(I)~=0
    ns_tmp(I)=Ub(I)+(ns_tmp(I)-Lb(I));
    I=ns_tmp<Lb;
end
% Apply to the upper bound
J=ns_tmp>Ub;
while sum(J)~=0
    ns_tmp(J)=Lb(J)+(ns_tmp(J)-Ub(J));
    J=ns_tmp>Ub;
end
% Check results
s=ns_tmp;
end
%%
function pop=initialization(num_pop,nd,Ub,Lb)

if size(Lb,2)==1
    Lb=Lb*ones(1,nd);
    Ub=Ub*ones(1,nd);
end
x(1,:)=rand(1,nd);
a=4;
for i=1:(num_pop-1)
    x(i+1,:)=a*x(i,:).*(1-x(i,:));
end 
for k=1:nd
    for i=1:num_pop
        pop(i,k)=Lb(k)+x(i,k)*(Ub(k)-Lb(k));
    end
end
end

在这里插入图片描述

4.参考文献

[1] Chou J S, Truong D N. A novel metaheuristic optimizer inspired by behavior of jellyfish in ocean[J]. Applied Mathematics and Computation, 2021, 389: 125535.

### 使用人工水母搜索算法实现人群轨迹预测 #### 方法概述 人工水母搜索算法(Artificial Jellyfish Search Algorithm, AJSA)是一种受自然界中水母行为启发而设计的优化算法。该算法模拟了水母在海洋中的运动模式及其觅食策略,能够有效处理复杂的多维空间寻优问题[^2]。 对于人群轨迹预测而言,AJSA可以用来寻找最优参数配置或路径规划方案,从而更好地拟合实际的人群移动规律。具体来说: - **初始化种群**:定义一组虚拟“水母”,即潜在解决方案集;每个个体代表一种可能的人群流动模式。 - **适应度评估**:通过比较历史数据与当前假设下的预期位置差异来计算各个体的表现得分。这一步骤通常涉及统计距离测量或其他相似性指标的选择。 - **更新机制**:依据预设规则调整每只“水母”的状态向量——包括方向、速度等因素——以便逐步逼近全局最佳解。此过程会反复迭代直至满足收敛条件为止。 - **边界约束处理**:考虑到物理环境限制以及安全因素考量,在每次位移操作之前需确保新坐标落在合法区域内。 #### 应用实例分析 以某大型商场内部顾客行走路线为例说明上述流程的应用场景: 1. 收集一段时间内不同时间段内的视频监控资料作为训练样本库; 2. 提取特征点并标注时间戳信息形成序列化输入格式供后续建模使用; 3. 构造目标函数表达式用于量化单个模型的好坏程度,比如最小二乘法误差平方和等; 4. 调用MATLAB内置工具箱执行AJSA核心逻辑运算得出最终结果可视化展示图谱如下所示: ```matlab % 假定已准备好相关变量dataSet(观测值), numIterations(最大循环次数) options = optimset('Display', 'iter'); % 设置显示选项 [x,fval] = ajsa(@objectiveFunction,dataSet,[],[],numIterations,options); plot(x,'o-r'); title('Predicted Trajectories Using Artificial Jellyfish Search Algorithm'); xlabel('Time Steps'); ylabel('Position Coordinates'); legend('X-axis','Y-axis') ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小O的算法实验室

谢谢大佬的肯定!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值