Skip to main content

A benchmark functions collection wrote in Python 3, suited for assessing the performances of optimisation problems on deterministic functions.

Project description

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.

Usage

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:

print(func.getSuggestedBounds())

will produce

([-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:

func.show(asHeatMap=True)

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

benchmark_functions-0.1.2.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

benchmark_functions-0.1.2-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file benchmark_functions-0.1.2.tar.gz.

File metadata

  • Download URL: benchmark_functions-0.1.2.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.47.0 CPython/3.8.5

File hashes

Hashes for benchmark_functions-0.1.2.tar.gz
Algorithm Hash digest
SHA256 040cf946b8c9e36b2289230dc381765338640f6414392bcde594191e4e708d74
MD5 70cf0f233dfbf160192cbc506a34c9ad
BLAKE2b-256 b1fdfa4f1367470a831580ea7956e3b972231d512110e7f9e23a96eeea0d36ca

See more details on using hashes here.

File details

Details for the file benchmark_functions-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: benchmark_functions-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.4.2 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.8.0 tqdm/4.47.0 CPython/3.8.5

File hashes

Hashes for benchmark_functions-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c9d9bed94cd0ec6bc1f76b044821a1d5978d93ab1a271c1d32493d90a1a558ba
MD5 6cc485f92ae420db47c745f1a88cd7ea
BLAKE2b-256 37f4c1cc043c3883cb3d94e3383dcf0ec21de53ca5e23797429edaf10aef876c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page