opfunu.benchmark module

class opfunu.benchmark.Benchmark[source]

Bases: object

Defines an abstract class for optimization benchmark problem.

All subclasses should implement the evaluate method for a particular optimization problem.

bounds

The lower/upper bounds of the problem. This a 2D-matrix of [lower, upper] array that contain the lower and upper bounds. By default, each problem has its own bounds. But user can try to put different bounds to test the problem.

Type

list

ndim

The dimensionality of the problem. It is calculated from bounds

Type

int

lb

The lower bounds for the problem

Type

np.ndarray

ub

The upper bounds for the problem

Type

np.ndarray

f_global

The global optimum of the evaluated function.

Type

float

x_global

A list of vectors that provide the locations of the global minimum. Note that some problems have multiple global minima, not all of which may be listed.

Type

np.ndarray

n_fe

The number of function evaluations that the object has been asked to calculate.

Type

int

dim_changeable

Whether we can change the benchmark function x variable length (i.e., the dimensionality of the problem)

Type

bool

property bounds

The lower/upper bounds to be used for optimization problem. This a 2D-matrix of [lower, upper] array that contain the lower and upper bounds for the problem. The problem should not be asked for evaluation outside these bounds. len(bounds) == ndim.

check_ndim_and_bounds(ndim=None, bounds=None, default_bounds=None)[source]

Check the bounds when initializing the object.

Parameters
  • ndim (int) – The number of dimensions (variables)

  • bounds (list, tuple, np.ndarray) – List of lower bound and upper bound, should use default None value

  • default_bounds (np.ndarray) – List of initial lower bound and upper bound values

check_solution(x)[source]

Raise the error if the problem size is not equal to the solution length

Parameters

x (np.ndarray) – The solution

continuous = True
convex = True
create_solution() numpy.ndarray[source]

Create a random solution for the current problem

Returns

solution – The random solution

Return type

1D-vector

differentiable = True
evaluate(x)[source]

Evaluation of the benchmark function.

Parameters

x (np.ndarray) – The candidate vector for evaluating the benchmark problem. Must have len(x) == self.ndim.

Returns

val – the evaluated benchmark function

Return type

float

get_paras()[source]

Return the parameters of the problem. Depended on function

is_ndim_compatible(ndim)[source]

Method to support searching the functions with input ndim

Parameters

ndim (int) – The number of dimensions

Returns

val – Always true if dim_changeable = True, Else return ndim == self.ndim

Return type

bool

is_succeed(x, tol=1e-05)[source]

Check if a candidate solution at the global minimum.

Parameters
  • x (np.ndarray) – The candidate vector for testing if the global minimum has been reached. Must have len(x) == self.ndim

  • tol (float) – The evaluated function and known global minimum must differ by less than this amount to be at a global minimum.

Returns

is_succeed – Answer the question: is the candidate vector at the global minimum?

Return type

bool

latex_formula = 'f(\\mathbf{x})'
latex_formula_bounds = 'x_i \\in [-2\\pi, 2\\pi], \\forall i \\in \\llbracket 1, d\\rrbracket'
latex_formula_dimension = 'd \\in \\mathbb{N}_{+}^{*}'
latex_formula_global_optimum = 'f(0, ..., 0)=-1, \\text{ for}, m=5, \\beta=15'
property lb

The lower bounds for the problem

Returns

lb – The lower bounds for the problem

Return type

1D-vector

linear = False
modality = True
name = 'Benchmark name'
property ndim

The dimensionality of the problem.

Returns

ndim – The dimensionality of the problem

Return type

int

parametric = True
randomized_term = False
scalable = True
separable = False
property ub

The upper bounds for the problem

Returns

ub – The upper bounds for the problem

Return type

1D-vector

unimodal = False