资源简介
%------初始化种群的个体------------%------先计算各个粒子的适应度,并初始化Pi和Pg----------------------
代码片段和文件信息
%% Initalization of Paraneters
clc
clear
%% ANN Structure
Thresh = .92;
NumofParticles = 30;
NPar = 243; % Number of Optimization Parameters
VarLow = 0; % Lower Limmit of problem
VarHigh = 1; % Upper Limmit of problem
ff = ‘costFinal‘;
GlobalBestP = rand(1NPar); % Global Best Position
GlobalBestP(GlobalBestP>Thresh) = 1;
GlobalBestP(GlobalBestP
GlobalBestC = feval(ffGlobalBestP0); % Global Best Cost
MaxIterations = 70;
DampCoef = 0.9999999;
C1 = 1.5;
C2 = 4 - C1;
%% Particles initialization
for i = 1:NumofParticles
Particles{i}.Velocity = (rand(1NPar)+2)*2;
R = rand(1NPar);
Particles{i}.Position = R > 1./(1 + exp(-Particles{i}.Velocity));
% sum(Particles{i}.Position==1)
Particles{i}.Cost = feval(ffParticles{i}.Position0);
Particles{i}.LocalBestPosition = Particles{i}.Position;
Particles{i}.LocalBestCost = Particles{i}.Cost;
if Particles{i}.Cost < GlobalBestC
GlobalBestP = Particles{i}.Position;
GlobalBestC = Particles{i}.Cost;
end
end
%% Main loop
for t = 1:MaxIterations
Damp = DampCoef^t;
for i = 1:NumofParticles
r1 = rand(1NPar);
r2 = rand(1NPar);
w = rand(1NPar);
Particles{i}.Velocity = Particles{i}.Velocity - ...
r1*C1.*(Particles{i}.LocalBestPosition - Particles{i}.Position) - ...
r2*C2.*(GlobalBestP - Particles{i}.Position);
Particles{i}.Velocity = Particles{i}.Velocity * Damp;
R = rand(1NPar);
Particles{i}.Position = R > 1./(1 + exp(-Particles{i}.Velocity));
Particles{i}.Cost = feval(ffParticles{i}.Position0);
- 上一篇:matlab实现的区域增长和分水岭算法
- 下一篇:multisim相位差检测电路仿真
评论
共有 条评论