🐝 Particle Swarm
Swarm intelligence optimization
Iteration 0
Best value:
Function
Parameters
Controls
Stats
Iterations
0
Best value
gbest (x, y)
Status
Ready
Info & Theory

Particle swarm optimization (PSO) mimics a flock of birds searching for food. Each particle is a candidate solution that flies through the search space, remembering where it personally did best and listening to the swarm's best find.

The velocity update

Every step each particle updates its velocity:

v = w·v + c1·r1·(pbest − x) + c2·r2·(gbest − x)

  • w — inertia, how much old motion is kept.
  • c1 — cognitive pull toward its own best.
  • c2 — social pull toward the global best.
  • r1, r2 — fresh random numbers in [0, 1].

Then the position moves: x = x + v.

Cost landscape

The background heatmap is the function value (dark = low cost). The swarm tries to reach the darkest point — the global minimum.

Test functions

  • Sphere — one smooth bowl, easy.
  • Rastrigin — many regular local minima.
  • Ackley — flat outer plate, deep central well.
  • Himmelblau — four equal global minima.

Exploration vs exploitation

High inertia and large coefficients spread the swarm out (exploration); low values let it tighten on the best region (exploitation). Tuning this balance is the art of PSO.

FAQ
What is particle swarm optimization?

A population-based metaheuristic inspired by flocking birds. A swarm of candidate solutions (particles) moves through the search space, each guided by its own best position and the swarm's best position.

How is a particle's velocity updated?

With v = w·v + c1·r1·(pbest − x) + c2·r2·(gbest − x), where w is inertia, c1 and c2 are the cognitive and social coefficients, and r1, r2 are random in [0,1]. Then x = x + v.

What are pbest and gbest?

pbest is the best position a single particle has personally visited; gbest is the best position found by the whole swarm. The velocity pulls each particle toward both.

What does the inertia weight w control?

How much of the previous velocity is carried over. High inertia favours exploration; low inertia favours local exploitation. Values around 0.4 to 0.9 are common.

What are the c1 and c2 coefficients?

c1 (cognitive) weights the pull toward a particle's own best; c2 (social) weights the pull toward the global best. Balancing them trades exploration against swarm consensus.

What test functions are used here?

The sphere (one smooth bowl), Rastrigin and Ackley (many local minima), and Himmelblau (four equal global minima) — standard optimisation benchmarks.

How does the swarm avoid local minima?

Particles keep momentum and are pulled toward different attractors, so the swarm spreads out and samples many basins. When one particle finds a better region, gbest updates.

Does PSO always find the global minimum?

No. It is a heuristic with no global guarantee, especially on rugged functions. Larger swarms, tuned coefficients and multiple runs improve the odds.

How is PSO different from a genetic algorithm?

PSO moves existing solutions through space using velocity and shared information, with no crossover or mutation. Genetic algorithms breed new solutions by recombining parents.

Where is PSO used in practice?

Tuning neural networks and controllers, designing antennas and power systems, scheduling, and many continuous problems where gradients are unavailable.

About Particle Swarm Optimisation

Written by MySimulator Team · Reviewed by MySimulator Editorial Review

Last updated: 5 July 2026

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.