Ackley Function
Mathematical Definition
\[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)\]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
The contour of the function is as presented below:
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
Python
For Python, the function is implemented in the benchmarkfcns package and can be installed from command line with pip install benchmarkfcns
.
from benchmarkfcns import ackley
print(ackley([[0, 0, 0],
[1, 1, 1]]))
MATLAB
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.
%
% 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)
Acknowledgement
The author would like to thank Prof. Ivo Welch for kindly contributing to the correctness of this document by pointing out some inconsistencies in the text.
See also:
References:
- http://www.sfu.ca/~ssurjano/ackley.html
- https://en.wikipedia.org/wiki/Test_functions_for_optimization
- http://www.cs.unm.edu/~neal.holts/dga/benchmarkFunction/ackley.html, This resource
contains an extensive collection of references for this function. The page also contains an implementation of the function in
Python
.