Benchmark Functions API
API reference for benchmark functions available in opt.benchmark.functions.
Overview
All benchmark functions share the same interface:
python
from opt.benchmark.functions import sphere, rosenbrock, ackley
import numpy as np
def benchmark_function(x: np.ndarray) -> float:
"""
Args:
x: Input vector of shape (n,)
Returns:
Scalar fitness value (lower is better)
"""
passAvailable Functions
For detailed mathematical definitions and properties, see Benchmark Functions.
Unimodal Functions
sphere(x)- Simple sum of squaresrosenbrock(x)- Rosenbrock valley functionschwefel_2_22(x)- Schwefel 2.22 functionschwefel_1_2(x)- Schwefel 1.2 functionstep(x)- Step function
Multi-Modal Functions
ackley(x)- Ackley functionshifted_ackley(x)- Shifted Ackley functionrastrigin(x)- Rastrigin functiongriewank(x)- Griewank functionlevy(x)- Levy functionschwefel(x)- Schwefel function
Usage
python
from opt.swarm_intelligence import ParticleSwarm
from opt.benchmark.functions import sphere, ackley
# Test with sphere function
optimizer = ParticleSwarm(
func=sphere,
lower_bound=-5.12,
upper_bound=5.12,
dim=10,
max_iter=100
)
best_solution, best_fitness = optimizer.search()
# Test with Ackley function
optimizer = ParticleSwarm(
func=ackley,
lower_bound=-32.768,
upper_bound=32.768,
dim=10,
max_iter=100
)
best_solution, best_fitness = optimizer.search()See Also
- Benchmark Functions Details - Mathematical definitions and properties
- Benchmark Methodology - How benchmarks are conducted
- Benchmark Results - Performance comparison results