Optimization Test Functions#

This subpackage provides access to several engineered objective functions for testing optimization algorithms

Entries on this page:

Base Class for Test Functions#

class TestFunction[source]#

Bases: object

Base Class for test functions used to verify optimization algorithms

evaluate(x)[source]#

Evaluate the function at the passed variable value

global_maxima()[source]#

A list of one or more values of the random variable x with f(x) being the global maximum value.

global_minima()[source]#

A list of one or more values of the random variable x with f(x) being the global minimum value.

Test Functions with Binary Input#

class IsolatedBinaryOptimizationFunction(a, n)[source]#

Bases: TestFunction

Note

This function is under development.

A test function for binary optimization defined on the following form

\[f(x) := \begin{cases} 10 n a ; x[: n//2] = n//2, x[n//2: ] = 0 10 n a ; x[: n//3] = n//3, x[n//3: ] = 0 - 10 n a ; x[: n//2] = 0, x[n//2: ] = n//2 - 10 n a ; x[: n//3] = 0, x[n//3: ] = n // 3 5 \lfloor \frac{n}/2 \rfloor - |x| * a ; & |x| > a \ 5 \lfloor \frac{n}/2 \rfloor -|x| * a ; & |x| < a \ 5 \lfloor \frac{n}/2 \rfloor * a ; & |x| = a \,, \end{cases}\]

where :\(x\) is the variable, and :\(n\) is its (integer) dimension, and both :\(a\) and :\(n\) are parameters passed upon instantiation. Here, a is assumed to be a postive number.

The global maximum of this function is :\(2 n a\) achieved by two vectors, and the global minimum of this function is :\(-2 n a\) achieved by two vectors.

Parm a:

positive number

Parm n:

positive integer representing dimension of the domain/variable

__init__(a, n)[source]#
evaluate(x)[source]#

Evaluate the function at the passed x viewed as a boolean variable.

property global_maxima#

A list of one or more values of the random variable x with f(x) being the global maximum value.

property global_minima#

A list of one or more values of the random variable x with f(x) being the global minimum value.

class AlternatingSignOptimizationFunction(n)[source]#

Bases: TestFunction

A weighting vector, of the same size as a passed vector x, is created on the form (1, -1, 1, -1, …). The weighting vector is pointwise multiplied by the passed vector and the objective is evaluated as the sum of the resulting vector. The global maximum (unique) is (1, 0, 1, 0, …) The global minimum (unique) is (0, 1, 0, 1, …) :parm n: positiveinteger representing dimension of the domain/variable

__init__(n)[source]#
evaluate(x)[source]#

Evaluate the function at the passed x viewed as a boolean variable.

property global_maxima#

A list of one or more values of the random variable x with f(x) being the global maximum value.

property global_minima#

A list of one or more values of the random variable x with f(x) being the global minimum value.

class WeightedAlternatingSignOptimizationFunction(n)[source]#

Bases: TestFunction

A weighting vector, of the same size as a passed vector x, is created on the form (1, -2, 3, -4, …). The weighting vector is pointwise multiplied by the passed vector and the objective is evaluated as the sum of the resulting vector. The global maximum (unique) is (1, 0, 1, 0, …) The global minimum (unique) is (0, 1, 0, 1, …) :parm n: positiveinteger representing dimension of the domain/variable

__init__(n)[source]#
evaluate(x)[source]#

Evaluate the function at the passed x viewed as a boolean variable.

property global_maxima#

A list of one or more values of the random variable x with f(x) being the global maximum value.

property global_minima#

A list of one or more values of the random variable x with f(x) being the global minimum value.

class FacilityFunction(shape=None, M=None)[source]#

Bases: TestFunction

Given a matrix \(M \in \mathbb{R}^{m \times n}\) with \(M_{i,j} \geq 0\), define the function

\[f(x) := \sum_{i=1}^m \max M[i, x]\]

for any binary vector \(x\). This function is guaranteed to be submodular.

__init__(shape=None, M=None)[source]#

Initialize the function with a matrix M or a shape to generate a random matrix.

Parameters:
  • shape (tuple[int, int] | None) – The shape of the matrix to generate

  • M (ndarray | None) – The matrix to use

evaluate(x)[source]#

Evaluate the function at the passed x viewed as a boolean variable.

Parameters:

x (ndarray) – The binary vector to evaluate