-
大小: 4KB文件类型: .zip金币: 1下载: 0 次发布日期: 2021-06-04
- 语言: Matlab
- 标签:
资源简介
matlab粒子群算法(PSO)程序,算法优化效果比较,适合研究改进PSO算法的同学。
代码片段和文件信息
clear all
clc
%%%??????标准PSO??????
tic
%???初始化算法参数
NI = 1000;
w_max = 0.9;
w_min = 0.4;
popsize = 40;
c1 = 2;c2 = 2;
D = 10;NR = 30;
%???适应度函数定义域
v_max = 100*ones(1 D);
v_min = -100*ones(1 D);
x_max = 100*ones(1 D);
x_min = -100*ones(1 D);
%???最优值变量
fit_best = zeros(NR NI);
fit_round_best = zeros(1 30);
for nr = 1:NR
pop = zeros(popsize D+1); velocity = zeros(popsize D);
p_best = zeros(popsize D+1); g_best = zeros(1D+1);
p_best(: D+1) = Inf*ones(popsize 1); g_best(D+1) = Inf;
%???初始化粒子位置和速度
for i = 1:popsize
for j = 1:D
pop(i j) = x_min(j)+rand()*(x_max(j)-x_min(j));
velocity(i j) = v_min(j)+rand()*(v_max(j)-v_min(j));
end
end
%???计算适应度值
for ni = 1:NI
for i = 1:popsize
pop(i D+1) = 0;
for j = 1:D
pop(i D+1) = pop(i D+1)+pop(i j)^2;
end
if pop(i D+1) < p_best(i D+1)
p_best(i:) = pop(i:);
if p_best(iD+1) < g_best(D+1)
g_best = p_best(i:);
end
end
end
w(ni) = w_max-(w_max-w_min)*ni/NI;
for i = 1:popsize
for j = 1:D
velocity(i j) = w(ni)*velocity(i j)+c1*rand()*(p_best(i j)-pop(i j))+c2*rand()*(g_best(j)-pop(i j));
if velocity(i j) > v_max(j)
velocity(i j) = v_max(j);
elseif velocity(i j) < v_min(j)
velocity(i j) = v_min(j);
end
pop(i j) = pop(i j)+velocity(i j);
if pop(i j) > x_max(j)
pop(i j) = x_max(j);
elseif pop(i j) < x_min(j)
pop(i j) = x_min(j);
end
end
end
fit_best1(nr ni) = g_best(D+1);
end
fit_round_best1(nr) = min(pop(:D+1));
end
toc
%???记录结果数据
Run_time1 = toc/NR;
fit_min1 = min(fit_round_best1);
fit_max1 = max(fit_round_best1);
fit_std1 = std(fit_round_best1);
fit_mean1 = mean(fit_round_best1);
fit_median1 = median(fit_round_best1);
fit1 = [fit_min1 fit_max1 fit_std1 fit_mean1 fit_median1 Run_time1];
fileID = fopen(‘Result.txt‘‘a‘);
formatSpec = ‘%e %e %e %e %e %e\n‘;
fprintf(fileID formatSpec fit_min1 fit_max1 fit_std1 fit_mean1 fit_median1 Run_time1);
fclose(fileID);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%??????R-dGPSO??????
tic
%???初始化算法参数
NI = 1000;
w_max = 0.9;
w_min = 0.4;
popsize = 40;
c1 = 2; c2 = 2;
D = 10; NR = 30;
%???适应度函数定义域
v_max = 100*ones(1 D);
v_min = -100*ones(1 D);
x_max = 100*ones(1 D);
x_min = -100*ones(1 D);
%???最优值变量
fit_best = zeros(NR NI);
fit_round_best = zeros(1 30);
for nr = 1:NR
pop = zeros(popsize D+1); velocity = zeros(popsize D);
p_best = zeros(popsize D+1); g_best = zeros(1D+1);
p_best(: D+1) = Inf*ones(popsize 1); g_best(D+1) = Inf;
%???初始化粒子位置和速度
for i = 1:
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-03-06 16:18 pso\
文件 6148 2019-03-06 16:18 pso\.DS_Store
目录 0 2019-03-06 16:18 __MACOSX\
目录 0 2019-03-06 16:18 __MACOSX\pso\
文件 120 2019-03-06 16:18 __MACOSX\pso\._.DS_Store
文件 2676 2019-03-06 11:16 pso\SPSO.m
文件 178 2019-03-06 11:16 __MACOSX\pso\._SPSO.m
文件 5261 2019-03-06 16:11 pso\pso_vs_cospso.m
文件 210 2019-03-06 16:11 __MACOSX\pso\._pso_vs_cospso.m
- 上一篇:区域生长算法的MATLAB编程实现
- 下一篇:matlab图像融合代码+图像
评论
共有 条评论