How supported optimization algorithms are tested#

estimagic provides a unified interface that supports a large number of optimization algorithms from different libraries. Additionally, it allows putting constraints on the optimization problem. To test the external interface of all supported algorithms, we consider different criterion (benchmark) functions and test each algorithm with every type of constraint.

Benchmark functions for testing#

Trid function#

\(f({x}) = \Sigma^{D}_{i=1}(x_{i} - 1)^2 - \Sigma^{D}_{i=2}(x_i x_{i-1})\)

Rotated Hyper Ellipsoid function#

\(f({x}) = \Sigma^{D}_{i=1} \Sigma^{i}_{j=1}x_j^2\)

Rosenbrock function#

\(\Sigma^{D-1}_{i=1}(100(x_i+1 - x_i^2)^2 + (x_i - 1)^2)\)

Sphere function#

\(f({x}) = \Sigma^{D}_{i=1} ix_{i}^2\)

How testcases are implemented#

We consider different implementations of each criterion and its gradient. All algorithms accept criterion functions specified in a dictionary, while a subset also accepts the criterion specified in scalar form. Likewise, if specified, the gradient of a criterion can be an np.ndarray or a pandas object. We test for all possible cases. For instance, for rotated hyper ellipsoid, we implement the following functions:

  • rotated_hyper_ellipsoid_scalar_criterion

  • rotated_hyper_ellipsoid_dict_criterion: This provides a dictionary wherein the contributions and root_contributions keys present the criterion as a least squares problem, relevant when we are testing a least squares algorithm.

  • rotated_hyper_ellipsoid_gradient

  • rotated_hyper_ellipsoid_pandas_gradient: Computes the gradient of the rotated hyper ellipsoid function, as a pandas object.

  • rotated_hyper_ellipsoid_criterion_and_gradient

These criterion functions are specified in the examples directory. For an overview of all constraints supported in estimagic, please see this how-to guide.

We write several test functions, each corresponding to the case of one constraint. Given the constraint, the test function considers all possible combinations of the algorithm, whether to maximize or to minimize, criterion function implementation, gradient implementation for that criterion (if provided), and whether criterion_and_derivative has been provided or not.

Below, we show the calculations behind the true values, for each testcase (one criterion and one constraint).

Trid: Solutions for three-dimension case#

\(f({x}) = (x_1-1)^2 + (x_2-1)^2 + (x_3-1)^2 - x_2 x_1 - x_3 x_2\)

Rotated Hyper Ellipsoid: Solutions for three-dimension case#

\(f({x}) = x^2_1 + (x^2_1 + x^2_2) + (x^2_1 + x^2_2 + x^2_3)\)

Rosenbrock: Solutions for three-dimension case#

\(f({x}) = 100(x_2 - x_1^2) + (x_1 - 1)^2\)

Global minima: \(x* = (1, 1, 1)\)