Overview

7 Swarm intelligence: Particles

Swarm intelligence uses the collective, emergent behavior of many simple agents to solve hard problems, and particle swarm optimization (PSO) is a practical embodiment of this idea. Inspired by phenomena like bird flocks and bee swarms—and abstracted by rules such as alignment, cohesion, and separation—PSO deploys a population of “particles” that explore a search space and gravitate toward promising regions discovered by themselves and their peers. It is particularly effective for large, continuous, and high-dimensional optimization tasks in which exhaustive search is infeasible and the global optimum can be obscured by many local optima.

The chapter reframes optimization as navigating a multidimensional landscape defined by a fitness function, where each input variable is a dimension and the function value represents solution quality. Through a concrete drone-design example (cast on a known benchmark surface), it shows how particles carry position, velocity, and a memory of their personal best, while the swarm tracks the global best. PSO’s lifecycle is simple but powerful: initialize a well-distributed swarm, evaluate fitness, and iteratively update velocities and positions. Movement blends three forces: inertia (momentum for exploration), a cognitive pull toward a particle’s personal best, and a social pull toward the swarm’s best. Tuning particle count, initialization, and the inertia/cognitive/social constants balances exploration and exploitation to avoid premature convergence while accelerating progress toward good solutions.

Convergence is monitored across iterations, with practical stopping criteria such as a fixed budget or stagnation of the best fitness; parameters can be adjusted if the swarm stalls in a local optimum. In the worked example, the swarm correctly converges to the known global optimum, illustrating PSO’s dynamics and the role of personal and global memories. Beyond toy functions, PSO serves as a versatile black-box optimizer: it can co-optimize neural network weights, improve motion tracking in videos, enhance speech by tuning noise-reduction filters, and even configure electrode directions in deep brain stimulation to maximize therapeutic targets while minimizing side effects and energy use. Overall, PSO offers an intuitive, implementation-friendly approach to navigating vast search spaces with minimal problem-specific assumptions.

An example bird flock formation
Rules that guide a swarm
A bee swarm converging on its goal
Pepper spice vs. pepper size
Pepper spice vs. pepper size trend
An example function for pepper spice vs. pepper size
Pepper spice vs. pepper size vs. pepper color
A function visualized in the 3D space as a plane
The function that represents the surface in figure 7.8
The drone optimization example
The example function for optimizing aluminum (x) and plastic (y)
Properties of a particle
The life cycle of a particle swarm optimization algorithm
Set up the particles.
A visualization of the initial positions of four particles in a 3D plane
Calculate the fitness of the particles.
The example function for optimizing aluminum (x) and plastic (y)
Fitness calculations for each particle
Update the positions of the particles.
The movement of particles over five iterations
Formula to calculate velocity
The intuition of the factors influencing velocity updates
Particle velocity calculation walkthrough
Calculating the new position of a particle
Particle velocity calculation walkthrough
A visualization of the movement of particles in the search space
Visualization of convergence of particles and a known surface
Has the algorithm reached a stopping condition?
Exploration converging and exploiting
Example of factors involved for probes in deep brain stimulation

Summary of particle swarm optimization

FAQ

What is Particle Swarm Optimization (PSO) and what inspired it?PSO is a population-based optimization method that uses the collective behavior of many simple agents (particles) to search for good solutions. It is inspired by swarm intelligence in nature—like bird flocks and bee swarms—where simple local rules (such as alignment, cohesion, and separation) produce effective group behavior that finds food sources or energy-efficient formations.
How does PSO frame an optimization problem?PSO treats candidate solutions as points (particle positions) in an N-dimensional search space, where each dimension corresponds to a decision variable. A fitness (objective) function maps each position to a score that should be minimized or maximized. Particles move through the space, and the algorithm seeks positions with optimal fitness. For example, optimizing two material ratios creates a 2D space; the fitness is the performance score at each point.
When is PSO a good choice?PSO is especially useful for large and/or high-dimensional search spaces, nonconvex landscapes with multiple local optima, and problems where gradients are unavailable or expensive. It shines when an exhaustive search is infeasible and a good heuristic search is needed.
What information does each particle carry?A particle maintains: - Position: its current coordinates in all dimensions - Velocity: the direction and step size of its next move - Personal best (position and fitness): the best location it has discovered so far The swarm also tracks the global (or neighborhood) best across all particles.
How do you initialize a PSO swarm?Choose a number of particles (often 50–100 as a practical starting range), place each at a random position uniformly within problem bounds, and give each a small random initial velocity (instead of zero) to encourage immediate exploration. Ensure bounds reflect problem constraints.
How is fitness computed and used during the run?At each iteration, evaluate the fitness function at every particle’s position. Update each particle’s personal best if the new fitness improves on its history. Identify the swarm’s global best as the best fitness among all particles. These bests guide subsequent movement.
How are particle velocities updated, and what’s the intuition?Each new velocity is the sum of three influences: - Inertia: keep some of the current velocity (controls momentum) - Cognitive: pull toward the particle’s personal best (self-exploration) - Social: pull toward the swarm’s global best (group convergence) Constants and random factors scale the cognitive and social pulls. Intuitively: inertia preserves motion, cognitive revisits what worked for the individual, and social follows what works for the group.
How do the inertia, cognitive constant, and social constant affect behavior? - Higher inertia favors exploration (particles maintain momentum and roam farther). Lower inertia favors exploitation (fine-tuning near good regions). - Higher cognitive constant makes particles rely more on their own discoveries (diversifies search). - Higher social constant makes particles follow the global best more aggressively (faster convergence, risk of premature collapse).
How are positions updated and what happens over iterations?After computing a new velocity, update the position by adding velocity to the current coordinates. Re-evaluate fitness, refresh personal and global bests, and repeat. Over iterations, particles typically spread out to explore, then converge toward promising areas and cluster around strong solutions.
What stopping criteria and applications does the chapter highlight?Common stopping rules include a maximum number of iterations and stagnation detection (when the global best no longer improves meaningfully). Applications discussed include: tuning a drone’s material ratio (demonstrated with the Booth function, which has a known minimum at x=1, y=3), optimizing neural network weights, motion tracking in videos, speech enhancement, and deep brain stimulation electrode configuration.

pro $24.99 per month

  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose one free eBook per month to keep
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime

lite $19.99 per month

  • access to all Manning books, including MEAPs!

team

5, 10 or 20 seats+ for your team - learn more


choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking AI Algorithms, Second Edition ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking AI Algorithms, Second Edition ebook for free
choose your plan

team

monthly
annual
$49.99
$499.99
only $41.67 per month
  • five seats for your team
  • access to all Manning books, MEAPs, liveVideos, liveProjects, and audiobooks!
  • choose another free product every time you renew
  • choose twelve free products per year
  • exclusive 50% discount on all purchases
  • renews monthly, pause or cancel renewal anytime
  • renews annually, pause or cancel renewal anytime
  • Grokking AI Algorithms, Second Edition ebook for free