🐝 Particle Swarm Optimization — Swarm Intelligence
A swarm of particles searches a 2D cost landscape, each pulled toward its personal best and the global best. Watch the flock converge on the global minimum across multiple test functions.
About Particle Swarm Optimisation
Particle Swarm Optimisation (PSO) is a population-based metaheuristic inspired by the collective behaviour of bird flocks and fish schools. Each particle in the swarm maintains a position in the search space and a velocity vector; it is attracted towards both its own personal best-known position and the global best position found by any member of the swarm. The technique was introduced by Kennedy and Eberhart in 1995 and is widely applied to continuous optimisation problems in engineering, neural network training, and financial modelling.
In this simulation you can adjust the swarm size, inertia weight (ω), cognitive coefficient (c₁), and social coefficient (c₂) to observe how they govern convergence speed and the risk of premature stagnation. The coloured trails reveal how individual particles explore the 2D fitness landscape before the swarm collectively homes in on the global minimum.
Frequently Asked Questions
How does a particle update its velocity in PSO?
Each timestep the new velocity is v = ω·v + c₁·r₁·(pBest − x) + c₂·r₂·(gBest − x), where ω is inertia, c₁ and c₂ are acceleration coefficients, and r₁, r₂ are independent random numbers in [0, 1]. Typical starting values are ω = 0.729, c₁ = c₂ = 1.494, which satisfy convergence conditions derived by Clerc and Kennedy in 2002.
What is the inertia weight and why does it matter?
The inertia weight ω scales the particle's previous velocity, balancing exploration (high ω) against exploitation (low ω). A common strategy is to start with ω ≈ 0.9 and linearly decrease it to 0.4 over the run, encouraging broad search early on and fine-grained convergence later. Setting ω ≥ 1 typically causes the swarm to diverge.
Can PSO get stuck in local optima?
Yes — PSO is not guaranteed to find the global optimum. On multimodal functions such as the Rastrigin or Ackley benchmark, premature convergence occurs when all particles cluster around a local minimum before the neighbourhood has been adequately explored. Remedies include increasing population size, using random re-initialisation for stagnant particles, or hybridising with a local search.
What is the difference between the global and local best topology?
In the global (gbest) topology every particle is attracted to the single best position found by any particle. In a ring (lbest) topology each particle only sees a small neighbourhood, which slows convergence but improves exploration on deceptive multimodal landscapes. The simulation uses the gbest topology for clarity.
How does PSO compare to a genetic algorithm?
Both are population-based metaheuristics, but PSO has no crossover or mutation operators. Instead, information sharing is implicit through the velocity update rule. PSO typically converges faster on continuous problems but lacks the recombination mechanism that helps genetic algorithms escape local optima on combinatorial problems.
What real-world problems is PSO used for?
PSO has been applied to antenna design, wind-farm layout optimisation, hyperparameter tuning for deep neural networks, power-grid scheduling, and portfolio optimisation. Its strength lies in problems with continuous, multi-dimensional search spaces where gradient information is unavailable or expensive to compute.
What benchmark functions are commonly used to test PSO?
Standard benchmarks include the Sphere (unimodal, easy), Rosenbrock (narrow curved valley), Rastrigin (highly multimodal with 10ⁿ local minima), Ackley, and Griewank functions. The CEC competition suites provide standardised test sets with known global optima to allow fair comparisons across algorithms.
Does the swarm size affect performance?
Larger swarms explore the search space more thoroughly but require more function evaluations per iteration. Empirically, swarm sizes between 20 and 50 particles perform well on low-dimensional problems (n ≤ 30), while higher-dimensional problems may benefit from 100–200 particles. Too small a swarm dramatically increases the risk of premature convergence.
Is PSO deterministic?
No. The random numbers r₁ and r₂ in the velocity update make each run stochastic. Results therefore vary between runs, and algorithm comparisons should report statistics (median, best, worst) over multiple independent runs — typically 25 to 51 runs per test function, as recommended by CEC benchmarking guidelines.
What is velocity clamping and why is it used?
Velocity clamping restricts each velocity component to the range [−Vmax, +Vmax] to prevent particles from flying out of the search space in a single step. Without clamping on high-dimensional problems, runaway velocities can cause the swarm to diverge. A common choice is Vmax = 0.1 × (domain range) per dimension.
A swarm of particles searches a 2D cost landscape, each pulled toward its personal best and the global best. Watch the flock converge on the global minimum across multiple test functions.
3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install