optim4ai

Logo

Optimisation for Artificial Intelligence, a 4-day course

View the Project on GitHub xoolive/optim4ai

A bestiary of functions

« Previous | Up ↑ | Next »

File bestiary.py provides implementations for three famous functions which are challenging for optimisation methods.

from bestiary import *

Himmelblau’s function

Himmelblau’s function has four identical local minima, including one in $(3, 2)$. It is defined as:

\[f(x, y) = (x^2+y-11)^2 + (x+y^2-7)^2\]
vec = np.linspace(-5, 5, 100)
X, Y = np.meshgrid(vec, vec)
contour_function(himmelblau, X, Y)

himmelblau

animate_function(himmelblau, X, Y)

Rastrigin’s function

Rastrigin’s function is a typical example of non-linear multimodal function, which generalises in $n$ dimensions. Finding the minimum of this function is a fairly difficult problem due to its large search space and its large number of local minima.

vec = np.linspace(-5, 5, 100)
X, Y = np.meshgrid(vec, vec)
contour_function(rastrigin, X, Y)

rastrigin

animate_function(rastrigin, X, Y)

Boulders

This function is a fun one to compute: imagine a handful of boulders hitting a plane, leaving a hole of a determined depth. If you know where the boulders hit, it is relatively easy to find the global minimum, but it is a good one to generate always new functions for challenging your algorithms.

vec = np.linspace(0, 1, 100)
X, Y = np.meshgrid(vec, vec)
b = boulders(64)  # the number of boulders
contour_function(b)

boulders

animate_function(b, X, Y)

« Previous | Up ↑ | Next »