Ackley Function
Ackley Function
The Ackley Function is a widely used benchmark function for testing the performance of optimization algorithms. Proposed by David Ackley in 1987, this function has many local minima, making it suitable for evaluating the escape capability of global optimization algorithms.
Mathematical Definition
\[f(\mathbf{x}) = -a \cdot \exp\left(-b \sqrt{\frac{1}{d}\sum_{i=1}^{d} x_i^2}\right) - \exp\left(\frac{1}{d}\sum_{i=1}^{d} \cos(c \cdot x_i)\right) + a + e\]Parameters:
- $a = 20$ (commonly used value)
- $b = 0.2$
- $c = 2\pi$
- $d$: number of dimensions
- $e$: Euler’s number (≈ 2.71828)
Characteristics
| Property | Value |
|---|---|
| Global Minimum | $f(\mathbf{0}) = 0$ |
| Search Domain | $x_i \in [-5, 5]$ (typical) |
| Features | Many local minima |
| Difficulty | Medium to High |
Python Implementation
import numpy as np
np.random.seed(0)
def ackley(X, a=20, b=0.2, c=2*np.pi):
"""
Compute the Ackley function.
Parameters:
X: A NumPy array of shape (n, d) where each row is a n-dimensional point.
a, b, c: Parameters of the Ackley function.
Returns:
A NumPy array of shape (n,) of function values
"""
X = np.atleast_2d(X)
d = X.shape[1]
sum_sq = np.sum(X ** 2, axis=1)
term1 = -a * np.exp(-b * np.sqrt(sum_sq / d))
term2 = -np.exp(np.sum(np.cos(c * X), axis=1) / d)
return term1 + term2 + a + np.e
Function Structure Analysis
The Ackley Function consists of two main terms:
- First term ($-a \cdot \exp(-b\sqrt{\cdot})$): Creates a deep “well” at the origin
- Second term ($-\exp(\cos(\cdot))$): Generates many local minima through the cosine function
The combination of these two terms results in:
- A single global minimum at the center
- Numerous local minima distributed across the nearly flat outer region
- Gradient-based optimization algorithms easily getting trapped in local minima
Applications
- Performance evaluation of Evolutionary Algorithms
- Testing Particle Swarm Optimization (PSO)
- Benchmarking Bayesian Optimization
- Comparing Gradient-free optimization algorithms
Usage Example
# Single point evaluation
x = np.array([[0, 0]])
print(f"f(0,0) = {ackley(x)[0]:.6f}") # Value close to 0
# Multiple points evaluation
points = np.random.uniform(-5, 5, size=(100, 2))
values = ackley(points)
print(f"Min value: {values.min():.4f}")
print(f"Max value: {values.max():.4f}")
References
- Ackley, D. H. (1987). A Connectionist Machine for Genetic Hillclimbing. Kluwer Academic Publishers.
- Virtual Library of Simulation Experiments
