2011-12-05 19:49:55
Tags: Swarm intelligent Leisure ant colony optimization pso optimization particle swarm optimization original works, allow reprint, please be sure to use hyperlinks in the form of the original source of the article, author information and this Statement. otherwise, the legal liability will be investigated. http://nxlhero.blog.51cto.com/962631/734212
Particle swarm optimization (pso) algorithm belongs to swarm intelligence (swarm Intelligence) optimization algorithm. Group intelligence is divided into two kinds, one is particle swarm optimization, the other is ant colony Optimization.
Swarm Intelligence Concept
Suppose you and your friend are looking for treasure, and everyone has a detector that knows the distance from the treasure to the Detector. You guys are looking, everyone can share the information, and you can have your teammates ' vision when you play dota, you can know the distance of everyone else from the treasure, so that you see who is nearest to the treasure, to whom to close, this will make you find the treasure of the opportunity to become larger, and this method than you single-looking more quickly.
This is a simple example of a group behavior (swarm behavior) in which each individual interacts, using a method more efficient than a single individual to solve a global goal. A group (swarm) can be defined as a collection of structures or agents of an interaction, and in the study of swarm intelligence computation, the individual groups of groups include ants, termites, bees, wasps, fish, birds, etc. In these groups, individuals are structurally simple, and their collective behavior can become quite complex. The researchers found that the Ant's transport route between the Bird's Nest and the food, no matter how random the beginning, eventually found a shortest path.
Particle swarm optimization Concept
Particle swarm optimization (particle swarm Optimization,pso) algorithm is based on group search, which is based on the simulation of bird Society. The initial meaning of the swarm concept is to simulate the graceful and unpredictable dance movements of birds through graphs, discovering the ability of the birds to control simultaneous flight and to suddenly change the direction of flight and re-formation in the best formation. This concept has been included in a simple and efficient optimization algorithm.
In pso, individuals called "particles" (particle) "flow" through the hyper-dimensional search Space. The change in the position of the particle in the search space is based on the Individual's success in exceeding the social psychological intentions of other individuals, so the change of particles in a group is affected by the experience or knowledge of its neighboring particles (individuals). The search behavior of a particle is affected by the search behavior of other particles in the Group. therefore, particle swarm optimization is a symbiotic cooperative algorithm.
Algorithm description
Let's describe it in one image: 5 birds foraging, each bird knows its distance from food, and shares this information with other BIRDS.
At first, 5 birds scattered in different places, assuming that no bird updates its speed and direction every second, the question is how to update it?
Each bird notes its nearest position to the food, called pbest,pbest0,pbest1,.. Pbest of 5 birds, Choose a gbest from here, the best in the Group.
Every second, the bird updates its own speed v (here is the vector),
V_new = v_old + c1*rand () * (pbest-pcurrent) +c2*rand () * (gbest-pcurrent)
C1,C2 generally 2,rand () generates 0~1 random Numbers.
Then fly at this speed for 1 seconds, update again, and eventually get closer to the Food.
The following pseudo-code from the Baidu Encyclopedia
The pseudo code of the program is as follows
For each particle
____initialize particle
END
Do
____for each particle
________calculate Fitness Value
________if The fitness value is better than the best fitness value (pbest) in history
____________set current value as the new Pbest
____end
____choose the particle with the best fitness value of the the particles as the gbest
____for each particle
________calculate particle velocity According equation (a)
________update particle position according equation (b)
____end
While maximum iterations or minimum error criteria are not attained
The speed of each particle is limited to a maximum speed vmax, and if a dimension is updated faster than the user-defined vmax, the speed of this dimension is limited to vmax.
Program examples
Calculates the minimum value of f (x) = x*x-20x + 100 and the x when the minimum value is taken
- #include <iostream>
- #include <cmath>
- #include <cstdlib>
- Using namespace std;
- #define C1 2
- #define C2 2
- #define VMAX 5.0
- #define MAX_ITERATIONS 100
- Float RAND01 ()
- {
- return (float) (rand ()/(double) rand_max);
- }
- struct particle{
- float current;
- float pbest;
- };
- Float Fitness (float x)
- {
- return x*x-20*x + 100;
- }
- float gbest = 10000;
- struct particle p[5];
- float v[5] = {0};
- void Init_particles ()
- {
- int i;
- for (i = 0; i < 5; i++)
- {
- P[i].current = -2+i;
- P[i].pbest = p[i].current;
- }
- }
- void Find_gbest ()
- {
- int i;
- for (i = 0; i < 5; i++)
- {
- if (fitness (gbest) > Fitness (p[i].current))
- Gbest = p[i].current;
- }
- }
- void Adjust_v ()
- {
- int i;
- for (i = 0; i < 5; i++)
- {
- v[i] = v[i] + c1*rand01 () * (p[i].pbest-p[i].current) + c2*rand01 () * (gbest-p[i].current);
- if (v[i] > VMAX)
- v[i] = VMAX;
- }
- }
- void PSO ()
- {
- int i,iter_num;
- Iter_num = 1;
- while (iter_num < Max_iterations)
- {
- /*for (i = 0; i < 5; i++)
- {
- cout << "p" <<i<< ": current" <<p[i].current<< "pbest" <<p[i].pbest<<endl;
- }
- cout << "gbest:" <<gbest<<endl;
- cout <<endl;
- GetChar (); */
- for (i = 0; i < 5; i++)
- {
- if (fitness (p[i].current) < fitness (p[i].pbest))
- P[i].pbest = p[i].current;
- }
- Find_gbest ();
- Adjust_v ();
- for (i = 0; i < 5; i++)
- P[i].current + = v[i];
- Iter_num + +;
- }
- }
- int main ()
- {
- Init_particles ();
- PSO ();
- printf ("after%d iterations,gbest is%f\n", max_iterations,gbest);
- return 0;
- }
Run results
Here is the result after each iteration, and you can see that after 5 iterations, the results are good.
- After 1 iterations
- P0:current-2 pbest-2
- P1:current-1 pbest-1
- P2:current 0 Pbest 0
- P3:current 1 Pbest 1
- P4:current 2 Pbest 2
- gbest:10000
- After 2 iterations
- P0:current 1.15506 pbest-2
- P1:current 3.79064 pbest-1
- P2:current 0.790205 pbest 0
- P3:current 2.53646 pbest 1
- P4:current 2 Pbest 2
- Gbest:2
- After 3 iterations
- P0:current 6.15506 pbest 1.15506
- P1:current 8.58128 pbest 3.79064
- P2:current 5.79021 pbest 0.790205
- P3:current 5.87216 pbest 2.53646
- P4:current 4.17373 pbest 2
- gbest:3.79064
- After 4 iterations
- P0:current 11.1551 pbest 6.15506
- P1:current 13.3719 pbest 8.58128
- P2:current 10.7902 pbest 5.79021
- P3:current 9.79741 pbest 5.87216
- P4:current 8.27141 pbest 4.17373
- gbest:8.58128
- After 5 iterations
- P0:current 13.8766 pbest 11.1551
- P1:current 10.1764 pbest 8.58128
- P2:current 14.7492 pbest 10.7902
- P3:current 13.7227 pbest 9.79741
- P4:current 13.2714 pbest 8.27141
- gbest:9.79741
- After 6 iterations
- P0:current 8.03327 pbest 11.1551
- P1:current 6.98078 pbest 10.1764
- P2:current 13.2414 pbest 10.7902
- P3:current 4.78856 pbest 9.79741
- P4:current 11.6974 pbest 8.27141
- gbest:10.1764
- After 7 iterations
- P0:current 5.84287 pbest 11.1551
- P1:current 9.25245 pbest 10.1764
- P2:current 5.23059 pbest 10.7902
- p3:current-3.28694 pbest 9.79741
- P4:current 9.93147 pbest 11.6974
- gbest:10.1764
This article is from the "niu blog" blog, make sure to keep this source http://nxlhero.blog.51cto.com/962631/734212
Particle swarm optimization algorithm