function.so.ackley

function.so.ackley(X)

N-dimensional Ackley function.

The Ackley function is a widely used test function for optimization algorithms. It is characterized by a nearly flat outer region and a large hole at the center. The function is multimodal with many local minima but only one global minimum.

Mathematical formula

f(X) = -a * exp(-b * sqrt(sum(x_i^2) / n)) - exp(sum(cos(c * x_i)) / n) + a + e

where

  • a = 20 (default)
  • b = 0.2 (default)
  • c = 2π (default)
  • e = exp(1) ≈ 2.71828
  • n = number of dimensions

Parameters

Name Type Description Default
X array - like Input points with shape (n_samples, n_features) or (n_features,). Can be a 1D array for a single point or 2D array for multiple points. required

Returns

Name Type Description
np.ndarray np.ndarray: Function values at the input points with shape (n_samples,).

Note

  • Global minimum: f(0, 0, …, 0) = 0
  • Typical search domain: [-32.768, 32.768]^N
  • Characteristics: Non-convex, multimodal, separable

Examples

Single point evaluation at global minimum:

from spotoptim.function import ackley
import numpy as np
X = np.array([0.0, 0.0, 0.0])
ackley(X)
array([4.4408921e-16])

Multiple points evaluation:

from spotoptim.function import ackley
import numpy as np
X = np.array([[0.0, 0.0], [1.0, 1.0], [-1.0, 1.0]])
result = ackley(X)
result[0]  # Should be close to 0
result[1] > 0  # Should be positive
np.True_

References

Ackley, D. H. (1987). “A connectionist machine for genetic hillclimbing”. Kluwer Academic Publishers.