Particle Swarm Optimization

Library

A C++ library (with Python bindings) for using Particle Swarm Optimization is avaiable on the popot google code project.

Examples

On the illustration below, you find the evolution of a swarm with a full connectivity, involving 16 particles on the 2D Rastrigin function. This function is displayed below :

The rastrigin cost function

We consider three conditions (see the documentation for the meaning of the parameters) :

  • Cognitive only with w = 0.729844, c1=1.496180, c2=0
  • Social only with w = 0.729844, c1=0, c2=1.496180
  • Both cognitive and social with w = 0.729844, c1=c2=1.496180

This leads to the behaviors shown below :

Cognitive only Social only Cognitive and social
pso_cognitive pso_social pso_both

Repeating the optimization for 1000 trials, allowing the swarm to iterate over 1000 steps, we get the following mean best fitness on the 2D Rastrigin function (the fitness can actually be much smaller than the mean that is plotted, but some cases fail and get stuck in local minima which increases the plotted mean).

Fitnesses of PSOs on the rastrigin cost function

We can even introduce a plateau in the cost function. Below we also used a Rastrigin function with a plateau at 800 on the square [-7.5, 7.5]x[-7.5,7.5]. The minimum of the rastrigin was shifted to (10,10). It took around 100 steps to converge below 1e-7.

PSO on rastrigin with a plateau