Test function module#
References
S Surjanovic and D Bingham, “Virtual Library of Simulation Experiments: Test Functions and Datasets,” sfu.ca. [Online]. Available: https://www.sfu.ca/~ssurjano/optimization.html. [Accessed March 11, 2023].
Parent class#
Ackley function#
- class nubo.test_functions.ackley.Ackley(dims: int, noise_std: float | None = 0.0, minimise: bool | None = True)[source]#
Bases:
TestFunction
\(d\)-dimensional Ackley function.
The Ackley function has many local minima and one global minimum \(f(\boldsymbol x^*) = 0\) at \(\boldsymbol x^* = (0, ..., 0)\). It is usually evaluated on the hypercube \(\boldsymbol x \in [-32.768, 32.768]^d\).
\[f(\boldsymbol x) = -a \exp \left(-b \sqrt{\frac{1}{d} \sum^d_{i=1} x^2_i}\right) - \exp \left( \frac{1}{d} \sum^d_{i=1} \cos(c x_i)\right) + a + \exp(1),\]where \(a = 20\), \(b = 0.2\), and \(c = 2\pi\).
- Attributes:
- dims
int
Number of input dimensions.
- noise_std
float
Standard deviation of Gaussian noise.
- minimise
bool
Minimisation problem if true, maximisation problem if false.
- bounds
torch.Tensor
(size 2 x dims) Bounds of input space.
- optimum
dict
Contains inputs and output of global maximum.
- a
float
Function parameter.
- b
float
Function parameter.
- c
float
Function parameter.
- dims
Methods
eval
(x)Compute output of Ackley function for some test points x.
Dixon-Price function#
- class nubo.test_functions.dixonprice.DixonPrice(dims: int, noise_std: float | None = 0.0, minimise: bool | None = True)[source]#
Bases:
TestFunction
\(d\)-dimensional Dixon-Price function.
The Dixon-Price function is valley-shaped and has one global minimum \(f(\boldsymbol x^*) = 0\) at \(x^*_i = 2^{-\frac{2^i-2}{2^i}}\), for all \(i = 1, ..., d\). It is usually evaluated on the hypercube \(\boldsymbol x \in [-10, 10]^d\).
\[f(\boldsymbol x) = (x_1 - 1)^2 + \sum_{i=2}^d i (2x_i^2 - x_{i-1})^2.\]- Attributes:
- dims
int
Number of input dimensions.
- noise_std
float
Standard deviation of Gaussian noise.
- minimise
bool
Minimisation problem if true, maximisation problem if false.
- bounds
torch.Tensor
(size 2 x dims) Bounds of input space.
- optimum
dict
Contains inputs and output of global maximum.
- dims
Methods
eval
(x)Compute output of Dixon-Price function for some test points x.
Griewank function#
- class nubo.test_functions.griewank.Griewank(dims: int, noise_std: float | None = 0.0, minimise: bool | None = True)[source]#
Bases:
TestFunction
\(d\)-dimensional Griewank function.
The Griewank function has many local minima and one global minimum \(f(\boldsymbol x^*) = 0\) at \(\boldsymbol x^* = (0, ..., 0)\). It is usually evaluated on the hypercube \(\boldsymbol x \in [-600, 600]^d\).
\[f(\boldsymbol x) = \sum_{i=1}^d \frac{x_i^2}{4000} - \prod_{i=1}^d \cos \left( \frac{x_i}{\sqrt{i}} \right) + 1.\]- Attributes:
- dims
int
Number of input dimensions.
- noise_std
float
Standard deviation of Gaussian noise.
- minimise
bool
Minimisation problem if true, maximisation problem if false.
- bounds
torch.Tensor
(size 2 x dims) Bounds of input space.
- optimum
dict
Contains inputs and output of global maximum.
- dims
Methods
eval
(x)Compute output of Griewank function for some test points x.
Hartmann function#
- class nubo.test_functions.hartmann.Hartmann3D(noise_std: float | None = 0.0, minimise: bool | None = True)[source]#
Bases:
TestFunction
3-dimensional Hartmann function.
The 3-dimensional Hartmann function has four local minima and one global minimum \(f(\boldsymbol x^*) = -3.86278\) at \(\boldsymbol x^* = (0.114614, 0.555649, 0.852547)\). It is usually evaluated on the hypercube \(\boldsymbol x \in (0, 1)^3\).
\[f(\boldsymbol x) = - \sum_{i=1}^4 \alpha_i \exp \left( - \sum_{j=1}^3 A_{ij} (x_j - P_{ij})^2 \right),\]where
\[\alpha = (1.0, 1.2, 3.0, 3.2)^T,\]\[\begin{split}\boldsymbol A = \begin{pmatrix} 3.0 & 10.0 & 30.0 \\ 0.1 & 10.0 & 35.0 \\ 3.0 & 10.0 & 30.0 \\ 0.1 & 10.0 & 35.0 \end{pmatrix},\end{split}\]\[\begin{split}\text{and } \boldsymbol P = 10^{-4} \begin{pmatrix} 3689 & 1170 & 2673 \\ 4699 & 4387 & 7470 \\ 1091 & 8732 & 5547 \\ 381 & 5743 & 8828 \end{pmatrix}.\end{split}\]- Attributes:
- dims
int
Number of input dimensions.
- noise_std
float
Standard deviation of Gaussian noise.
- minimise
bool
Minimisation problem if true, maximisation problem if false.
- bounds
torch.Tensor
(size 2 x dims) Bounds of input space.
- optimum
dict
Contains inputs and output of global maximum.
- a
torch.Tensor
(size 4 x 1) Function parameters.
- A
torch.Tensor
(size 4 x 3) Function parameters.
- P
torch.Tensor
(size 4 x 3) Function parameters.
- dims
Methods
eval
(x)Compute output of Hartmann function for some test points x.
- class nubo.test_functions.hartmann.Hartmann6D(noise_std: float | None = 0.0, minimise: bool | None = True)[source]#
Bases:
TestFunction
6-dimensional Hartmann function.
The 6-dimensional Hartmann function has six local minima and one global minimum \(f(\boldsymbol x^*) = -3.32237\) at \(\boldsymbol x^* = (0.20169, 0.150011, 0.476874, 0.275332, 0.311652, 0.6573)\). It is usually evaluated on the hypercube \(\boldsymbol x \in (0, 1)^6\).
\[f(\boldsymbol x) = - \sum_{i=1}^4 \alpha_i \exp \left( - \sum_{j=1}^6 A_{ij} (x_j - P_{ij})^2 \right),\]where
\[\alpha = (1.0, 1.2, 3.0, 3.2)^T,\]\[\begin{split}\boldsymbol A = \begin{pmatrix} 10.00 & 3.00 & 17.00 & 3.50 & 1.70 & 8.00 \\ 0.05 & 10.00 & 17.00 & 0.10 & 8.00 & 14.00 \\ 3.00 & 3.50 & 1.70 & 10.00 & 17.00 & 8.00 \\ 17.00 & 8.00 & 0.05 & 10.00 & 0.10 & 14.00 \end{pmatrix},\end{split}\]\[\begin{split}\text{and } \boldsymbol P = 10^{-4} \begin{pmatrix} 1312 & 1696 & 5569 & 124 & 8283 & 5886 \\ 2329 & 4135 & 8307 & 3736 & 1004 & 9991 \\ 2348 & 1451 & 3522 & 2883 & 3047 & 6650 \\ 4047 & 8828 & 8732 & 5743 & 1091 & 381 \end{pmatrix}.\end{split}\]- Attributes:
- dims
int
Number of input dimensions.
- noise_std
float
Standard deviation of Gaussian noise.
- minimise
bool
Minimisation problem if true, maximisation problem if false.
- bounds
torch.Tensor
(size 2 x dims) Bounds of input space.
- optimum
dict
Contains inputs and output of global maximum.
- a
torch.Tensor
(size 4 x 1) Function parameters.
- A
torch.Tensor
(size 4 x 6) Function parameters.
- P
torch.Tensor
(size 4 x 6) Function parameters.
- dims
Methods
eval
(x)Compute output of Hartmann function for some test points x.
Levy function#
- class nubo.test_functions.levy.Levy(dims: int, noise_std: float | None = 0.0, minimise: bool | None = True)[source]#
Bases:
TestFunction
\(d\)-dimensional Levy function.
The Levy function has many local minima and one global minimum \(f(\boldsymbol x^*) = 0\) at \(\boldsymbol x^* = (1, ..., 1)\). It is usually evaluated on the hypercube \(\boldsymbol x \in [-10, 10]^d\).
\[f(\boldsymbol x) = \sin^2 (\pi w_1) + \sum_{i=1}^{d-1} (w_i - 1)^2 [1 + 10 \sin^2 (\pi w_i + 1)] + (w_d - 1)^2 [1 + \sin^2(2\pi w_d)],\]where \(w_i = 1 + \frac{x_i - 1}{4}\), for all \(i = 1, ..., d\).
- Attributes:
- dims
int
Number of input dimensions.
- noise_std
float
Standard deviation of Gaussian noise.
- minimise
bool
Minimisation problem if true, maximisation problem if false.
- bounds
torch.Tensor
(size 2 x dims) Bounds of input space.
- optimum
dict
Contains inputs and output of global maximum.
- dims
Methods
eval
(x)Compute output of Levy function for some test points x.
Rastrigin function#
- class nubo.test_functions.rastrigin.Rastrigin(dims: int, noise_std: float | None = 0.0, minimise: bool | None = True)[source]#
Bases:
TestFunction
\(d\)-dimensional Rastrigin function.
The Rastrigin function has many local minima and one global minimum \(f(\boldsymbol x^*) = 0\) at \(\boldsymbol x^* = (0, ..., 0)\). It is usually evaluated on the hypercube \(\boldsymbol x \in [-5.12, 5.12]^d\).
\[f(\boldsymbol x) = 10d + \sum_{i-1}^d [x_i^2 - 10 \cos(2 \pi x_i)].\]- Attributes:
- dims
int
Number of input dimensions.
- noise_std
float
Standard deviation of Gaussian noise.
- minimise
bool
Minimisation problem if true, maximisation problem if false.
- bounds
torch.Tensor
(size 2 x dims) Bounds of input space.
- optimum
dict
Contains inputs and output of global maximum.
- dims
Methods
eval
(x)Compute output of Rastrigin function for some test points x.
Schwefel function#
- class nubo.test_functions.schwefel.Schwefel(dims: int, noise_std: float | None = 0.0, minimise: bool | None = True)[source]#
Bases:
TestFunction
\(d\)-dimensional Schwefel function.
The Schwefel function has many local minima and one global minimum \(f(\boldsymbol x^*) = 0\) at \(\boldsymbol x^* = (420.9687, ..., 420.9687)\). It is usually evaluated on the hypercube \(\boldsymbol x \in [-500, 500]^d\).
\[f(\boldsymbol x) = 418.9829 d - \sum_{i=1}^d x_i \sin (\sqrt{\lvert x_i \rvert}).\]- Attributes:
- dims
int
Number of input dimensions.
- noise_std
float
Standard deviation of Gaussian noise.
- minimise
bool
Minimisation problem if true, maximisation problem if false.
- bounds
torch.Tensor
(size 2 x dims) Bounds of input space.
- optimum
dict
Contains inputs and output of global maximum.
- dims
Methods
eval
(x)Compute output of Schwefel function for some test points x.
Sphere function#
- class nubo.test_functions.sphere.Sphere(dims: int, noise_std: float | None = 0.0, minimise: bool | None = True)[source]#
Bases:
TestFunction
\(d\)-dimensional Sphere function.
The Sphere function is bowl-shaped and has one global minimum \(f(\boldsymbol x^*) = 0\) at \(\boldsymbol x^* = (0, ..., 0)\). It is usually evaluated on the hypercube \(\boldsymbol x \in [-5.12, 5.12]^d\).
\[f(\boldsymbol x) = \sum_{i=1}^d x_i^2.\]- Attributes:
- dims
int
Number of input dimensions.
- noise_std
float
Standard deviation of Gaussian noise.
- minimise
bool
Minimisation problem if true, maximisation problem if false.
- bounds
torch.Tensor
(size 2 x dims) Bounds of input space.
- optimum
dict
Contains inputs and output of global maximum.
- dims
Methods
eval
(x)Compute output of Sphere function for some test points x.
Sum Squares function#
- class nubo.test_functions.sumsquares.SumSquares(dims: int, noise_std: float | None = 0.0, minimise: bool | None = True)[source]#
Bases:
TestFunction
\(d\)-dimensional Sum Squares function.
The Sum Squares function is bowl-shaped and has one global minimum \(f(\boldsymbol x^*) = 0\) at \(\boldsymbol x^* = (0, ..., 0)\). It is usually evaluated on the hypercube \(\boldsymbol x \in [-10, 10]^d\).
\[f(\boldsymbol x) = \sum_{i=1}^d i x_i^2.\]- Attributes:
- dims
int
Number of input dimensions.
- noise_std
float
Standard deviation of Gaussian noise.
- minimise
bool
Minimisation problem if true, maximisation problem if false.
- bounds
torch.Tensor
(size 2 x dims) Bounds of input space.
- optimum
dict
Contains inputs and output of global maximum.
- dims
Methods
eval
(x)Compute output of Sum-of-Squares function for some test points x.
Zakharov function#
- class nubo.test_functions.zakharov.Zakharov(dims: int, noise_std: float | None = 0.0, minimise: bool | None = True)[source]#
Bases:
TestFunction
\(d\)-dimensional Zakharov function.
The Zakharov function is plate-shaped and has one global minimum \(f(\boldsymbol x^*) = 0\) at \(\boldsymbol x^* = (0, ..., 0)\). It is usually evaluated on the hypercube \(\boldsymbol x \in [-5, 10]^d\).
\[f(\boldsymbol x) = \sum_{i=1}^d x_i^2 + \left( \sum_{i=1}^d 0.5 i x_i \right)^2 + \left( \sum_{i=1}^d 0.5 i x_i \right)^4.\]- Attributes:
- dims
int
Number of input dimensions.
- noise_std
float
Standard deviation of Gaussian noise.
- minimise
bool
Minimisation problem if true, maximisation problem if false.
- bounds
torch.Tensor
(size 2 x dims) Bounds of input space.
- optimum
dict
Contains inputs and output of global maximum.
- dims
Methods
eval
(x)Compute output of Zakharov function for some test points x.