Benchmarks

class beeoptimal.benchmarks.BenchmarkFunction(fun, bounds, optimal_solution, name='')[source]

Bases: object

Class to define a D-dimensional benchmark function for optimization.

fun

The function to evaluate.

Type:

callable

bounds

The bounds of the function, provided as a numpy array of shape (D,2) or (2,D).

Type:

numpy-array

optimal_solution

The known solution achieving the optimal value, provided as numpy array of shape (D,), (D,1) or (1,D).

Type:

numpy-array

name

The name of the function. Defaults to empty string.

Type:

str, optional

Examples

>>> from beeoptimal.benchmarks import BenchmarkFunction
>>> import numpy as np
>>> sphere = lambda point: np.sum(np.array(point)**2)
>>> Sphere2d = BenchmarkFunction(
        name             = "Sphere-2d",
        fun              = sphere,
        bounds           = np.array([(-5.12, 5.12)]*2),
        optimal_solution = np.zeros(2)
    )
evaluate(point)[source]

Evaluate the function at the given point.

Parameters:

point (array-like) – The point at which to evaluate the function, provided as numpy array of shape (D,), (D,1) or (1,D).

Returns:

The value of the function computed at the given point.

Return type:

float

Raises:
  • TypeError – If the point is not provided as a numpy array.

  • ValueError – If the point dimensions are not consistent with the optimal solution

property optimal_value

Return the optimal value of the function.