HomeArticlesAlgorithms

Particle Swarm Optimization: Swarm Intelligence Explained

In 1995, watching starlings bank and wheel as one flock became a gradient-free algorithm that finds global optima with almost no tuning.

mysimulator teamUpdated July 2026≈ 9 min read▶ Open the simulation

A flock's memory, turned into an algorithm

Kennedy and Eberhart's 1995 insight was deceptively simple: good solutions attract neighbours. Just as a bird adjusts its flight to keep up with its flock while remembering where it personally found the best food, each particle in PSO carries a social memory — the swarm's best-known position, gbest — and a cognitive memory, its own best-known position, pbest. PSO belongs to the broader family of swarm intelligence algorithms (alongside Ant Colony Optimisation and Artificial Bee Colony), all sharing the property of emergence: near-optimal global behaviour from simple local rules, with no centralised control.

The velocity update equation

A swarm of N particles is initialised at random positions in the search space. At each iteration, every particle updates its velocity from three forces — inertia (keep moving in the current direction), a cognitive pull toward its own best-known position, and a social pull toward the swarm's global best — then updates its position by simply adding the new velocity. The random scalars r1 and r2 are resampled per particle, per dimension, per iteration, which is essential: without that randomness, particles in a symmetric configuration could lock into identical movement and the swarm would collapse to a deterministic pattern.

v(t+1) = ω·v(t) + c1·r1·(pbest − x(t)) + c2·r2·(gbest − x(t))
x(t+1) = x(t) + v(t+1)

Typical: ω 0.4→0.9 (linearly decayed), c1 = c2 = 1.5–2.0
Clerc's constriction values: ω = 0.729, c1 + c2 ≤ 4

Convergence, stagnation, and the ring topology fix

Clerc and Kennedy (2002) formalised PSO's convergence conditions: without parameter control the swarm can oscillate and never settle, but a region of (ω, c1, c2) space — the convergence triangle — guarantees a stable trajectory. The most common failure mode is premature convergence, where the whole swarm collapses onto a local optimum before exploring the space, typically because the social coefficient c2 dominates or diversity has already been lost. Mitigations include random restarts for stagnated particles or switching from a single shared gbest to a local (lbest) ring topology, where each particle only sees its nearest neighbours — slower to converge, but far more resistant to getting trapped in one basin.

PSO versus genetic algorithms and simulated annealing

PSO, genetic algorithms and simulated annealing are all gradient-free, but they differ in mechanism: PSO moves a population continuously via velocity and persistent memory (pbest, gbest); a genetic algorithm applies crossover and mutation with selection pressure and no per-individual memory; simulated annealing perturbs a single solution under a cooling temperature schedule. In practice PSO is often preferred for continuous, low-to-medium dimensional problems (≤100 dimensions) because it's simple to implement and converges in a few dozen iterations — from engineering design and PID tuning to wind-farm layout optimisation and hyperparameter search.

Frequently asked questions

What do the three terms in the PSO velocity update mean?

Inertia (ω·v) is momentum — the particle keeps moving in its current direction. The cognitive term (c1·r1·(pbest−x)) pulls the particle back toward its own best-ever position. The social term (c2·r2·(gbest−x)) pulls it toward the swarm's best-known position. Random scalars r1 and r2 are resampled every dimension every step, which prevents the swarm from locking into a deterministic, gradient-like pattern.

What causes premature convergence in PSO and how is it fixed?

Premature convergence happens when the entire swarm converges on a local optimum before exploring the full search space, usually because the social coefficient c2 is too large relative to c1, or the swarm has lost diversity. Mitigations include random restarts for stagnated particles, switching to a local-neighbourhood (lbest, ring) topology instead of a single shared global best, or simply increasing swarm size.

How does PSO compare to a genetic algorithm?

Both are population-based and gradient-free, but PSO moves particles continuously through velocity updates guided by memory (pbest, gbest), while a genetic algorithm applies crossover and mutation with selection pressure and no persistent per-individual memory. PSO tends to converge faster on continuous, low-to-medium dimensional problems, while GAs are more natural for combinatorial problems and structural variation.

Try it live

Everything above runs in your browser — open Particle Swarm Optimization and watch a swarm of particles converge on the global minimum of several test functions, tuning inertia, cognitive and social weights live. Nothing is installed, nothing is uploaded.

▶ Open Particle Swarm Optimization simulation

What did you find?

Add reproduction steps (optional)