function [Best_rime_rate, Best_pos, Convergence_curve, bestPred, bestNet, bestInfo] = RIME(SearchAgents_no, Max_iter, lb, ub, dim, fobj)
初始化位置
Best_rime = zeros(1, dim);
Best_rime_rate = inf; % 用于最大化问题,请将此值改为 -inf
for i = 1:dim
, i) = lb(i) + rand(SearchAgents_no, 1) .* (ub(i) - lb(i)); % 初始种群 :
end
Lb = lb .* ones(1, dim); % 下边界
Ub = ub .* ones(1, dim); % 上边界
it = 1; % 迭代次数
Convergence_curve = zeros(1, Max_iter);
Rime_rates = zeros(1, SearchAgents_no); % 初始化适应度值
newRime_rates = zeros(1, SearchAgents_no);
W = 5; % 软霜冰参数,在论文第4.3.1节中有详细讨论
计算初始位置的适应度值
for i = 1:SearchAgents_no
i),Value{i},Net{i},Info{i}] = fobj(Rimepop(i, :)); % 计算每个搜索体的适应度值
进行贪婪选择
if Rime_rates(1, i) < Best_rime_rate
Best_rime_rate = Rime_rates(1, i);
Best_rime = Rimepop(i, :);
bestPred = Value{i};
bestNet = Net{i};
bestInfo = Info{i};
end
end
主循环
while it <= Max_iter
RimeFactor = (rand - 0.5) * 2 * cos((pi * it / (Max_iter / 10))) * (1 - round(it * W / Max_iter) / W); % 公式(3),(4),(5)的参数
E = (it / Max_iter)^0.5; % 公式(6)
newRimepop = Rimepop; % 记录新的种群
normalized_rime_rates = normr(Rime_rates); % 公式(7)的参数
for i = 1:SearchAgents_no
for j = 1:dim
软霜冰搜索策略
r1 = rand();
if r1 < E
j) = Best_rime(1, j) + RimeFactor * ((Ub(j) - Lb(j)) * rand + Lb(j)); % 公式(3)
end
硬霜冰穿刺机制
r2 = rand();
if r2 < normalized_rime_rates(i)
j) = Best_rime(1, j); % 公式(7)
end
end
end
for i = 1:SearchAgents_no
边界吸收
Flag4ub = newRimepop(i, :) > ub;
Flag4lb = newRimepop(i, :) < lb;
) = (newRimepop(i, :) .* ~(Flag4ub + Flag4lb)) + ub .* Flag4ub + lb .* Flag4lb; :
i),newValue{i},newNet{i},newInfo{i}] = fobj(newRimepop(i, :));
正向贪婪选择机制
if newRime_rates(1, i) < Rime_rates(1, i)
i) = newRime_rates(1, i);
) = newRimepop(i, :); :
newValue{i}; =
newNet{i}; =
newInfo{i}; =
部分图片来源于网络,侵权联系删除!
完整代码:https://mbd.pub/o/bread/mbd-ZZealpds
欢迎感兴趣的小伙伴点击“阅读原文”或上方链接获得完整版代码哦~
关注小编会不定期推送高创新型、高质量的学习资料、文章程序代码,为你的科研加油助力~