Benchmarks¶
Common mathematical benchmark functions for optimization tasks.
- evolib.utils.benchmarks.ackley(x)[source]¶
Ackley function (n-dimensional).
Global minimum: f(0, …, 0) = 0 Recommended domain: x_i ∈ [-32.768, 32.768]
- Parameters:
x (list or np.ndarray) – Input vector.
- Returns:
Function value at x.
- Return type:
float
- evolib.utils.benchmarks.ackley_2d(x, y, a=20, b=0.2, c=6.283185307179586)[source]¶
2D Ackley test function.
Global minimum at (0, 0): f(0,0) = 0
- Parameters:
x (float | np.ndarray) – x-coordinate(s)
y (float | np.ndarray) – y-coordinate(s)
a (float) – Ackley function parameters
b (float) – Ackley function parameters
c (float) – Ackley function parameters
- Returns:
function value(s)
- Return type:
float | np.ndarray
- evolib.utils.benchmarks.ackley_3d(x, y, z)[source]¶
3D Ackley function evaluated on meshgrid-style inputs.
Global minimum at (0, 0, 0).
- Return type:
ndarray
- evolib.utils.benchmarks.generate_timeseries(length, normalize=True, pattern='default', seed=None)[source]¶
Generate synthetic time series data for evolution or forecasting. Uses local RNG to avoid modifying global numpy random state.
- Parameters:
length (int) – Number of time steps.
normalize (bool) – Whether to scale the output to [-1, 1].
pattern (str) – Pattern to generate: - “default”: Trend + Sinus + Noise - “trend_switch”: Linear trend up, then down - “parabolic”: Smooth U-shaped curve (trend reversal) - “zigzag”: Periodic linear up/down pattern - “shock”: Trend followed by sharp reversal
- Returns:
The generated time series.
- Return type:
np.ndarray
- evolib.utils.benchmarks.griewank(x)[source]¶
Griewank function (n-dimensional).
Global minimum: f(0, …, 0) = 0 Recommended domain: x_i ∈ [-600, 600]
- Parameters:
x (list or np.ndarray) – Input vector.
- Returns:
Function value at x.
- Return type:
float
- evolib.utils.benchmarks.griewank_2d(x, y)[source]¶
2D Griewank function, evaluated element-wise on meshgrid arrays.
Global minimum at (0, 0) with f(x, y) = 0. Non-convex, with moderate multimodality.
- Parameters:
x (np.ndarray) – Meshgrid-style array of x-values.
y (np.ndarray) – Meshgrid-style array of y-values.
- Returns:
Fitness values for each (x, y) pair.
- Return type:
np.ndarray
- evolib.utils.benchmarks.griewank_3d(x, y, z)[source]¶
3D Griewank function.
Global minimum at (0, 0, 0).
- Return type:
ndarray
- evolib.utils.benchmarks.lfsr_sequence(length, seed=19, taps=(5, 2), invert_feedback=True)[source]¶
Generate a binary sequence using an n-bit LFSR (Linear Feedback Shift Register).
- Parameters:
length (int) – Number of output bits to generate.
seed (int, optional) – Initial state of the LFSR (must be non-zero). Default: 0b10011.
taps (tuple[int, ...], optional) – Tap positions (1-based, e.g. (5, 2) for x^5 + x^2 + 1).
invert_feedback (bool, optional) – If True (default), the feedback bit is inverted at initialization. This variant ensures a maximal-length sequence for (5, 2). If False, the classical Fibonacci-LFSR update rule is used.
- Returns:
Generated bit sequence of the given length.
- Return type:
list[int]
- evolib.utils.benchmarks.random_fixed_sequence(length, seed=1234)[source]¶
Generate a reproducible random bit sequence with a fixed seed.
- Parameters:
length (int) – Length of the sequence.
seed (int, optional) – Random seed for reproducibility. Default: 1234.
- Returns:
Generated random bit sequence (0/1).
- Return type:
list[int]
- evolib.utils.benchmarks.rastrigin(x, A=10)[source]¶
Rastrigin-Funktion (n-dimensional).
Globales Minimum: f(0, …, 0) = 0 Empfohlener Suchraum: x_i ∈ [-5.12, 5.12]
- Parameters:
x (list or np.ndarray) – Eingabevektor (beliebige Dimension).
A (float) – Konstante der Rastrigin-Funktion (Standard: 10).
- Returns:
Funktionswert der Rastrigin-Funktion an der Stelle x.
- Return type:
float
- evolib.utils.benchmarks.rastrigin_2d(x, y)[source]¶
2D Rastrigin function, evaluated element-wise on meshgrid arrays.
Global minimum at (0, 0) with f(x, y) = 0. Highly multimodal.
- Parameters:
x (np.ndarray) – Meshgrid-style array of x-values.
y (np.ndarray) – Meshgrid-style array of y-values.
- Returns:
Fitness values for each (x, y) pair.
- Return type:
np.ndarray
- evolib.utils.benchmarks.rastrigin_3d(x, y, z)[source]¶
3D Rastrigin function.
Global minimum at (0, 0, 0).
- Return type:
ndarray
- evolib.utils.benchmarks.rosenbrock(x)[source]¶
Rosenbrock function (n-dimensional).
Global minimum: f(1, …, 1) = 0 Recommended domain: x_i ∈ [-5, 10]
- Parameters:
x (list or np.ndarray) – Input vector.
- Returns:
Function value at x.
- Return type:
float
- evolib.utils.benchmarks.rosenbrock_2d(x, y)[source]¶
2D Rosenbrock function.
Global minimum at (1, 1) with f(x, y) = 0.
- Parameters:
x (float or np.ndarray) – x-coordinate(s)
y (float or np.ndarray) – y-coordinate(s)
- Returns:
function value(s)
- Return type:
float or np.ndarray
- evolib.utils.benchmarks.rosenbrock_3d(x, y, z)[source]¶
3D Rosenbrock function.
Minimum at (1, 1, 1).
- Return type:
ndarray
- evolib.utils.benchmarks.schwefel(x)[source]¶
Schwefel function (n-dimensional).
Global minimum: f(420.9687, …, 420.9687) = 0 Recommended domain: x_i ∈ [-500, 500]
- Parameters:
x (list or np.ndarray) – Input vector.
- Returns:
Function value at x.
- Return type:
float
- evolib.utils.benchmarks.schwefel_2d(x, y)[source]¶
2D Schwefel function, evaluated element-wise on meshgrid arrays.
Global minimum at (420.9687, 420.9687) with f(x, y) = 0. Many local minima; highly deceptive.
- Parameters:
x (np.ndarray) – Meshgrid-style array of x-values.
y (np.ndarray) – Meshgrid-style array of y-values.
- Returns:
Fitness values for each (x, y) pair.
- Return type:
np.ndarray
- evolib.utils.benchmarks.schwefel_3d(x, y, z)[source]¶
3D Schwefel function.
Minimum at (420.9687, 420.9687, 420.9687).
- Return type:
ndarray
- evolib.utils.benchmarks.simple_quadratic(x)[source]¶
Simple 1D benchmark: f(x) = x^2
Global minimum: f(0) = 0
- Parameters:
x (float or np.ndarray) – Input value(s).
- Returns:
Function value.
- Return type:
float
- evolib.utils.benchmarks.sphere(x)[source]¶
Sphere function (n-dimensional).
Global minimum: f(0, …, 0) = 0 Recommended domain: x_i ∈ [-5.12, 5.12]
- Parameters:
x (list or np.ndarray) – Input vector.
- Returns:
Function value at x.
- Return type:
float
- evolib.utils.benchmarks.sphere_2d(x, y)[source]¶
2D Sphere function, evaluated element-wise on meshgrid arrays.
Global minimum at (0, 0) with f(x, y) = 0. Convex and unimodal.
- Parameters:
x (np.ndarray) – Meshgrid-style array of x-values.
y (np.ndarray) – Meshgrid-style array of y-values.
- Returns:
Fitness values for each (x, y) pair.
- Return type:
np.ndarray
- evolib.utils.benchmarks.sphere_3d(x, y, z)[source]¶
3D Sphere function.
Global minimum at (0, 0, 0).
- Return type:
ndarray
- evolib.utils.benchmarks.xor_sequence(length, k=2, seed=(0, 1))[source]¶
Generate a sequence where each new bit is the XOR of the last k bits.
- Parameters:
length (int) – Length of the sequence to generate.
k (int, optional) – Window size for XOR. Default: 2 (classic XOR sequence).
seed (Sequence[int], optional) – Initial bits to start the sequence. Must have length >= k.
- Returns:
Generated bit sequence of the given length.
- Return type:
list[int]