Skip to content

2. Getting started

Iannick Gagnon edited this page May 19, 2025 · 13 revisions

Importing objective functions

The MDAF_objective_functions library provides a variety of well-known objective functions that you can import as follows:

from MDAF_objective_functions import Ackley, Rastrigin, StyblinskiTang, DropWave

To see a list of all available objective functions:

>>> import MDAF_objective_functions as of
>>> of.show_all()
Ackley
Buckin6
DropWave
...

Visualizing objective functions

Each ObjectiveFunction class provides a .visualize() method for quick 2D/3D visualizations:

>>> from MDAF_objective_functions import Bukin6
>>> Bukin6().visualize()

The previous commands will generate the following interactive graph:

Bukin No. 6

Note: The star (⭐) symbol represents the global minimum.

Evaluating objective functions

To evaluate a function at a single position:

>>> from MDAF_objective_functions import Sphere
>>> foo = Sphere()
>>> val = foo.evaluate(np.array([[1, 1]]))
>>> print(val)
[2]

To evaluate a function at multiple positions:

>>> from MDAF_objective_functions import Sphere
>>> foo = Sphere()
>>> val = foo.evaluate(np.array([[1, 1], [2, 2]]))
>>> print(val)
[2, 8]

You can also customize the visualization by passing parameters such as dimensions, bounds, and resolution. See the ObjectiveFunction class documentation for details.

Clone this wiki locally