Mathematical Definition

In the above equation, the values $a$, $b$ and $c$ are constants and are usually chosen as $a=20$, $b=0.2$ and $c=2\pi$.

Plots

Ackley Function

Ackley Function

The contour of the function is as presented below:

Ackley Function

Description and Features

  • The function is continuous.
  • The function is not convex.
  • The function is defined on n-dimensional space.
  • The function is multimodal.

Input Domain

The function can be defined on any input domain but it is usually evaluated on $x_i \in [-32, 32]$ for all $i = 1,…,n$.

Global Minima

The function has one global minimum at: $f(\textbf{x}^{\ast})=0$ at $\textbf{x}^{\ast} = (0, …, 0)$.

Implementation

An implementation of the Ackley Function with MATLAB is provided below.

% Computes the value of Ackley benchmark function.
% SCORES = ACKLEYFCN(X) computes the value of the Ackey function at point
% X. ACKLEYFCN accepts a matrix of size M-by-N and returns a vetor SCORES
% of size M-by-1 in which each row contains the function value for each row
% of X.
% For more information please visit: 
% https://en.wikipedia.org/wiki/Test_functions_for_optimization
% 
% Author: Mazhar Ansari Ardeh
% Please forward any comments or bug reports to mazhar.ansari.ardeh at
% Google's e-mail service or feel free to kindly modify the repository.
function scores = ackleyfcn(x)
    n = size(x, 2);
    ninverse = 1 / n;
    sum1 = sum(x .^ 2, 2);
    sum2 = sum(cos(2 * pi * x), 2);
    
    scores = 20 + exp(1) - (20 * exp(-0.2 * sqrt( ninverse * sum1))) - exp( ninverse * sum2);
end

The function can be represented in Latex as follows:

f(\textbf{x}) = f(x_1, ..., x_n)= -a.exp(-b\sqrt{\frac{1}{n}\sum_{i=1}^{n}x_i^2})-exp(\frac{1}{n}\sum_{i=1}^{n}cos(cx_i))+ a + exp(1)

See also:

References: