Skip to main content

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/getMaxima1 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/getMaximum1 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.

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.

  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. ↩ ↩2

Metadata

Release files for benchmark-functions 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for benchmark-functions 0.1.2
File Size Uploaded
benchmark_functions-0.1.2.tar.gz 15.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for benchmark-functions 0.1.2
File Interpreter ABI Platform
benchmark_functions-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 39.6 kB

Release files / benchmark_functions-0.1.2.tar.gz

Download URL benchmark_functions-0.1.2.tar.gz
Size 15.4 kB
Tags Source
SHA-256 checksum
How to use checksums
040cf946b8c9e36b2289230dc381765338640f6414392bcde594191e4e708d74
BLAKE2b-256 checksum
How to use checksums
b1fdfa4f1367470a831580ea7956e3b972231d512110e7f9e23a96eeea0d36ca
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / benchmark_functions-0.1.2-py3-none-any.whl

Download URL benchmark_functions-0.1.2-py3-none-any.whl
Size 24.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c9d9bed94cd0ec6bc1f76b044821a1d5978d93ab1a271c1d32493d90a1a558ba
BLAKE2b-256 checksum
How to use checksums
37f4c1cc043c3883cb3d94e3383dcf0ec21de53ca5e23797429edaf10aef876c
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1

2 release files

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page