什么意思这健身编码?我不理解。“的”是什么意思吗?

4视图(30天)
这是编码
清晰的
clc
n = 50;%的大小群“不鸟”
bird_step = 50;%最大数量的“鸟步骤”
昏暗的= 10;%问题的维度
c2 = 1.2;%算法参数C1
c1 = 0.12;% C2算法参数
w = 0.9;% pso动量或惯性
健身= 0 * 1 (n, bird_step);%健身人口
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * %
%初始化参数
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * %
R1 =兰德(暗,n);
R2 =兰德(暗,n);
current_fitness = 0 * 1 (1, n);
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * %
%初始化群体和速度和位置
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * %
%初始化随机数发生器
current_position = 10 *(兰德(暗,n));
速度= 3 * randn(暗淡,n);
local_best_position = current_position;
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * %
%计算初始种群
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * %
i = 1: n
current_fitness (i) =。(current_position(:,我));
结束
local_best_fitness = current_fitness;
[global_best_fitness g] = min (local_best_fitness);
i = 1: n
globl_best_position(:,我)= local_best_position (:, g);
结束
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * %
%的优化
% * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * %
% - - - - - - - - - - - - %速度更新
速度= w *速度+ c1 * (R1。* (local_best_position-current_position)) + c2 * (R2。* (globl_best_position-current_position));
% - - - - - - SWARMUPDATE - - - - - - %
current_position = current_position +速度;
% - - - - - -评估新群- - - - - - %
global_best_fitness =正;
% % % %主循环
iter = 0;% Iterationscounter
(iter < bird_step)
iter = iter + 1;
i = 1: n,
current_fitness (i) =。(current_position(:,我));
结束
i = 1: n
如果current_fitness (i) < local_best_fitness(我)
local_best_fitness (i) = current_fitness(我);
local_best_position(:,我)= current_position(:,我);
结束
结束
[current_global_best_fitness g] = min (local_best_fitness);
如果current_global_best_fitness < global_best_fitness
global_best_fitness = current_global_best_fitness;
i = 1: n
globl_best_position(:,我)= local_best_position (:, g);
结束
结束
速度= w *速度+ c1 * (R1。* (local_best_position-current_position)) + c2 * (R2。* (globl_best_position-current_position));
current_position = current_position +速度;
x = current_position (1);
:y = current_position (2);
clf
情节(x, y,“h”)
轴([5 5 5 5]);
暂停(3)
结束%的while循环的结束意味着所有鸟类移动一步
[Jbest_min,我]= min (current_fitness)%最低健身
current_position(:,我)%最佳解决方案
%
我不理解的是……
健身= 0 * 1 (n, bird_step);%健身人口
通过零乘以的什么?
下面是rosenbrock.m
函数f = ui (X)
%适应度函数
n =长度(X);
f = 0;
我= 1:n - 1
f = f + 100 * (X(我,1)*(我,1)- X (i + 1, - 1)) ^ 2 + (X(我,1)1)^ 2;%求和函数f = f +…
结束
1评论
沃尔特·罗伯森
沃尔特·罗伯森 2022年6月23日
编辑:沃尔特·罗伯森 2022年6月23日
这将是清晰如果用户编码
健身= 0 (n, bird_step);%健身人口
有一些非常微妙的效率差异在使用0 *的(),和一些内部预先配置的差异没有影响,除非你使用一个数组超过一半的RAM。
主要是,有些人喜欢0 *()的类比类似3.7 *()将一个策略的所有条目设置为3.7。他们觉得这是不一致的写0()设置为0的情况下而不得不使用常数*的设置值常数()。

登录置评。

答案(0)

标签

社区寻宝

找到宝藏在MATLAB中央,发现社区如何帮助你!

开始狩猎!