A benchmark functions collection wrote in Python 3, suited for assessing the performances of optimisation problems on deterministic functions.
Benchmark Functions: a Python Collection
A benchmark functions collection wrote in Python 3, suited for assessing the performances of optimisation problems on deterministic functions. Most functions here implemented can be created in an arbitrary number of dimensions. Suggested boundaries, as well the values of known minima/maxima, are also provided. Finally, every function can be visualised with an interactive widget.
To use a function from the collection it is sufficient to instantiate the relative class from the library:
import benchmark_functions as bf func = bf.Schwefel(n_dimensions=4)
calling directly the instantiated function on a point will provide the function's value:
point = [25, -34.6, -112.231, 242] func(point) # results in -129.38197657025287
Most functions impelmented can be instantiated with an arbitrary number of dimensions. This can be set with a n_dimensions optional parameter. If the numer of dimensions are not specified a default value (generally $N=2$) will be used. Some functions require other specific parameters (e.g. Ackley), these can be set in the constructor, otherwise default values will be taken. Some functions are only defined for 2 dimensions (e.g. Easom) in these cases no n_dimensions parameter is accepted.
Normally, these functions are designed for a minimisation problem, so they are designed accordingly. An optional flag opposite can be passed in any function constructor. If set to True the value of the function will be the opposite at each call, as well as the optimum value. This is useful to use a maximisation algorithm on these functions.
A set of convenience functions are also set in the class, namely:
- getName the name of the function
- getMinima/getMaxima[^1] a list of tuples (point, value) with the coordinate and value of the global minima/maxima. If any value is unkown, a None value will be present instead.
- getMinimum/getMaximum[^1] a single tuple (point, value) with the coordinate and value of the global minimum/maximum. If any value is unkown, a None value will be present instead.
- getSuggestedBounds returns a tuple of two elements (LB, UB) each one is a list of n_dimensions elements, representing the suggested search boundary of the function.
- show plot the function in an interactive graphic widget. Read the relative section below for more information on this feature.
As an example, the following code:
([-500.0, -500.0, -500.0, -500.0], [500.0, 500.0, 500.0, 500.0])
for the Schwefel function.
[^1]: generally a function global minimum/maximum can change with the number of dimensions. For this reason some minima/maxima values may be missing or inaccurate. If you find a better global optimum please open an issue about that with the coordinates and I'll update the library.
Visualise a function
Using the show function will plot the benchmark function in an interactive widget. This can be done only if the n_dimensions is lower than 3. The resulting plot is either a 3D surface (when n_dimensions=2) or a simple 2D graph plot (n_dimensions=1). If the function is defined in 2 dimensions, it is also possible to plot it as an heatmap setting the function parameter asHeatMap=True as follows:
Note: whilst importing and using the library require nothing more than the tandard math python library, in order to visualise the functions the libraries mlp_toolkits, numpy, and matplotlib are also required.
List of Available Functions
For a list of available functions please refer to the project homepage.
Author and License
This library is developed and mantained by Luca Baronti (gmail address: lbaronti) and released under GPL v3 license.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size benchmark_functions-0.1.2-py3-none-any.whl (24.2 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size benchmark_functions-0.1.2.tar.gz (15.4 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for benchmark_functions-0.1.2-py3-none-any.whl
Hashes for benchmark_functions-0.1.2.tar.gz