Benchmarking Functions for BBO

In this open-source Python module, we have provided a set of benchmarking/test functions which have been commonly used in the black-box optimization / zeroth-order optimization / gradient-free optimization / derivative-free optimization / global optimization / direct search / randomized optimization / meta-heuristics / evolutionary algorithms / swarm intelligence community.

Note

In the coming days, we are planning to add some challenging BBO models from various real-world applications. Since this is a long-term development project, welcome anyone to make any open-source contributions to it.

For a set of 23 benchmarking/test functions, their base forms, shifted/transformed forms, rotated forms, and rotated-shifted forms have been coded and well-tested. Typically, their rotated-shifted forms should be employed in Comparison Experiments for BBO, in order to avoid possible biases towards certain search points (e.g., the origin) or separability.

Checking of Coding Correctness

For all testing code of benchmarking functions, please refer to the following openly accessible links for details (In fact, we have spent much time in checking of Python coding correctness):

Base Functions

Here we introduce the base form of some benchmarking functions common in the BBO literature, as presented below:

_images/sphere.png _images/surface_sphere.png

Reference (In Part):

  • Loshchilov, I., Glasmachers, T. and Beyer, H.G., 2018. Large scale black-box optimization by limited-memory matrix adaptation. IEEE Transactions on Evolutionary Computation, 23(2), pp.353-358.

  • Beyer, H.G. and Sendhoff, B., 2017. Simplify your covariance matrix adaptation evolution strategy. IEEE Transactions on Evolutionary Computation, 21(5), pp.746-759.

  • Jastrebski, G.A. and Arnold, D.V., 2006, July. Improving evolution strategies through active covariance matrix adaptation. In IEEE International Conference on Evolutionary Computation (pp. 2814-2821). IEEE.

  • Zhou, Q. and Li, Y., 2003. Directed variation in evolution strategies. IEEE Transactions on Evolutionary Computation, 7(4), pp.356-366.

pypop7.benchmarks.base_functions.cigar(x)[source]

Cigar test function.

Note

Its dimensionality should > 1.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/cigar.png _images/surface_cigar.png
  • Generation script of its 3D surface: https://github.com/Evolutionary-Intelligence/pypop/blob/main/tutorials/plotting/surface/plot_surface_for_cigar.py

  • Loshchilov, I., Glasmachers, T. and Beyer, H.G., 2018. Large scale black-box optimization by limited-memory matrix adaptation. IEEE Transactions on Evolutionary Computation, 23(2), pp.353-358.

  • Beyer, H.G. and Sendhoff, B., 2017. Simplify your covariance matrix adaptation evolution strategy. IEEE Transactions on Evolutionary Computation, 21(5), pp.746-759.

  • Jastrebski, G.A. and Arnold, D.V., 2006, July. Improving evolution strategies through active covariance matrix adaptation. In IEEE International Conference on Evolutionary Computation (pp. 2814-2821). IEEE.

pypop7.benchmarks.base_functions.discus(x)[source]

Discus (also called Tablet) test function.

Note

Its dimensionality should > 1.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/discus.png _images/surface_discus.png
  • Loshchilov, I., Glasmachers, T. and Beyer, H.G., 2018. Large scale black-box optimization by limited-memory matrix adaptation. IEEE Transactions on Evolutionary Computation, 23(2), pp.353-358.

  • Beyer, H.G. and Sendhoff, B., 2017. Simplify your covariance matrix adaptation evolution strategy. IEEE Transactions on Evolutionary Computation, 21(5), pp.746-759.

  • Jastrebski, G.A. and Arnold, D.V., 2006, July. Improving evolution strategies through active covariance matrix adaptation. In IEEE International Conference on Evolutionary Computation (pp. 2814-2821). IEEE.

pypop7.benchmarks.base_functions.cigar_discus(x)[source]

Cigar-Discus test function.

Note

Its dimensionality should > 1.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/cigar_discus.png _images/surface_cigar_discus.png
  • Jastrebski, G.A. and Arnold, D.V., 2006, July. Improving evolution strategies through active covariance matrix adaptation. In IEEE International Conference on Evolutionary Computation (pp. 2814-2821). IEEE.

pypop7.benchmarks.base_functions.ellipsoid(x)[source]

Ellipsoid test function.

Note

Its dimensionality should > 1.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/ellipsoid.png _images/surface_ellipsoid.png
  • Loshchilov, I., Glasmachers, T. and Beyer, H.G., 2018. Large scale black-box optimization by limited-memory matrix adaptation. IEEE Transactions on Evolutionary Computation, 23(2), pp.353-358.

  • Beyer, H.G. and Sendhoff, B., 2017. Simplify your covariance matrix adaptation evolution strategy. IEEE Transactions on Evolutionary Computation, 21(5), pp.746-759.

  • Jastrebski, G.A. and Arnold, D.V., 2006, July. Improving evolution strategies through active covariance matrix adaptation. In IEEE International Conference on Evolutionary Computation (pp. 2814-2821). IEEE.

pypop7.benchmarks.base_functions.different_powers(x)[source]

Different-Powers test function.

Note

Its dimensionality should > 1.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/different_powers.png _images/surface_different_powers.png
  • Loshchilov, I., Glasmachers, T. and Beyer, H.G., 2018. Large scale black-box optimization by limited-memory matrix adaptation. IEEE Transactions on Evolutionary Computation, 23(2), pp.353-358.

  • Beyer, H.G. and Sendhoff, B., 2017. Simplify your covariance matrix adaptation evolution strategy. IEEE Transactions on Evolutionary Computation, 21(5), pp.746-759.

  • Jastrebski, G.A. and Arnold, D.V., 2006, July. Improving evolution strategies through active covariance matrix adaptation. In IEEE International Conference on Evolutionary Computation (pp. 2814-2821). IEEE.

pypop7.benchmarks.base_functions.schwefel221(x)[source]

Schwefel221 test function.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/schwefel221.png _images/surface_schwefel221.png
pypop7.benchmarks.base_functions.step(x)[source]

Step test function.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/step.png _images/surface_step.png
pypop7.benchmarks.base_functions.schwefel222(x)[source]

Schwefel222 test function.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/schwefel222.png _images/surface_schwefel222.png
pypop7.benchmarks.base_functions.rosenbrock(x)[source]

Rosenbrock test function.

Note

Its dimensionality should > 1.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/b_rosenbrock.png _images/surface_rosenbrock.png
  • Loshchilov, I., Glasmachers, T. and Beyer, H.G., 2018. Large scale black-box optimization by limited-memory matrix adaptation. IEEE Transactions on Evolutionary Computation, 23(2), pp.353-358.

  • Beyer, H.G. and Sendhoff, B., 2017. Simplify your covariance matrix adaptation evolution strategy. IEEE Transactions on Evolutionary Computation, 21(5), pp.746-759.

  • Jastrebski, G.A. and Arnold, D.V., 2006, July. Improving evolution strategies through active covariance matrix adaptation. In IEEE International Conference on Evolutionary Computation (pp. 2814-2821). IEEE.

pypop7.benchmarks.base_functions.schwefel12(x)[source]

Schwefel12 test function.

Note

Its dimensionality should > 1.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/schwefel12.png _images/surface_schwefel12.png
pypop7.benchmarks.base_functions.exponential(x)[source]

Exponential test function.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/exponential.png _images/surface_exponential.png
pypop7.benchmarks.base_functions.griewank(x)[source]

Griewank test function.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/griewank.png _images/surface_griewank.png _images/bohachevsky_2.png images/surface_bohachevsky_2.png _images/bohachevsky.png _images/surface_bohachevsky.png
pypop7.benchmarks.base_functions.ackley(x)[source]

Ackley test function.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/ackley.png _images/surface_ackley.png
  • Bungert, L., Roith, T. and Wacker, P., 2024. Polarized consensus-based dynamics for optimization and sampling. Mathematical Programming, pp.1-31.

  • Carrillo, J.A., Choi, Y.P., Totzeck, C. and Tse, O., 2018. An analytical framework for consensus-based global optimization method. Mathematical Models and Methods in Applied Sciences, 28(06), pp.1037-1066.

pypop7.benchmarks.base_functions.rastrigin(x)[source]

Rastrigin test function.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/rastrigin.png _images/surface_rastrigin.png
  • Bungert, L., Roith, T. and Wacker, P., 2024. Polarized consensus-based dynamics for optimization and sampling. Mathematical Programming, pp.1-31.

pypop7.benchmarks.base_functions.scaled_rastrigin(x)[source]

Scaled-Rastrigin test function.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/scaled_rastrigin.png _images/surface_scaled_rastrigin.png
pypop7.benchmarks.base_functions.skew_rastrigin(x)[source]

Skew-Rastrigin test function.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/skew_rastrigin.png _images/surface_skew_rastrigin.png
pypop7.benchmarks.base_functions.levy_montalvo(x)[source]

Levy-Montalvo test function.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/levy_montalvo.png _images/surface_levy_montalvo.png
pypop7.benchmarks.base_functions.michalewicz(x)[source]

Michalewicz test function.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/michalewicz.png _images/surface_michalewicz.png
pypop7.benchmarks.base_functions.salomon(x)[source]

Salomon test function.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/salomon.png _images/surface_salomon.png
pypop7.benchmarks.base_functions.shubert(x)[source]

Shubert test function.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/shubert.png _images/surface_shubert.png
pypop7.benchmarks.base_functions.schaffer(x)[source]

Schaffer test function.

Parameters:

x (ndarray) – An input vector.

Returns:

y – A scalar fitness.

Return type:

float

_images/schaffer.png _images/surface_schaffer.png

Shifted/Transformed Forms

In the following, we will introduce shifted/transformed forms of the above base functions, as presented below:

pypop7.benchmarks.shifted_functions.generate_shift_vector(func, ndim, low, high, seed=None)[source]
Generate a random shift vector of dimension ndim, sampled uniformly

between low (inclusive) and high (exclusive).

Note

The generated shift vector will be automatically stored in the txt form for further use.

Parameters:
  • func (str or func) – function name.

  • ndim (int) – number of dimensions of the shift vector.

  • low (float or array_like) – lower boundary of the shift vector.

  • high (float or array_like) – upper boundary of the shift vector.

  • seed (int) – a scalar seed for random number generator (RNG).

Returns:

shift_vector – a shift vector of size ndim sampled uniformly in [low, high).

Return type:

ndarray (of dtype np.float64)

pypop7.benchmarks.shifted_functions.load_shift_vector(func, x, shift_vector=None)[source]

Load the shift vector which needs to be generated in advance.

Note

When None, the shift vector should have been generated and stored in the txt form in advance via generate_shift_vector().

Parameters:
  • func (func) – function name.

  • x (array_like) – a decision vector (aka an input vector).

  • shift_vector (array_like) – a shift vector with the same size as x.

Returns:

shift_vector – a shift vector with the same size as x.

Return type:

ndarray (of dtype np.float64)

pypop7.benchmarks.shifted_functions.sphere(x, shift_vector=None)[source]

Sphere test function.

Parameters:
  • x (ndarray) – an input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – a scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.cigar(x, shift_vector=None)[source]

Cigar test function.

Parameters:
  • x (ndarray) – an input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – a scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.discus(x, shift_vector=None)[source]

Discus (aka Tablet) test function.

Parameters:
  • x (ndarray) – an input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – a scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.cigar_discus(x, shift_vector=None)[source]

Cigar-Discus test function.

Parameters:
  • x (ndarray) – an input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – a scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.ellipsoid(x, shift_vector=None)[source]

Ellipsoid test function.

Parameters:
  • x (ndarray) – an input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – a scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.different_powers(x, shift_vector=None)[source]

Different-Powers test function.

Parameters:
  • x (ndarray) – an input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – a scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.schwefel221(x, shift_vector=None)[source]

Schwefel221 test function.

Note

It’s LaTeX formulation is $$. If its parameter shift_vector is None, please use function generate_shift_vector() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.step(x, shift_vector=None)[source]

Step test function.

Note

It’s LaTeX formulation is $$. If its parameter shift_vector is None, please use function generate_shift_vector() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.schwefel222(x, shift_vector=None)[source]

Schwefel222 test function.

Note

It’s LaTeX formulation is $$. If its parameter shift_vector is None, please use function generate_shift_vector() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.rosenbrock(x, shift_vector=None)[source]

Rosenbrock test function.

Note

It’s LaTeX formulation is $$. If its parameter shift_vector is None, please use function generate_shift_vector() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.schwefel12(x, shift_vector=None)[source]

Schwefel12 test function.

Note

It’s LaTeX formulation is $$. If its parameter shift_vector is None, please use function generate_shift_vector() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.exponential(x, shift_vector=None)[source]

Exponential test function.

Note

It’s LaTeX formulation is $$. If its parameter shift_vector is None, please use function generate_shift_vector() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.griewank(x, shift_vector=None)[source]

Griewank test function.

Note

It’s LaTeX formulation is $$. If its parameter shift_vector is None, please use function generate_shift_vector() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.bohachevsky(x, shift_vector=None)[source]

Bohachevsky test function.

Note

It’s LaTeX formulation is $$. If its parameter shift_vector is None, please use function generate_shift_vector() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.ackley(x, shift_vector=None)[source]

Ackley test function.

Note

It’s LaTeX formulation is $$. If its parameter shift_vector is None, please use function generate_shift_vector() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.rastrigin(x, shift_vector=None)[source]

Rastrigin test function.

Note

It’s LaTeX formulation is $$. If its parameter shift_vector is None, please use function generate_shift_vector() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.scaled_rastrigin(x, shift_vector=None)[source]

Scaled-Rastrigin test function.

Note

It’s LaTeX formulation is $$. If its parameter shift_vector is None, please use function generate_shift_vector() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.skew_rastrigin(x, shift_vector=None)[source]

Skew-Rastrigin test function.

Note

It’s LaTeX formulation is $$. If its parameter shift_vector is None, please use function generate_shift_vector() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.levy_montalvo(x, shift_vector=None)[source]

Levy-Montalvo test function.

Note

It’s LaTeX formulation is $$. If its parameter shift_vector is None, please use function generate_shift_vector() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.michalewicz(x, shift_vector=None)[source]

Michalewicz test function.

Note

It’s LaTeX formulation is $$. If its parameter shift_vector is None, please use function generate_shift_vector() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.salomon(x, shift_vector=None)[source]

Salomon test function.

Note

It’s LaTeX formulation is $$. If its parameter shift_vector is None, please use function generate_shift_vector() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.shubert(x, shift_vector=None)[source]

Shubert test function.

Note

It’s LaTeX formulation is $$. If its parameter shift_vector is None, please use function generate_shift_vector() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.shifted_functions.schaffer(x, shift_vector=None)[source]

Schaffert test function.

Note

It’s LaTeX formulation is $$. If its parameter shift_vector is None, please use function generate_shift_vector() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (ndarray) – a vector with the same size as x.

Returns:

y – scalar fitness.

Return type:

float

Rotated Forms

In the following, we will introduce rotated forms of the above base functions, as presented below:

pypop7.benchmarks.rotated_functions.generate_rotation_matrix(func, ndim, seed)[source]

Generate a random rotation matrix of dimension [ndim * ndim], sampled normally.

Note

The generated rotation matrix will be automatically stored in txt form for further use.

Parameters:
  • func (str or func) – function name.

  • ndim (int) – number of dimensions of the rotation matrix.

  • seed (int) – scalar seed for random number generator (RNG).

Returns:

rotation_matrix – rotation matrix of size [ndim * ndim].

Return type:

ndarray

pypop7.benchmarks.rotated_functions.load_rotation_matrix(func, x, rotation_matrix=None)[source]

Load the rotation matrix which needs to be generated in advance.

Note

When None, the rotation matrix should have been generated and stored in txt form in advance.

Parameters:
  • func (str or func) – function name.

  • x (array_like) – decision vector.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

rotation_matrix – rotation matrix of size [len(x) * len(x)].

Return type:

ndarray

pypop7.benchmarks.rotated_functions.sphere(x, rotation_matrix=None)[source]

Sphere test function.

Note

It’s LaTeX formulation is $sum_{i=1}^{n}x_i^2$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.cigar(x, rotation_matrix=None)[source]

Cigar test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.discus(x, rotation_matrix=None)[source]

Discus/Tablet test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.cigar_discus(x, rotation_matrix=None)[source]

Cigar-Discus test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.ellipsoid(x, rotation_matrix=None)[source]

Ellipsoid test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.different_powers(x, rotation_matrix=None)[source]

Different-Powers test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.schwefel221(x, rotation_matrix=None)[source]

Schwefel221 test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.step(x, rotation_matrix=None)[source]

Step test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.schwefel222(x, rotation_matrix=None)[source]

Schwefel222 test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.rosenbrock(x, rotation_matrix=None)[source]

Rosenbrock test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.schwefel12(x, rotation_matrix=None)[source]

Schwefel12 test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.exponential(x, rotation_matrix=None)[source]

Exponential test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.griewank(x, rotation_matrix=None)[source]

Griewank test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.bohachevsky(x, rotation_matrix=None)[source]

Bohachevsky test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.ackley(x, rotation_matrix=None)[source]

Ackley test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.rastrigin(x, rotation_matrix=None)[source]

Rastrigin test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.scaled_rastrigin(x, rotation_matrix=None)[source]

Scaled-Rastrigin test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.levy_montalvo(x, rotation_matrix=None)[source]

Levy-Montalvo test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.michalewicz(x, rotation_matrix=None)[source]

Michalewicz test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.salomon(x, rotation_matrix=None)[source]

Salomon test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.shubert(x, rotation_matrix=None)[source]

Shubert test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.rotated_functions.schaffer(x, rotation_matrix=None)[source]

Schaffer test function.

Note

It’s LaTeX formulation is $$. If its parameter rotation_matrix is None, please use function generate_rotation_matrix() to generate it (stored in txt form) in advance.

Parameters:
  • x (ndarray) – input vector.

  • rotation_matrix (ndarray) – a matrix with the same size as x in each dimension.

Returns:

y – scalar fitness.

Return type:

float

Rotated-Shifted Forms

In the following, we will introduce rotated-shifted forms of the above base functions, as presented below:

pypop7.benchmarks.continuous_functions.load_shift_and_rotation(func, x, shift_vector=None, rotation_matrix=None)[source]

Load both the shift vector and rotation matrix which need to be generated in advance.

Note

When None, the shift vector should have been generated and stored in txt form in advance. When None, the rotation matrix should have been generated and stored in txt form in advance.

Parameters:
  • func (str or func) – function name.

  • x (array_like) – decision vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

  • shift_vector (ndarray (of dtype np.float64)) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

pypop7.benchmarks.continuous_functions.sphere(x, shift_vector=None, rotation_matrix=None)[source]

Sphere test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.cigar(x, shift_vector=None, rotation_matrix=None)[source]

Cigar test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.discus(x, shift_vector=None, rotation_matrix=None)[source]

Discus test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.cigar_discus(x, shift_vector=None, rotation_matrix=None)[source]

Cigar-Discus test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.ellipsoid(x, shift_vector=None, rotation_matrix=None)[source]

Ellipsoid test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.different_powers(x, shift_vector=None, rotation_matrix=None)[source]

Different-Power test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.schwefel221(x, shift_vector=None, rotation_matrix=None)[source]

Schwefel221 test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.step(x, shift_vector=None, rotation_matrix=None)[source]

Step test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.schwefel222(x, shift_vector=None, rotation_matrix=None)[source]

Schwefel222 test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.rosenbrock(x, shift_vector=None, rotation_matrix=None)[source]

Rosenbrock test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.schwefel12(x, shift_vector=None, rotation_matrix=None)[source]

Schwefel12 test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.exponential(x, shift_vector=None, rotation_matrix=None)[source]

Exponential test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.griewank(x, shift_vector=None, rotation_matrix=None)[source]

Griewank test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.bohachevsky(x, shift_vector=None, rotation_matrix=None)[source]

Bohachevsky test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.ackley(x, shift_vector=None, rotation_matrix=None)[source]

Ackley test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.rastrigin(x, shift_vector=None, rotation_matrix=None)[source]

Rastrigin test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.scaled_rastrigin(x, shift_vector=None, rotation_matrix=None)[source]

Scaled-Rastrigin test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.skew_rastrigin(x, shift_vector=None, rotation_matrix=None)[source]

Skew-Rastrigin test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.levy_montalvo(x, shift_vector=None, rotation_matrix=None)[source]

Levy-Montalvo test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.michalewicz(x, shift_vector=None, rotation_matrix=None)[source]

Michalewicz test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.salomon(x, shift_vector=None, rotation_matrix=None)[source]

Salomon test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.shubert(x, shift_vector=None, rotation_matrix=None)[source]

Shubert test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

pypop7.benchmarks.continuous_functions.schaffer(x, shift_vector=None, rotation_matrix=None)[source]

Schaffer test function.

Parameters:
  • x (ndarray) – input vector.

  • shift_vector (array_like) – shift vector with the same size as x.

  • rotation_matrix (ndarray) – rotation matrix of size [len(x) * len(x)].

Returns:

y – scalar fitness.

Return type:

float

Benchmarking for Large-Scale BBO (LBO)

Here we have provided two different benchmarking cases (local vs global search) for large-scale black-box optimization (LBO):

Black-Box Classification from Data Science

Here we have provided a family of test functions from black-box classification of data science:

Benchmarking on Photonics Models from NeverGrad

Please refer to NeverGrad for an introduction to the photonics model.

Benchmarking of Controllers on Gymnasium

Please refer to Gymnasium for an introduction (from Farama Foundation).

Lennard-Jones Cluster Optimization from PyGMO

Please refer to pagmo2 for an introduction (from European Space Agency) to this 444-d Lennard-Jones cluster optimization problem from PyGMO.

Test Classes and Data

In the following, we will provide a set of test classes and test data for benchmarking functions. Since these classes and data are used only for the testing purpose, end-users can skip this section safely.

class pypop7.benchmarks.cases.Cases(is_shifted=False, is_rotated=False)[source]

Test the correctness of benchmarking functions via sampling (test cases).

check_origin(func, n_samples=7)[source]

Check the origin point of which the function value is zero via random sampling (test cases).

Parameters:
  • func – benchmarking function, func.

  • n_samples – number of samples, int.

Returns:

True if all function values computed on test cases are zeros, otherwise False; bool.

compare(func, ndim, y_true, shift_vector=None, rotation_matrix=None, atol=0.001)[source]

Compare true function values with these returned by the used benchmark function.

Parameters:
  • func – benchmarking function, func.

  • ndim – number of dimensions (only ranged in [1, 7]), int.

  • y_truendarray, where each element is the true function value of the corresponding test case.

  • shift_vector – shift vector, ndarray.

  • rotation_matrix – rotation matrix, ndarray.

  • atol – absolute tolerance parameter, float.

Returns:

True if all function values computed on test cases match y_true; otherwise, False.

make_test_cases(ndim=None)[source]

Make multiple test cases for a specific dimension (only ranged in [1, 7]).

Note

The number of test cases may be different on different dimensions.

Parameters:

ndim – number of dimensions (only ranged in [1, 7]), int.

Returns:

ndarray of dtype np.float64, where each row is a test case.

pypop7.benchmarks.cases.get_y_sphere(ndim)[source]

Get test data for Sphere test function.

pypop7.benchmarks.cases.get_y_cigar(ndim)[source]

Get test data for Cigar test function.

pypop7.benchmarks.cases.get_y_discus(ndim)[source]

Get test data for Discus test function.

pypop7.benchmarks.cases.get_y_cigar_discus(ndim)[source]

Get test data for Cigar-Discus test function.

pypop7.benchmarks.cases.get_y_ellipsoid(ndim)[source]

Get test data for Ellipsoid test function.

pypop7.benchmarks.cases.get_y_different_powers(ndim)[source]

Get test data for Different-Powers test function.

pypop7.benchmarks.cases.get_y_schwefel221(ndim)[source]

Get test data for Schwefel221 test function.

pypop7.benchmarks.cases.get_y_step(ndim)[source]

Get test data for Step test function.

pypop7.benchmarks.cases.get_y_schwefel222(ndim)[source]

Get test data for Schwefel222 test function.

pypop7.benchmarks.cases.get_y_rosenbrock(ndim)[source]

Get test data for Rosenbrock test function.

pypop7.benchmarks.cases.get_y_schwefel12(ndim)[source]

Get test data for Schwefel12 test function.

pypop7.benchmarks.cases.get_y_exponential()[source]

Get test data for Exponential test function.

pypop7.benchmarks.cases.get_y_griewank(ndim)[source]

Get test data for Griewank test function.

pypop7.benchmarks.cases.get_y_bohachevsky(ndim)[source]

Get test data for Bohachevsky test function.

pypop7.benchmarks.cases.get_y_ackley(ndim)[source]

Get test data for Ackley test function.

pypop7.benchmarks.cases.get_y_rastrigin(ndim)[source]

Get test data for Rastrigin test function.

pypop7.benchmarks.cases.get_y_scaled_rastrigin(ndim)[source]

Get test data for Scaled-Rastrigin test function.

pypop7.benchmarks.cases.get_y_skew_rastrigin(ndim)[source]

Get test data for Skew-Rastrigin test function.

pypop7.benchmarks.cases.get_y_levy_montalvo()[source]

Get test data for LevyMontalvo test function.

pypop7.benchmarks.cases.get_y_michalewicz()[source]

Get test data for Michalewicz test function.

pypop7.benchmarks.cases.get_y_salomon()[source]

Get test data for Salomon test function.

pypop7.benchmarks.cases.get_y_shubert()[source]

Get test data for Schaffer test function.

pypop7.benchmarks.cases.get_y_schaffer(ndim)[source]

Get test data for Schaffer test function.

https://visitor-badge.laobi.icu/badge?page_id=Evolutionary-Intelligence.pypop