JSwarm-PSO: Swarm optimization package (original) (raw)

JSwarm-PSO

JSwarm-PSO is a Particle swarm optimization package written in Java. PSO is an optimization technique used to find global optimum for complex problems. Roughly stated, it's in the same 'category' as Genetic algorithms or Simmilated annealing. If you don't know what PSO is, I recommend you to start reading wikipedia's definition. JSwarm-PSO is designed to require minimum effort to use while also highly modular.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Optimization example

This example tries to minimize Rastrigin's function which has infinie local minimum and maximum. You can run the example just typing the command (on unix like enviroments):

java -jar jswarm-pso_VERSION.jar

On Windows it sohuld be enough to just double click on jar file.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

How to optimize your own function / model

This is a simple description of the code you'll find in jswarm-pso.example1:

// Set position (and velocity) constraints.
// i.e.: where to look for solutions
swarm.setMaxPosition(1);
swarm.setMinPosition(0);
// Optimize a few times
for( int i = 0; i < 20; i++ ) swarm.evolve();
// Print en results
System.out.println(swarm.toStringStats())

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Usuall / Deafult settings

Optimization type:

Particle's velocity update (to understand next settings, you'll probably need to read "Particle position and velocity update")

Position restrictions (these restrictions must always be setted):

Velocity restrictions:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Particle position and velocity update

Each time the swarm evolves, updates every particle's position and velocity (see jswarm-pso.Particle.update() for details).
Particle's position is updated (for each dimention i):

// Update position position[i] = position[i] + velocity[i]

While particle's velocity is updated (for each dimention i):

// Update velocity velocity[i] = inertia * velocity[i] // Inertia + rlocal[i] * particleIncrement * (bestPosition[i] - position[i]) // Local best + rglobal[i] * globalIncrement * (globalBestPosition[i] - position[i]); // Global best

where rlocal[i] and rglobal[i] are two random vectors, uniformly distributted on the interval [0,1].

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Author: Pablo Cingolani (pcingola@users.sourceforge.net)