Why study a benchmark function?
Real research objectives — calibrating a behavioral model, tuning a simulation, or solving a comfort-weighted pedestrian network design (PedNetOpt) — are often nonconvex, multimodal, and expensive to evaluate. Before trusting an optimizer on such a black box, it has to be validated on landscapes where the answer is known. That is exactly what synthetic benchmark functions are for: the global optimum, the number and placement of local minima, and the difficulty are all known in advance, so an optimizer’s behavior can be measured rather than guessed (Jamil & Yang, 2013).
The Ackley function (Ackley, 1987) is one of the most widely used of these tests. Its mix of a single deep basin and a dense field of shallow local minima makes it a clean probe for one specific question: can this optimizer escape local minima and find the global basin, or does it get stuck?
Mathematical definition
\[f(\mathbf{x}) = -a \cdot \exp\!\left(-b \sqrt{\tfrac{1}{d}\sum_{i=1}^{d} x_i^2}\right) - \exp\!\left(\tfrac{1}{d}\sum_{i=1}^{d} \cos(c\, x_i)\right) + a + e\]with the standard parameters $a = 20$, $b = 0.2$, $c = 2\pi$, where $d$ is the dimensionality and $e$ is Euler’s number.
| Property | Value / classification |
|---|---|
| Global minimum | $f(\mathbf{0}) = 0$ at $\mathbf{x} = \mathbf{0}$ |
| Search domain | $x_i \in [-32.768,\ 32.768]$ (SFU standard; $[-5, 5]$ also common) |
| Modality | Multimodal — many local minima |
| Separability | Non-separable (the first term couples all dimensions) |
| Scalability | Defined for any $d$; difficulty grows with $d$ |
| Continuity | Continuous, almost-everywhere differentiable |
Classification follows the benchmark survey of Jamil & Yang (2013).
Landscape analysis
The function is the sum of two competing terms:
- First term $-a\,\exp(-b\sqrt{\cdot})$ — a smooth, near-Gaussian well centered at the origin. Because it depends on $\lVert\mathbf{x}\rVert$, it couples every dimension and gives the global structure: a single basin surrounded by an almost-flat plateau.
- Second term $-\exp(\overline{\cos(\cdot)})$ — a periodic ripple from the cosine that studs the whole domain with regularly spaced local minima.
The combination produces the behavior that makes Ackley a good test:
- a single global minimum at the center;
- a nearly flat outer region where the gradient is tiny and uninformative, so local search stalls;
- many local minima along the way that trap descent-based methods.
This is why gradient-based and local optimizers reliably fail on Ackley unless started near the center, while population-based / global methods (Differential Evolution, CMA-ES, Particle Swarm, Genetic Algorithms) are designed precisely to traverse the plateau and escape the local minima — the property the benchmark is meant to expose.
Python implementation
import numpy as np
def ackley(X, a=20, b=0.2, c=2 * np.pi):
"""Ackley function, vectorized over a batch of points.
X : array of shape (n, d) — each row is a d-dimensional point.
Returns array of shape (n,) of function values (global min = 0 at origin).
"""
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
Visualizing the landscape (2D)
import numpy as np
import matplotlib.pyplot as plt
g = np.linspace(-5, 5, 400)
XX, YY = np.meshgrid(g, g)
ZZ = ackley(np.c_[XX.ravel(), YY.ravel()]).reshape(XX.shape)
plt.contourf(XX, YY, ZZ, levels=50, cmap="viridis")
plt.colorbar(label="f(x, y)")
plt.scatter([0], [0], c="red", marker="*", s=120, label="global min")
plt.legend(); plt.title("Ackley function (d = 2)")
plt.show()
The contour shows the funnel-to-the-center structure: a ring of local minima around a single deep basin, embedded in a flat outer plateau.
A fair benchmarking protocol
A single run says almost nothing — optimizer performance on a multimodal landscape is stochastic. To compare methods honestly:
- Vary dimensionality ($d = 2, 10, 30, \dots$): Ackley gets harder as $d$ grows, and methods separate.
- Multiple random seeds (e.g. 30 independent runs) under a fixed evaluation budget, so cost is held constant across optimizers.
- Report distributions, not single numbers — mean ± std of the best value found, success rate (fraction of runs reaching $f < \varepsilon$), and convergence curves (best-so-far vs. evaluations).
import numpy as np
from scipy.optimize import differential_evolution, minimize
def best_of(method, d, seed, budget=2000):
rng = np.random.default_rng(seed)
bounds = [(-32.768, 32.768)] * d
f = lambda x: float(ackley(np.atleast_2d(x))[0])
if method == "gradient": # local: random start + L-BFGS-B
x0 = rng.uniform(-32.768, 32.768, size=d)
return minimize(f, x0, method="L-BFGS-B", bounds=bounds).fun
if method == "de": # global: differential evolution
res = differential_evolution(f, bounds, seed=seed,
maxiter=budget // (15 * d), polish=True)
return res.fun
# 30 seeds per method → compare distributions, not a single lucky run
for d in (2, 10, 30):
for m in ("gradient", "de"):
vals = [best_of(m, d, s) for s in range(30)]
print(f"d={d:2d} {m:8s} mean={np.mean(vals):.3f} std={np.std(vals):.3f}")
Run as-is, this reproduces the textbook pattern: the local method is dominated by where it happens to start and rarely reaches the global basin as $d$ grows, while the global method stays near $f \approx 0$ — the qualitative result that motivates choosing gradient-free solvers for multimodal problems (Jamil & Yang, 2013). (Exact numbers depend on seed, budget, and solver settings — the point is the protocol and the gap between method classes, not any single figure.)
Relevance to my research
Pedestrian-network and behavioral objectives are frequently nonconvex and expensive (each evaluation may require an equilibrium solve or a simulation). Ackley is the controlled setting where I can check, before spending that compute, whether a candidate optimizer (a) escapes deceptive local minima and (b) keeps working as dimensionality rises. That diligence carries directly into work like the comfort-weighted bilevel design in PedNetOpt, where the objective landscape is far less forgiving than a textbook function.
References
- Ackley, D. H. (1987). A Connectionist Machine for Genetic Hillclimbing. Kluwer Academic Publishers.
- Jamil, M., & Yang, X.-S. (2013). A literature survey of benchmark functions for global optimization problems. International Journal of Mathematical Modelling and Numerical Optimisation, 4(2), 150–194.
- Surjanovic, S., & Bingham, D. Virtual Library of Simulation Experiments: Ackley Function. sfu.ca/~ssurjano/ackley.html