MAT之PSO:利用PSO+ω参数实现对一元函数y = sin(10*pi*x) ./ x进行求解优化,找到最优个体适应度
【摘要】 MAT之PSO:利用PSO+ω参数实现对一元函数y = sin(10*pi*x) ./ x进行求解优化,找到最优个体适应度
目录
输出结果
实现代码
输出结果
实现代码
x = 1:0.01:2; &n...
MAT之PSO:利用PSO+ω参数实现对一元函数y = sin(10*pi*x) ./ x进行求解优化,找到最优个体适应度
目录
输出结果
实现代码
-
x = 1:0.01:2;
-
y = sin(10*pi*x) ./ x;
-
figure
-
plot(x, y)
-
title('绘制目标函数曲线图—Jason niu');
-
hold on
-
-
-
c1 = 1.49445;
-
c2 = 1.49445;
-
-
maxgen = 50;
-
sizepop = 10;
-
-
Vmax = 0.5;
-
Vmin = -0.5;
-
popmax = 2;
-
popmin = 1;
-
-
ws = 0.9;
-
we = 0.4;
-
-
for i = 1:sizepop
-
-
pop(i,:) = (rands(1) + 1) / 2 + 1;
-
V(i,:) = 0.5 * rands(1);
-
-
fitness(i) = fun(pop(i,:));
-
end
-
-
-
[bestfitness bestindex] = max(fitness);
-
zbest = pop(bestindex,:);
-
gbest = pop;
-
fitnessgbest = fitness;
-
fitnesszbest = bestfitness;
-
-
for i = 1:maxgen
-
w = ws - (ws-we)*(i/maxgen);
-
for j = 1:sizepop
-
-
V(j,:) = w*V(j,:) + c1*rand*(gbest(j,:) - pop(j,:)) + c2*rand*(zbest - pop(j,:));
-
V(j,find(V(j,:)>Vmax)) = Vmax;
-
V(j,find(V(j,:)<Vmin)) = Vmin;
-
-
pop(j,:) = pop(j,:) + V(j,:);
-
pop(j,find(pop(j,:)>popmax)) = popmax;
-
pop(j,find(pop(j,:)<popmin)) = popmin;
-
-
fitness(j) = fun(pop(j,:));
-
end
-
-
for j = 1:sizepop
-
if fitness(j) > fitnessgbest(j)
-
gbest(j,:) = pop(j,:);
-
fitnessgbest(j) = fitness(j);
-
end
-
-
if fitness(j) > fitnesszbest
-
zbest = pop(j,:);
-
fitnesszbest = fitness(j);
-
end
-
end
-
yy(i) = fitnesszbest;
-
end
-
-
[fitnesszbest zbest]
-
plot(zbest, fitnesszbest,'r*')
-
-
figure
-
plot(yy)
-
title('PSO:PSO算法(快于GA算法)+ω参数实现找到最优个体适应度—Jason niu','fontsize',12);
-
xlabel('进化代数','fontsize',12);ylabel('适应度','fontsize',12);
相关文章
PSO:利用PSO+ω参数实现对一元函数y = sin(10*pi*x) ./ x进行求解优化,找到最优个体适应度
文章来源: yunyaniu.blog.csdn.net,作者:一个处女座的程序猿,版权归原作者所有,如需转载,请联系作者。
原文链接:yunyaniu.blog.csdn.net/article/details/79381647
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)