Skip to content

BBOB

The names of the available benchmark functions are the keys of evosax.problems.bbob_fns.

BBOBProblem

BBOBProblem(fn_name: str = 'sphere', num_dims: int = 2, x_opt: Array | None = None, f_opt: float | None = None, sample_rotations: bool = True, noise_config: dict = {'noise_model_name': 'noiseless', 'use_stabilization': True}, seed: int = 0)

Bases: Problem

Blackbox Optimization Benchmarking (BBOB).

A single instance of one BBOB function with a fixed number of dimensions. The instance (optimum location, optimal value, rotations and noise parameters) is sampled once in the constructor from seed and reused by every eval call. Solutions are flat arrays of shape (num_dims,).

Parameters:

  • fn_name (str, default: 'sphere' ) –

    Name of the BBOB function, a key of bbob_fns in evosax.problems.bbob.bbob_fns, e.g. "sphere" or "rosenbrock".

  • num_dims (int, default: 2 ) –

    Number of search dimensions.

  • x_opt (Array | None, default: None ) –

    Location of the optimum. If None, it is sampled uniformly from x_opt_range.

  • f_opt (float | None, default: None ) –

    Function value at the optimum, added to every fitness value. If None, it is sampled.

  • sample_rotations (bool, default: True ) –

    If True, use randomly sampled rotation matrices. If False, use identity matrices.

  • noise_config (dict, default: {'noise_model_name': 'noiseless', 'use_stabilization': True} ) –

    Dictionary with the entries "noise_model_name" (one of "noiseless", "gaussian", "uniform", "cauchy", "additive") and "use_stabilization" (if True, noise is stabilized close to the optimal value).

  • seed (int, default: 0 ) –

    Seed of the PRNG key used to sample the problem instance.

References

x_range property

x_range

Range of the search space for solutions.

x_opt_range property

x_opt_range

Range for the optimal solution location.

f_opt_range property

f_opt_range

Range for the optimal function value.

x_opt property

x_opt

Optimal solution location.

f_opt property

f_opt

Optimal function value.

num_dims property

num_dims: int

Number of search dimensions, i.e. the total size of a solution.

init

init(key: Array) -> State

Initialize the problem state with an evaluation counter of zero.

eval

eval(key: Array, solutions: Population, state: State) -> tuple[Fitness, State, Metrics]

Evaluate a population of solutions on the BBOB function.

Parameters:

  • key (Array) –

    PRNG key, used by the noise model.

  • solutions (Population) –

    Population to evaluate, an array of shape (population_size, num_dims).

  • state (State) –

    Current problem state.

Returns:

  • tuple[Fitness, State, Metrics] –

    A tuple (fitness, state, info). fitness is the function value to minimize: the noisy function value plus the boundary penalty plus f_opt. state has its counter incremented. info contains "fn_val" (function value without noise, penalty and f_opt), "fn_noise" (function value after the noise model) and "fn_pen" (boundary penalty).

sample

sample(key: Array) -> Solution

Sample a solution uniformly from x_range.

Parameters:

  • key (Array) –

    PRNG key.

Returns:

  • Solution –

    An array of shape (num_dims,).

visualize_2d

visualize_2d(key: Array, *, ax=None, logscale=False)

Visualize the optimization problem as a 2D contour plot.

Requires num_dims == 2. The location of the optimum is marked with a star for most functions.

Parameters:

  • key (Array) –

    PRNG key used to evaluate the function on the grid.

  • ax (Axes | None, default: None ) –

    Matplotlib axes to draw on. If None, a new figure is created.

  • logscale (bool, default: False ) –

    If True, shift the function values to be at least 1 and use a logarithmic color scale.

Returns:

  • fig ( Figure ) –

    The Matplotlib figure containing the plot.

visualize_3d

visualize_3d(key: Array, *, ax=None, logscale=False)

Visualize the optimization problem as a 3D surface plot.

Requires num_dims == 2.

Parameters:

  • key (Array) –

    PRNG key used to evaluate the function on the grid.

  • ax (Axes | None, default: None ) –

    Matplotlib 3D axes to draw on. If None, a new figure is created.

  • logscale (bool, default: False ) –

    If True, shift the function values to be at least 1 and plot their logarithm.

Returns:

  • fig ( Figure ) –

    The Matplotlib figure containing the plot.

MetaBBOBProblem

MetaBBOBProblem(fn_names: list[str] = ['sphere'], min_num_dims: int = 2, max_num_dims: int = 8, noise_config: dict = {'noise_model_names': 'noiseless', 'use_stabilization': True})

Bases: MetaProblem

Blackbox Optimization Benchmarking Meta-Problem class.

A family of BBOB problem instances. sample_params draws an instance: a function from fn_names, a number of active dimensions, the optimum location and value, rotation matrices and noise parameters. Solutions are always flat arrays of shape (max_num_dims,); an instance only uses its first params.num_dims entries.

Parameters:

  • fn_names (list[str], default: ['sphere'] ) –

    Names of the BBOB functions to sample from, keys of bbob_fns in evosax.problems.bbob.bbob_fns.

  • min_num_dims (int, default: 2 ) –

    Lower bound of the number of active dimensions of an instance, which is drawn with jax.random.randint(minval=min_num_dims, maxval=max_num_dims).

  • max_num_dims (int, default: 8 ) –

    Size of the solution vectors and maxval of the draw of the number of active dimensions.

  • noise_config (dict, default: {'noise_model_names': 'noiseless', 'use_stabilization': True} ) –

    Keyword arguments of the noise model (evosax.problems.bbob.bbob_noise.NoiseModel), e.g. "noise_model_names" (a name or list of names among "noiseless", "gaussian", "uniform", "cauchy", "additive") and "use_stabilization".

References

num_dims property

num_dims: int

Number of search dimensions, i.e. the total size of a solution.

sample_params

sample_params(key: Array) -> Params

Sample the parameters of a BBOB problem instance.

Parameters:

  • key (Array) –

    PRNG key.

Returns:

  • Params –

    Parameters with the function id (index into fn_names), the number of active dimensions, the optimum location x_opt (uniform in x_opt_range), the optimal value f_opt (Cauchy distributed with scale 100, clipped to [-1000, 1000]), the rotation matrices R and Q and the noise model parameters.

init

init(key: Array, params: Params) -> State

Initialize the problem state with an evaluation counter of zero.

eval

eval(key: Array, solutions: Population, state: State, params: Params) -> tuple[Fitness, State, Metrics]

Evaluate a population of solutions on a BBOB problem instance.

Parameters:

  • key (Array) –

    PRNG key, used by the noise model.

  • solutions (Population) –

    Population to evaluate, an array of shape (population_size, max_num_dims).

  • state (State) –

    Current problem state.

  • params (Params) –

    Parameters of the problem instance.

Returns:

  • tuple[Fitness, State, Metrics] –

    A tuple (fitness, state, info). fitness is the function value to minimize: the noisy function value plus the boundary penalty plus params.f_opt. state has its counter incremented. info contains "fn_val" (function value without noise, penalty and f_opt), "fn_noise" (function value after the noise model) and "fn_pen" (boundary penalty).

sample

sample(key: Array) -> Solution

Sample a solution uniformly from x_range.

Parameters:

  • key (Array) –

    PRNG key.

Returns:

  • Solution –

    An array of shape (max_num_dims,).

generate_random_rotation

generate_random_rotation(key: Array, num_dims: int) -> jax.Array

Generate a random (n, n) rotation matrix uniformly sampled from SO(n).

This implementation follows the method described in: "How to generate a random unitary matrix" [Maris Ozols 2006] http://home.lu.lv/~sd20008/papers/essays/Random%20unitary%20[paper].pdf https://github.com/alecjacobson/gptoolbox/blob/master/matrix/rand_rotation.m

Uses a fixed-size matrix of max_num_dims and masks the extra dimensions to handle variable num_dims while remaining jit-compatible.

Parameters:

  • key (Array) –

    PRNG key.

  • num_dims (int) –

    Number of active dimensions n.

Returns:

  • Array –

    A matrix of shape (max_num_dims, max_num_dims) whose leading (num_dims, num_dims) block holds the sampled rotation.