Skip to content

Cuckoo Search

Swarm Intelligence

Cuckoo Search (CS) optimization algorithm.

Algorithm Overview

This module implements the Cuckoo Search (CS) optimization algorithm. CS is a nature-inspired metaheuristic algorithm, which is based on the obligate brood parasitism of some cuckoo species. In these species, the cuckoos lay their eggs in the nests of other host birds. If the host bird discovers the eggs are not their own, it will either throw these alien eggs away or abandon its nest and build a completely new one.

In the context of the CS algorithm, each egg in a nest represents a solution, and a cuckoo egg represents a new solution. The aim is to use the new and potentially better solutions (cuckoo eggs) to replace a not-so-good solution in the nests. In the simplest form, each nest represents a solution, and thus the egg represents a new solution that is to replace the old one if the new solution is better.

The CS algorithm is used to solve optimization problems by iteratively trying to improve a candidate solution with regard to a given measure of quality, or fitness function.

Usage

python
from opt.swarm_intelligence.cuckoo_search import CuckooSearch
from opt.benchmark.functions import sphere

optimizer = CuckooSearch(
    func=sphere,
    lower_bound=-5.12,
    upper_bound=5.12,
    dim=10,
    max_iter=500,
    population_size=50,
)

best_solution, best_fitness = optimizer.search()
print(f"Best solution: {best_solution}")
print(f"Best fitness: {best_fitness:.6e}")

Parameters

ParameterTypeDefaultDescription
funcCallableRequiredObjective function to minimize.
lower_boundfloatRequiredLower bound of search space.
upper_boundfloatRequiredUpper bound of search space.
dimintRequiredProblem dimensionality.
population_sizeint100Number of nests (solutions) in the population.
max_iterint1000Maximum iterations.
mutation_probabilityfloat0.1Probability of abandoning a nest (discovery rate pa).
seedint | NoneNoneRandom seed for reproducibility.

Algorithm Metadata

PropertyValue
Algorithm NameCuckoo Search
AcronymCS
Year Introduced2009
AuthorsYang, Xin-She; Deb, Suash
Algorithm ClassSwarm Intelligence
ComplexityO(population_size * dim * max_iter)
PropertiesPopulation-based, Derivative-free, Nature-inspired
ImplementationPython 3.10+
COCO CompatibleYes

Mathematical Formulation

Core update equation using Lévy flights:

xit+1=xit+αLévy(λ)

where:

  • xit is the position of nest i at iteration t
  • α>0 is the step size (typically α=1)
  • denotes entry-wise multiplication
  • Lévy(λ) is a Lévy flight with parameter λ=1.5

Lévy flight step:

Lévy(λ)u=tλ,1<λ3

Discovery and randomization:

  • A fraction pa of worst nests are abandoned
  • New random solutions replace abandoned nests
  • Typical pa[0.1,0.3]

Constraint handling:

  • Boundary conditions: Clamping to [lower_bound, upper_bound]
  • Feasibility enforcement: Random repositioning for out-of-bound solutions

Hyperparameters

ParameterDefaultBBOB RecommendedDescription
population_size10010*dimNumber of nests
max_iter100010000Maximum iterations
mutation_probability0.10.1-0.3Probability of nest abandonment (pa)

Sensitivity Analysis:

  • mutation_probability: High impact - controls exploration vs exploitation balance
  • Recommended tuning ranges: pa[0.1,0.3]
  • Lévy flight parameter λ=1.5 is typically fixed

COCO/BBOB Benchmark Settings

Search Space:

  • Dimensions tested: 2, 3, 5, 10, 20, 40
  • Bounds: Function-specific (typically [-5, 5] or [-100, 100])
  • Instances: 15 per function (BBOB standard)

Evaluation Budget:

  • Budget: dim×10000 function evaluations
  • Independent runs: 15 (for statistical significance)
  • Seeds: 0-14 (reproducibility requirement)

Performance Metrics:

  • Target precision: 1e-8 (BBOB default)
  • Success rate at precision thresholds: [1e-8, 1e-6, 1e-4, 1e-2]
  • Expected Running Time (ERT) tracking

Raises

ValueError: If search space is invalid or function evaluation fails.

Notes

  • Modifies self.history if track_history=True
  • Uses self.seed for all random number generation
  • BBOB: Returns final best solution after max_iter or convergence

Computational Complexity:

  • Time per iteration: O(population_size×dim)
  • Space complexity: O(population_size×dim)
  • BBOB budget usage: Typically uses 50-70% of dim*10000 budget for convergence

BBOB Performance Characteristics:

  • Best function classes: Multimodal, High-dimensional problems
  • Weak function classes: Simple unimodal functions (over-explores)
  • Typical success rate at 1e-8 precision: 40-50% (dim=5)
  • Expected Running Time (ERT): Efficient on complex landscapes, competitive with PSO

Convergence Properties:

  • Convergence rate: Sub-linear due to Lévy flight exploration
  • Local vs Global: Excellent global search capability
  • Premature convergence risk: Very Low - Lévy flights prevent stagnation

Reproducibility:

  • Deterministic: Yes - Same seed guarantees same results
  • BBOB compliance: seed parameter required for 15 independent runs
  • Initialization: Uniform random sampling in [lower_bound, upper_bound]
  • RNG usage: numpy.random.default_rng(self.seed) throughout

Implementation Details:

  • Parallelization: Not supported in current implementation
  • Constraint handling: Clamping to bounds and random repositioning
  • Numerical stability: Uses NumPy operations for Lévy flight generation

Known Limitations:

  • Lévy flight implementation may vary across different versions
  • Discovery rate (pa) requires problem-specific tuning
  • BBOB known issues: May be inefficient on simple unimodal functions

Version History:

  • v0.1.0: Initial implementation
  • Current: BBOB-compliant with seed parameter support

References

[1] Yang, X.-S., Deb, S. (2009). "Cuckoo Search via Lévy Flights." In: Proceedings of World Congress on Nature & Biologically Inspired Computing (NaBIC 2009), IEEE Publications, pp. 210-214. https://doi.org/10.1109/NABIC.2009.5393690

[2] Hansen, N., Auger, A., Ros, R., Mersmann, O., Tušar, T., Brockhoff, D. (2021). "COCO: A platform for comparing continuous optimizers in a black-box setting." Optimization Methods and Software, 36(1), 114-144. https://doi.org/10.1080/10556788.2020.1808977

COCO Data Archive:

Implementation:

See Also

FireflyAlgorithm: Another nature-inspired algorithm by Yang BBOB Comparison: CS shows better global search due to Lévy flights

BatAlgorithm: Yang's echolocation-based algorithm BBOB Comparison: Both have similar multimodal performance

FlowerPollination: Also uses Lévy flights for global pollination BBOB Comparison: Similar exploration strategies

AbstractOptimizer: Base class for all optimizers opt.benchmark.functions: BBOB-compatible test functions

Related BBOB Algorithm Classes:

  • Evolutionary: GeneticAlgorithm, DifferentialEvolution
  • Swarm: ParticleSwarm, AntColony, FireflyAlgorithm
  • Gradient: AdamW, SGDMomentum

Benchmark Performance

Interactive fitness landscape of a representative multimodal benchmark function (drag to rotate, scroll to zoom):

Run-based charts

Convergence, distribution and ECDF charts appear here once this optimizer is included in the benchmark suite.


Source Code

View the implementation: cuckoo_search.py

Released under the MIT License.