liveBook · Manning

Particle swarm optimization

As explained in Evolutionary Deep Learning: Genetic algorithms and neural networks

Particle swarm optimization is a population-based optimization algorithm in which candidate solutions move through a search space according to collective-swarm behavior.

Particle swarm optimization (PSO) is an evolutionary-computation method that searches with a population of particles. Each particle is evaluated for fitness; fitter particles guide the swarm toward better regions of the solution space. The approach borrows survival-of-the-fittest and swarming behavior rather than relying on genetic operators. section 1.1.1 section 4.6

A particle represents one candidate solution as a vector. It begins at a position within configured bounds and has a speed. On each iteration, the algorithm evaluates every particle, retains each particle’s best-known position, identifies the swarm’s best particle, then updates positions by changing speeds toward those better candidates. Speed limits constrain each update. section 4.2.1

Listing 4.7 EDL_4_2_PSO.ipynb: Setting up the toolbox
toolbox = base.Toolbox()
toolbox.register("particle", 
                 generate, size=2, pmin=-6, 
                  pmax=6, smin=-3, smax=3)             #1
toolbox.register("population", 
                 tools.initRepeat, list, 
                  toolbox.particle)                    #2
toolbox.register("update", 
                 updateParticle, phi1=200, phi2=200)     #3
toolbox.register("evaluate", evaluate)                   #4

Use the toolbox setup to see the four practical PSO operations: create particles, build a population, update movement, and evaluate fitness. section 4.2.1

Finding cannon-shot inputs

PSO can search for the initial velocity and firing angle that send a cannon ball to a target distance. Each particle is one velocity-and-angle guess; fitness is the squared difference between its calculated distance and the target. Repeated evaluation and swarming produce the best parameter pair. section 4.2 section 4.2.1

PSO is useful when a known function has unknown input parameters, and it extends to more-complex optimization problems. A further application is automatic hyperparameter optimization: map a particle vector into bounded hyperparameter values, train a model, use loss as fitness, and swarm toward lower-loss configurations. section 4.6 section 5.4.2

A practical DEAP workflow is:

  • Define a particle generator with position and speed ranges. section 4.2.1
  • Register particle, population, update, and evaluation functions in a toolbox. section 4.2.1
  • Evaluate every particle and record personal and global best candidates. section 4.2.1
  • Update particles toward the global best, then repeat for a chosen number of generations. section 4.2.1

How Evolutionary Deep Learning: Genetic algorithms and neural networks covers it

How deep it goes
Works through DEAP particle generation, fitness evaluation, best tracking, velocity updates, and a complete swarm loop.
Examples
Uses cannon-shot velocity and angle to hit a target distance, plus loss-driven neural-network hyperparameter search.
What it assumes
Builds from genetic-algorithm foundations while distinguishing particle operators from genetic operators.
What you can do after
Apply it via DEAP to optimize function inputs or map particle vectors to model hyperparameters.
How it connects
Connects evolutionary computation with DEAP, hyperparameter optimization, deep learning, genetic algorithms, and differential evolution.

Also explained in

Compare how 3 books explain particle swarm optimization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Evolutionary Deep Learning: Genetic algorithms and neural networks. The section links point to the parts of the book it draws on.