Skip to content

Benchmarks

ypea.benchmarks has the classic test functions and the CEC 2017 and CEC 2022 suites. Every function takes one point of shape (d,) or a batch of shape (..., d), and every ready-made problem is vectorized.

Classic functions

26 functions, each with its standard bounds, optimum value and optimum location:

Function Bounds Function Bounds
sphere [-100, 100] levy [-10, 10]
ellipsoid [-100, 100] zakharov [-5, 10]
sum_squares [-10, 10] step [-100, 100]
schwefel_1_2 [-100, 100] quartic [-1.28, 1.28]
schwefel_2_21 [-100, 100] alpine1 [-10, 10]
schwefel_2_22 [-10, 10] styblinski_tang [-5, 5]
schwefel_2_26 [-500, 500] dixon_price [-10, 10]
rosenbrock [-30, 30] michalewicz [0, pi]
rastrigin [-5.12, 5.12] salomon [-100, 100]
ackley [-32.768, 32.768] weierstrass [-0.5, 0.5]
griewank [-600, 600] happy_cat [-100, 100]
bent_cigar [-100, 100] hgbat [-100, 100]
discus [-100, 100] expanded_schaffer_f6 [-100, 100]

The optimum is 0, except for Styblinski Tang (-39.166... d) and Michalewicz, computed for each dimension (-9.66015 for d = 10). quartic_noisy adds uniform noise to quartic and is not in the suite. Each docstring gives the formula and its source (Yao, Liu and Lin 1999, Jamil and Yang 2013, or the CEC reports).

Call a function directly, for example inside your own objective. Here Rastrigin gets one point in 5 dimensions and Ackley a batch of three points:

import numpy as np
import ypea

point = np.zeros(5)
batch = np.ones((3, 5))
print(ypea.benchmarks.rastrigin(point), ypea.benchmarks.ackley(batch))
0.0 [3.62538494 3.62538494 3.62538494]

Differs from Python: points are rows: a batch is n by d.

point = zeros(1, 5);
batch = ones(3, 5);  % one point per row
disp(ypea.benchmarks.rastrigin(point))
disp(ypea.benchmarks.ackley(batch))
     0

    3.6254
    3.6254
    3.6254

Or get a ready-made Problem with the bounds and the known optimum, here Rastrigin in 10 dimensions. Because the optimum is known, results also report the error, the distance of the best value from the optimum:

import ypea

problem = ypea.benchmarks.problem("rastrigin", 10)
print(problem.name, problem.optimum, problem.vars)
rastrigin_d10 0.0 [Real('x', shape=(10,))]
problem = ypea.benchmarks.problem("rastrigin", 10);
disp(problem.name)
disp(problem.optimum)
disp(problem.vars)
rastrigin_d10
     0

    {1×1 ypea.Real}
Contour plots of twelve classic functions in two dimensions
Twelve of the classic functions in two dimensions (darker is lower, with the colors scaled separately for each function). Sphere, Rosenbrock and Griewank are shown on a log scale. Rosenbrock is zoomed in on its curved valley, and some other functions on their local minima.

Shift and rotation

Many functions have their optimum at the origin, which some algorithms find too easily. shift=True moves the optimum to a random point in the central 80 percent of the bounds. rotate=True applies a random rotation around the optimum, so the variables are no longer separable. seed fixes both. The example checks that the value at the moved optimum is still 0:

import ypea

problem = ypea.benchmarks.problem("rastrigin", 10, shift=True, rotate=True, seed=3)
print(problem.name)
optimum = ypea.Solution(x=problem.info["x_opt"])  # the moved optimum
print(problem.objective(optimum))
rastrigin_d10_shifted_rotated_s3
0.0

Differs from Python: MATLAB draws its own shift and rotation for a seed, so this instance is not Python's.

problem = ypea.benchmarks.problem("rastrigin", 10, shift=true, rotate=true, seed=3);
disp(problem.name)
optimum = struct("x", problem.info.x_opt);  % the moved optimum
disp(problem.objective(optimum))
rastrigin_d10_shifted_rotated_s3
     0

info["x_opt"] is the optimum, and info["shift"] and info["rotate"] hold the vector and matrix. Michalewicz cannot be shifted or rotated.

ypea.benchmarks.classic(dim) returns the whole suite as a list of problems (without Michalewicz when shifted or rotated), and ypea.benchmarks.names() the names.

CEC 2017

The 30 functions of the CEC 2017 competition on bound-constrained optimization (Awad et al. 2016): unimodal (F1 to F3), simple multimodal (F4 to F10), hybrid (F11 to F20) and composition (F21 to F30). The range is [-100, 100], and function F has the optimum 100 F. cec2017(10) gives the whole suite in 10 dimensions:

import ypea

problems = ypea.benchmarks.cec2017(10)
print(len(problems), problems[0].name, problems[0].optimum)
29 cec2017_f1_d10 100.0
problems = ypea.benchmarks.cec2017(10);
fprintf("%d %s %g\n", numel(problems), problems{1}.name, problems{1}.optimum);
29 cec2017_f1_d10 100

The suite has 29 problems, not 30, because F2 is left out (see below).

Dimension Functions
2 F1 to F10 and F23 to F28
10, 30, 50, 100 F1 to F30
20 F1 to F10 and F20 to F28

The official data covers only these. F2 was removed from the competition as numerically unstable, so cec2017(dim) leaves it out unless you pass include_f2=True or functions=[2]. cec2017(dim, functions=[1, 4, 5]) gives a subset, cec2017_problem(f, dim) one problem, and cec2017_function(f, dim) the bare function.

CEC 2022

The 12 functions of the CEC 2022 competition (Kumar et al. 2021), at dimensions 10 and 20, and all but F6 to F8 also at dimension 2. The range is [-100, 100], and the optima are 300, 400, 600, 800, 900, 1800, 2000, 2200, 2300, 2400, 2600 and 2700.

The example prints the optima of the first four functions in 20 dimensions:

import ypea

problems = ypea.benchmarks.cec2022(20)
optima = []
for p in problems[:4]:
    optima.append(p.optimum)
print(optima)
[300.0, 400.0, 600.0, 800.0]
problems = ypea.benchmarks.cec2022(20);
optima = zeros(1, 4);
for k = 1:4
    optima(k) = problems{k}.optimum;
end
disp(optima)
   300   400   600   800

cec2022_problem(f, dim) and cec2022_function(f, dim) work as for CEC 2017.

Both suites are ports of the official C code with the official data, tested against values from the compiled C code. Where the C code and the technical report disagree, the port follows the C code, because the published results came from it. The module docstrings list these cases.

The CEC 1e-8 rule

The CEC rules count an error below 1e-8 as 0. Experiment reports keep the raw values, so set report.zero_below = 1e-8 before you compare your tables with published CEC results.

The CEC 2017 rules also fix the budget (10 000 D evaluations), the runs (51) and the points where the error is recorded. Experiment records the error at these points by default (see Experiments).

Data and license

The CEC data ships with the package, unchanged, in compressed NumPy files with a notice that credits the organizers (github.com/P-N-Suganthan). Cite the technical report of a suite when you publish results on it:

  • N. H. Awad, M. Z. Ali, P. N. Suganthan, J. J. Liang and B. Y. Qu, "Problem Definitions and Evaluation Criteria for the CEC 2017 Special Session and Competition on Single Objective Real-Parameter Numerical Optimization", Technical Report, Nanyang Technological University, Singapore, 2016.
  • A. Kumar, K. V. Price, A. W. Mohamed, A. A. Hadi and P. N. Suganthan, "Problem Definitions and Evaluation Criteria for the CEC 2022 Special Session and Competition on Single Objective Bound Constrained Numerical Optimization", Technical Report, Nanyang Technological University, Singapore, 2021.