mirror's Blog

Happy coding

粒子群算法的寻优算法

mirror posted @ 2013年1月09日 11:16 in PSO , 2249 阅读

粒子群算法( Particle Swarm Optimization, PSO)最早是由Eberhart和Kennedy于1995年提出,它的基本概念源于对鸟群觅食行为的研究。设想这样一个场景:一群鸟在随机搜寻食物,在这个区域里只有一块食物,所有的鸟都不知道食物在哪里,但是它们知道当前的位置离食物还有多远。那么找到食物的最优策略是什么呢?最简单有效的就是搜寻目前离食物最近的鸟的周围区域。

PSO算法就从这种生物种群行为特性中得到启发并用于求解优化问题。在PSO中,每个优化问题的潜在解都可以想象成d维搜索空间上的一个点,我们称之为“粒子”(Particle),所有的粒子都有一个被目标函数决定的适应值(Fitness Value ),每个粒子还有一个速度决定他们飞翔的方向和距离,然后粒子们就追随当前的最优粒子在解空间中搜索。Reynolds对鸟群飞行的研究发现。鸟仅仅是追踪它有限数量的邻居但最终的整体结果是整个鸟群好像在一个中心的控制之下.即复杂的全局行为是由简单规则的相互作用引起的。

大致流程:

由n个粒子组成的群体对Q维(就是每个粒子的维数)空间进行搜索。每个粒子表示为:xi=(xi1,xi2,xi3,...,xiQ),每个粒子对应的速度可以表示为vi=(vi1,vi2,vi3,....,viQ),每个粒子在搜索时要考虑两个因素:

1。自己搜索到的历史最优值 pi ,pi=(pi1,pi2,....,piQ),i=1,2,3,....,n。

2。全部粒子搜索到的最优值pg,pg=(pg1,pg2,....,pgQ),注意这里的pg只有一个。

粒子群算法的位置速度更新公式:

w是保持原来速度的系数,所以叫做惯性权重

c1是粒子跟踪自己历史最优值的权重系数,它表示粒子自身的认识,所以叫“认知”。通常设置为2。

c2是粒子跟踪群体最优值的权重系数,它表示粒子对整个群体知识的认识,所以叫做“社会知识”,经常叫做“社会”。通常设置为2。

η、ξ是[0,1]区间内均匀分布的随机数。

r是对位置更新的时候,在速度前面加的一个系数,这个系数我们叫做约束因子。通常设置为1。

 

代码:

%清空运行环境
clc
clear

%设置速度更新参数
c1=1.49445;
c2=1.49445;
maxgen=300; %迭代次数
sizepop=20; %种群规模
%个体和速度最大值最小值
popmax=2;
popmin=-2;
Vmax=0.5;
Vmin=-0.5;
figure;

%种群初始化
for i=1:sizepop
    %随机产生一个种群
    pop(i,:)=2*rands(1,2); %初始化粒子
    V(i,:)=0.5*rands(1,2); %初始化速度
    %计算粒子适应度值
    fitness(i)=fun(pop(i,:));
end

    %寻找出极值
    [bestfitness bestindex]=max(fitness);
    zbest=pop(bestindex,:); %群体极值位置
    gbest=pop; %个体极值位置
    fitnessgbest=fitness; %个体极值适应度值
    fitnesszbest=bestfitness; %群体极值适应度值

%迭代寻优
for i=1:maxgen

    for j=1:sizepop
        %速度更新
        V(j,:)=V(j,:)+c1*rand*(gbest(j,:)-pop(j,:))+c2*rand*(zbest-pop(j,:));
        if V(j,1)>Vmax
            V(j,1)=Vmax;
        end
        if V(j,2)>Vmax
            V(j,2)=Vmax;
        end
         if V(j,1)<Vmin
            V(j,1)=Vmin;
        end
        if V(j,2)<Vmin
            V(j,2)=Vmin;
        end
        %位置更新
        pop(j,:)=pop(j,:)+0.5*V(j,:);
        if pop(j,1)>popmax
            pop(j,1)=popmax;
        end
        if pop(j,2)>popmax
            pop(j,2)=popmax;
        end
         if pop(j,1)<popmin
            pop(j,1)=popmin;
        end
        if pop(j,2)<popmin
            pop(j,2)=popmin;
        end
         %新粒子适应度值
        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
   result(i)=fitnesszbest;
end

%画出每代最优化个体适应度值
plot(result)
title('最优个体适应度值','fontsize',12);
xlabel('进化代数','fontsize',12);
ylabel('适应度值','fontsize',12);

 

Avatar_small
seo service london 说:
2024年1月16日 14:44

This was really an interesting topic and I kinda agree with what you have mentioned here!Hello, I have browsed most of your posts. This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this. Are you aware of any other websites on this subjec

Avatar_small
앙상블 가입코드 说:
2024年1月25日 14:13

This is often at the same time a good present that many of us seriously enjoyed browsing. It's not at all on a daily basis which i provide the likeliness to check something.

Avatar_small
온라인카지노쿠폰 说:
2024年1月25日 14:48

Decent data, profitable and phenomenal outline, as offer well done with smart thoughts and ideas, bunches of extraordinary data and motivation, both of which I require, on account of offer such an accommodating data her

Avatar_small
토지노주소 说:
2024年1月25日 14:54

Discover the best selection and lowest prices on prescription and over-the-counter medications. Everything you'd expect from Canada's largest online pharmacy! CanadaCloudPharmacy.com is the most trusted name in high-quality, affordable medications, having been a first-class, certified online pharmacy serving many satisfied customers since 2001. In addition to discount prescription drugs, our Canada Pharmacy online provides a wide variety of discounted over-the-counter (OTC) medications, such as pain relievers, allergy medications, and even pet medications.

Avatar_small
라이브맨배당흐름 说:
2024年1月25日 15:01

Hey There. I found your blog using msn. This is a very well written article. I’ll be sure to bookmark it and come back to read more of your useful info. Thanks for the post. I’ll definitely return.

Avatar_small
카지노게임사이트 说:
2024年1月25日 15:08

This is often at the same time a good present that many of us seriously enjoyed browsing. It's not at all on a daily basis which i provide the likeliness to check something.

Avatar_small
배트맨토토주소 说:
2024年1月25日 15:12

I will love the light for it shows me the way, yet I will endure the darkness because it shows me the stars.’

Avatar_small
카지노사이트순위 说:
2024年1月25日 15:13

Acknowledges for paper such a beneficial composition, I stumbled beside your blog besides decipher a limited announce. I want your technique of inscription.

Avatar_small
메이저놀이터 说:
2024年1月25日 15:22

I will love the light for it shows me the way, yet I will endure the darkness because it shows me the stars.’

Avatar_small
บาคาร่าออนไลน์ 说:
2024年1月25日 15:23

Hey what a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you.

Avatar_small
카지노사이트 说:
2024年1月25日 15:31

Hey There. I found your blog using msn. This is a very well written article. I’ll be sure to bookmark it and come back to read more of your useful info. Thanks for the post. I’ll definitely return.

Avatar_small
먹튀검증커뮤니티 说:
2024年1月25日 15:36

Normally, you can only use Payday for around 10,000 yen for the first time, but this plan is specialized for Apple products and has a significantly wider usage limit.

Avatar_small
먹튀폴리스주소 说:
2024年1月25日 15:38

I definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work.

Avatar_small
토토사이트 说:
2024年1月25日 15:56

Hello every one life is short live with joyness and dont loose your fashion life style visit online via american jacket store .com and hunt your choice out fit

Avatar_small
ok토토먹튀검증 说:
2024年1月25日 15:59

All the contents you mentioned in post is too good and can be very useful. I will keep it in mind, thanks for sharing the information keep updating, looking forward for more posts.Thanks

Avatar_small
메이저놀이터 说:
2024年1月25日 16:08

Hey There. I found your blog using msn. This is a very well written article. I’ll be sure to bookmark it and come back to read more of your useful info. Thanks for the post. I’ll definitely return.

Avatar_small
양방사이트 说:
2024年1月25日 16:16

Thanks for sharing the post.. parents are worlds best person in each lives of individual..they need or must succeed to sustain needs of the family.

Avatar_small
엔트리파워볼 说:
2024年1月25日 16:19

Partaking in a particularly overpowering undertaking utilizes a great deal of our assets. Appreciation for sharing. I regard your site's facilities and strong data. Look at our site, and we will find you.

Avatar_small
토토검증 说:
2024年1月25日 16:24

Nicely and effectively written blog and conveying the right information to the readers.Taxi in Alesund

Avatar_small
토토뱃지 说:
2024年1月25日 16:28

Wonderful article man! The way you have explained everything step by step is phenomenal. I really appreciate your work. Keep it up!!! In case, if you are looking

Avatar_small
온라인카지노 说:
2024年1月25日 16:35

Just admiring your work and wondering how you managed this blog so well. It’s so remarkable that I can't afford to not go through this valuable information whenever I surf the internet!

Avatar_small
토토사이트추천 说:
2024年1月25日 16:38

I'm impressed by the variety of topics you cover. Letari Studio offers a comprehensive range of services, including pre-wedding shoots, actual day coverage, cinematic highlight videos, and destination wedding packages.

Avatar_small
토토캡스 说:
2024年1月25日 16:49

Thanks for sharing nice information with us. i like your post and all you share with us is uptodate and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job.

Avatar_small
먹튀검증 说:
2024年1月25日 16:51

I found your this post while searching for some related information on blog search...Its a good post..keep posting and update the information.

Avatar_small
우리계열 说:
2024年1月25日 16:54

Wonderful article man! The way you have explained everything step by step is phenomenal. I really appreciate your work. Keep it up!!! In case, if you are looking

Avatar_small
사설토토 추천 说:
2024年1月25日 17:36

Hi, I find reading this article a joy. It is extremely helpful and interesting and very much looking forward to reading more of your work.

Avatar_small
사설토토 说:
2024年1月25日 17:39

I'm impressed by the variety of topics you cover. Letari Studio offers a comprehensive range of services, including pre-wedding shoots, actual day coverage, cinematic highlight videos, and destination wedding packages.

Avatar_small
토토하우스주소 说:
2024年1月25日 17:49

Hi, I find reading this article a joy. It is extremely helpful and interesting and very much looking forward to reading more of your work.

Avatar_small
슈어맨배너 说:
2024年1月25日 17:57

Partaking in a particularly overpowering undertaking utilizes a great deal of our assets. Appreciation for sharing. I regard your site's facilities and strong data. Look at our site, and we will find you.

Avatar_small
사설토토 说:
2024年1月25日 18:06

Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing. Keep blogging,

Avatar_small
먹튀검증 说:
2024年1月25日 18:16

I recently came across your blog and have been reading along. I thought I would leave my first comment.

Avatar_small
사설먹튀검증업체 说:
2024年1月25日 18:22

Hi, I find reading this article a joy. It is extremely helpful and interesting and very much looking forward to reading more of your work.

Avatar_small
안전놀이터 说:
2024年1月25日 18:23

Hi, I find reading this article a joy. It is extremely helpful and interesting and very much looking forward to reading more of your work.

Avatar_small
먹튀검증소주소 说:
2024年1月25日 18:30

Great to be here in your article or post, whatever, I figure I ought to likewise buckle down for my own site like I see some great and refreshed working in your site.

Avatar_small
먹튀사이트 说:
2024年1月25日 18:39

Acknowledges for paper such a beneficial composition, I stumbled beside your blog besides decipher a limited announce. I want your technique of inscription.

Avatar_small
메이저사이트추천 说:
2024年1月25日 18:48

Acknowledges for paper such a beneficial composition, I stumbled beside your blog besides decipher a limited announce. I want your technique of inscription.

Avatar_small
seo service UK 说:
2024年2月22日 20:45

The the next occasion I read a blog, Hopefully it doesnt disappoint me around this blog. What i’m saying is, I know it was my substitute for read, but I really thought youd have something interesting to express. All I hear is often a number of whining about something you could fix in the event you werent too busy in search of attention

Avatar_small
seo service UK 说:
2024年2月22日 20:46

The the next occasion I read a blog, Hopefully it doesnt disappoint me around this blog. What i’m saying is, I know it was my substitute for read, but I really thought youd have something interesting to express. All I hear is often a number of whining about something you could fix in the event you werent too busy in search of attention


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter