Population-Based Algorithms

Population-based algorithms maintain a collection of candidate solutions (individuals) that evolve together. They share information about promising regions and provide natural parallelism for multi-core systems.

Overview

Algorithm

Description

Particle Swarm Optimization

Particles move toward best positions with velocity dynamics.

Spiral Optimization

Particles spiral inward toward the global best.

Parallel Tempering

Multiple simulated annealers at different temperatures.

Genetic Algorithm

Selection, crossover, and mutation inspired by evolution.

Evolution Strategy

Population of hill climbers with occasional mixing.

Differential Evolution

Creates new solutions from weighted differences.

CMA-ES

Adapts a full covariance matrix to learn landscape structure.

When to Use Population-Based

Good for:

  • Multi-modal landscapes with distinct basins

  • Problems that benefit from parallelization

  • Discrete and combinatorial optimization (GA, DE)

  • Robust optimization in noisy environments

Not ideal for:

  • Very expensive objective functions (each iteration evaluates N individuals)

  • Simple unimodal functions (overkill)

  • Very tight computational budgets

Common Parameters

All population-based algorithms share:

Parameter

Default

Description

population

10

Number of individuals in the population

Population Size

Larger populations provide better coverage but require more evaluations per iteration:

from gradient_free_optimizers import ParticleSwarmOptimizer

# Small population - faster iterations, may miss optima
opt = ParticleSwarmOptimizer(search_space, population=5)

# Large population - thorough coverage, slower iterations
opt = ParticleSwarmOptimizer(search_space, population=50)

Tip

Rule of thumb: Use population = 10 * n_dimensions as a starting point, then adjust based on convergence behavior.

Algorithm Comparison

Algorithm

Information Sharing

Best For

Key Feature

Particle Swarm

Global + Personal best

Continuous optimization

Velocity-based movement

Spiral

Global best

Balanced exploration

Spiral trajectories

Parallel Tempering

Temperature swaps

Multi-modal

Temperature diversity

Genetic Algorithm

Crossover

Discrete/combinatorial

Evolutionary operators

Evolution Strategy

Selection

Noisy optimization

Robust selection

Differential Evolution

Difference vectors

Non-linear continuous

Self-adaptive steps

CMA-ES

Covariance matrix

Correlated continuous

Full covariance adaptation

Conceptual Comparison

Population-based algorithm comparison

How different population-based algorithms move their individuals. PSO uses velocity vectors, GA recombines parent genes, and DE creates new candidates from weighted differences.

Visualization

Particle Swarm on Sphere function

Particle Swarm: particles converge toward the best known position.

Genetic Algorithm on Sphere function

Genetic Algorithm: population evolves through selection and crossover.

Evolution Strategy on Sphere function

Evolution Strategy: population of hill climbers with selection.

Differential Evolution on Sphere function

Differential Evolution: creates trials from weighted differences.

Example: Particle Swarm Optimization

import numpy as np
from gradient_free_optimizers import ParticleSwarmOptimizer

def rastrigin(para):
    x = para["x"]
    y = para["y"]
    A = 10
    return -(A * 2 + (x**2 - A * np.cos(2 * np.pi * x))
                  + (y**2 - A * np.cos(2 * np.pi * y)))

search_space = {
    "x": np.linspace(-5.12, 5.12, 100),
    "y": np.linspace(-5.12, 5.12, 100),
}

opt = ParticleSwarmOptimizer(
    search_space,
    population=20,
    inertia=0.5,
    cognitive_weight=0.5,
    social_weight=0.5,
)

opt.search(rastrigin, n_iter=200)
print(f"Best: {opt.best_para}, Score: {opt.best_score}")

Algorithms