Ackley Function#

The Ackley function is an \(M\)-dimensional scalar-valued function. The function was first introduced by Ackley [Ack87] as a test function for optimization algorithms. Originally presented as a two-dimensional function, it was later generalized by Bäck and Schwefel [BS93].

import numpy as np
import matplotlib.pyplot as plt
import uqtestfuns as uqtf

The plots for one-dimensional and two-dimensional Ackley function are shown below. As can be seen, the function features many local optima with a single global optima.

../_images/ackley_3_0.png

Test function instance#

To create a default instance of the Ackley test function, type:

my_testfun = uqtf.Ackley()

Check if it has been correctly instantiated:

print(my_testfun)
Name              : Ackley
Spatial dimension : 2
Description       : Optimization test function from Ackley (1987)

By default, the spatial dimension is set to \(2\)1. To create an instance with another value of spatial dimension, pass an integer to the parameter spatial_dimension (keyword only). For example, to create an instance of 10-dimensional Ackley function, type:

my_testfun = uqtf.Ackley(spatial_dimension=10)

In the subsequent section, this 10-dimensional Ackley function will be used for illustration.

Description#

The generalized Ackley function according to [BS93] is defined as follows:

\[ \mathcal{M}(\boldsymbol{x}) = -a_1 \exp \left[ -a_2 \sqrt{\frac{1}{M} \sum_{m=1}^M x_m^2} \right] - \exp \left[ \frac{1}{M} \sum_{m=1}^M \cos (a_3 x_m) \right] + a_1 + e \]

where \(\boldsymbol{x} = \{ x_1, \ldots, x_M \}\) is the \(M\)-dimensional vector of input variables further defined below, and \(\boldsymbol{a} = \{ a_1, a_2, a_3 \}\) are parameters of the function.

Input#

Based on [Ack87], the search domain of the Ackley function is in \([-32.768, 32.768]^M\). In UQTestFuns, this search domain can be represented as probabilistic input using the uniform distribution with marginals shown in the table below.

my_testfun.prob_input

Name: Ackley1987

Spatial Dimension: 10

Description: Search domain for the Ackley function from Ackley (1987).

Marginals:

No. Name Distribution Parameters Description
1 X1 uniform [-32.768 32.768] None
2 X2 uniform [-32.768 32.768] None
3 X3 uniform [-32.768 32.768] None
4 X4 uniform [-32.768 32.768] None
5 X5 uniform [-32.768 32.768] None
6 X6 uniform [-32.768 32.768] None
7 X7 uniform [-32.768 32.768] None
8 X8 uniform [-32.768 32.768] None
9 X9 uniform [-32.768 32.768] None
10 X10 uniform [-32.768 32.768] None

Copulas: None

Parameters#

The Ackley function requires three additional parameters to complete the specification. The recommended (and the default) values are \(a_1 = 20, a_2 = 0.2, a_3 = 2 \pi\).

Reference results#

This section provides several reference results related to the test function.

Sample histogram#

Shown below is the histogram of the output based on \(100'000\) random points:

np.random.seed(42)
xx_test = my_testfun.prob_input.get_sample(100000)
yy_test = my_testfun(xx_test)

plt.hist(yy_test, bins="auto", color="#8da0cb");
plt.grid();
plt.ylabel("Counts [-]");
plt.xlabel("$\mathcal{M}(\mathbf{X})$");
plt.gcf().set_dpi(150);
../_images/ackley_13_0.png

Optimum values#

The global optimum value of the Ackley function is \(\mathcal{M}(\boldsymbol{x}^*) = 0\) at \(x_m^* = 0,\, m = 1, \ldots, M\).

References#

Ack87(1,2)

David H. Ackley. A connectionist machine for genetic hillclimbing. The Springer International Series in Engineering and Computer Science (SECS, volume 28). Springer US, Boston, MA., 1987. doi:10.1007/978-1-4613-1997-9.

BS93(1,2)

Thomas Bäck and Hans-Paul Schwefel. An overview of evolutionary algorithms for parameter optimization. Evolutionary Computation, 1(1):1–23, 1993. doi:10.1162/evco.1993.1.1.1.


1

This default dimension applies to all variable dimension test functions. It will be used if the spatial_dimension argument is not given.