Skip to content

Optimization API

Bowl shaped functions for the useful-math-functions library.

AbsoluteBowlFunction

Bases: OptFunction

Absolute bowl function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class AbsoluteBowlFunction(OptFunction):
    r"""Absolute bowl function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the absolute bowl function."""
        _validate_two_dimensional(*x, function_name="AbsoluteBowl")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the absolute bowl function at x."""
        x_1, x_2 = self._x
        return np.abs(x_1) + np.abs(x_2)

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the absolute bowl function."""
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the absolute bowl function at x.

__minima__ property

Return the minima of the absolute bowl function.

__init__(*x)

Initialize the absolute bowl function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the absolute bowl function."""
    _validate_two_dimensional(*x, function_name="AbsoluteBowl")
    super().__init__(*x)

BohachevskyFunctionType1

Bases: OptFunction

Bohachevsky function type 1.

The Bohachevsky function type 1 is a 2D-dimensional function with multimodal structure and sharp peaks.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.bowl_shaped import BohachevskyFunctionType1
>>> x = np.linspace(-10, 10, 100)
>>> y = np.linspace(-10, 10, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = BohachevskyFunctionType1(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("BohachevskyFunctionType1.png", dpi=300, transparent=True)
Notes

The Bohachevsky function type 1 is defined as:

\[ f(x) = x_1^2 + 2 x_2^2 - 0.3 \cos(3 \pi x_1) - 0.4 \cos(4 \pi x_2) + 0.7 \]

Reference: Original implementation can be found here

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class BohachevskyFunctionType1(OptFunction):
    r"""Bohachevsky function type 1.

    The Bohachevsky function type 1 is a 2D-dimensional function with multimodal
    structure and sharp peaks.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.bowl_shaped import BohachevskyFunctionType1
        >>> x = np.linspace(-10, 10, 100)
        >>> y = np.linspace(-10, 10, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = BohachevskyFunctionType1(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("BohachevskyFunctionType1.png", dpi=300, transparent=True)

    Notes:
        The Bohachevsky function type 1 is defined as:

        $$
            f(x) = x_1^2 + 2 x_2^2 - 0.3 \cos(3 \pi x_1) - 0.4 \cos(4 \pi x_2) + 0.7
        $$

        > Reference: Original implementation can be found
        > [here](http://www.sfu.ca/~ssurjano/boha.html)

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="BohachevskyType1",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Bohachevsky function type 1 at x.

        Returns:
            UniversalArray: Evaluated function value.
        """
        x_1 = self._x[0]
        x_2 = self._x[1]
        return (
            x_1**2
            + 2 * x_2**2
            - 0.3 * np.cos(3 * np.pi * x_1)
            - 0.4 * np.cos(4 * np.pi * x_2)
            + 0.7
        )

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Bohachevsky function type 1.

        Returns:
            MinimaAPI: Minima of the Bohachevsky function type 1.
        """
        return MinimaAPI(f_x=0, x=(0, 0))

__eval__ property

Evaluate Bohachevsky function type 1 at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Evaluated function value.

__minima__ property

Return the minima of the Bohachevsky function type 1.

Returns:

Name Type Description
MinimaAPI MinimaAPI

Minima of the Bohachevsky function type 1.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="BohachevskyType1",
            dimension=__2d__,
        )
    super().__init__(*x)

BohachevskyFunctionType2

Bases: OptFunction

Bohachevsky function tye 2.

The Bohachevsky function type 2 is a 2D-dimensional function with multimodal structure and sharp peaks.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.bowl_shaped import BohachevskyFunctionType2
>>> x = np.linspace(-10, 10, 100)
>>> y = np.linspace(-10, 10, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = BohachevskyFunctionType2(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("BohachevskyFunctionType2.png", dpi=300, transparent=True)
Notes

The Bohachevsky function type 2 is defined as:

\[ f(x) = x_1^2 + 2 x_2^2 - 0.3 \cos(3 \pi x_1) \cos(4 \pi x_2) + 0.3 \]

Reference: Original implementation can be found here

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class BohachevskyFunctionType2(OptFunction):
    r"""Bohachevsky function tye 2.

    The Bohachevsky function type 2 is a 2D-dimensional function with multimodal
    structure and sharp peaks.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.bowl_shaped import BohachevskyFunctionType2
        >>> x = np.linspace(-10, 10, 100)
        >>> y = np.linspace(-10, 10, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = BohachevskyFunctionType2(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("BohachevskyFunctionType2.png", dpi=300, transparent=True)

    Notes:
        The Bohachevsky function type 2 is defined as:

        $$
            f(x) = x_1^2 + 2 x_2^2 - 0.3 \cos(3 \pi x_1) \cos(4 \pi x_2) + 0.3
        $$

        > Reference: Original implementation can be found
        > [here](http://www.sfu.ca/~ssurjano/boha.html)

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="BohachevskyType2",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Bohachevsky function type 2 at x.

        Returns:
            UniversalArray: Evaluated function value.
        """
        x_1 = self._x[0]
        x_2 = self._x[1]
        return (
            x_1**2
            + 2 * x_2**2
            - 0.3 * np.cos(3 * np.pi * x_1) * np.cos(4 * np.pi * x_2)
            + 0.3
        )

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Bohachevsky function type 2.

        Returns:
            MinimaAPI: Minima of the Bohachevsky function type 2.
        """
        return MinimaAPI(f_x=0, x=(0, 0))

__eval__ property

Evaluate Bohachevsky function type 2 at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Evaluated function value.

__minima__ property

Return the minima of the Bohachevsky function type 2.

Returns:

Name Type Description
MinimaAPI MinimaAPI

Minima of the Bohachevsky function type 2.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="BohachevskyType2",
            dimension=__2d__,
        )
    super().__init__(*x)

BohachevskyFunctionType3

Bases: OptFunction

Bohachevsky function type 3.

The Bohachevsky function type 3 is a 2D-dimensional function with multimodal structure and sharp peaks.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.bowl_shaped import BohachevskyFunctionType3
>>> x = np.linspace(-10, 10, 100)
>>> y = np.linspace(-10, 10, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = BohachevskyFunctionType3(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("BohachevskyFunctionType3.png", dpi=300, transparent=True)
Notes

The Bohachevsky function type 3 is defined as:

\[ f(x) = x_1^2 + 2 x_2^2 - 0.3 \cos(3 \pi x_1 + 4 \pi x_2) + 0.3 \]

Reference: Original implementation can be found here

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class BohachevskyFunctionType3(OptFunction):
    r"""Bohachevsky function type 3.

    The Bohachevsky function type 3 is a 2D-dimensional function with multimodal
    structure and sharp peaks.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.bowl_shaped import BohachevskyFunctionType3
        >>> x = np.linspace(-10, 10, 100)
        >>> y = np.linspace(-10, 10, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = BohachevskyFunctionType3(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("BohachevskyFunctionType3.png", dpi=300, transparent=True)

    Notes:
        The Bohachevsky function type 3 is defined as:

        $$
            f(x) = x_1^2 + 2 x_2^2 - 0.3 \cos(3 \pi x_1 + 4 \pi x_2) + 0.3
        $$

        > Reference: Original implementation can be found
        > [here](http://www.sfu.ca/~ssurjano/boha.html)

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="BohachevskyType3",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Bohachevsky function type 3 at x.

        Returns:
            UniversalArray: Evaluated function value.
        """
        x_1 = self._x[0]
        x_2 = self._x[1]
        return (
            x_1**2 + 2 * x_2**2 - 0.3 * np.cos(3 * np.pi * x_1 + 4 * np.pi * x_2) + 0.3
        )

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Bohachevsky function type 3.

        Returns:
            MinimaAPI: Minima of the Bohachevsky function type 3.
        """
        return MinimaAPI(f_x=0, x=(0, 0))

__eval__ property

Evaluate Bohachevsky function type 3 at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Evaluated function value.

__minima__ property

Return the minima of the Bohachevsky function type 3.

Returns:

Name Type Description
MinimaAPI MinimaAPI

Minima of the Bohachevsky function type 3.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="BohachevskyType3",
            dimension=__2d__,
        )
    super().__init__(*x)

CrossQuadraticFunction

Bases: OptFunction

Cross-quadratic function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class CrossQuadraticFunction(OptFunction):
    r"""Cross-quadratic function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the cross-quadratic function."""
        _validate_two_dimensional(*x, function_name="CrossQuadratic")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the cross-quadratic function at x."""
        x_1, x_2 = self._x
        return (x_1 + x_2) ** 2 + (x_1 - x_2) ** 4

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the cross-quadratic function."""
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the cross-quadratic function at x.

__minima__ property

Return the minima of the cross-quadratic function.

__init__(*x)

Initialize the cross-quadratic function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the cross-quadratic function."""
    _validate_two_dimensional(*x, function_name="CrossQuadratic")
    super().__init__(*x)

CubicNormFunction

Bases: OptFunction

Cubic norm function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class CubicNormFunction(OptFunction):
    r"""Cubic norm function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the cubic norm function."""
        _validate_three_or_higher(*x, function_name="CubicNorm")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the cubic norm function at x."""
        return np.array(sum(np.abs(axis) ** 3 for axis in self._x))

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the cubic norm function."""
        return MinimaAPI(f_x=0.0, x=tuple(0.0 for _ in range(self.dimension)))

__eval__ property

Evaluate the cubic norm function at x.

__minima__ property

Return the minima of the cubic norm function.

__init__(*x)

Initialize the cubic norm function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the cubic norm function."""
    _validate_three_or_higher(*x, function_name="CubicNorm")
    super().__init__(*x)

EllipticAbsoluteRootFunction

Bases: OptFunction

Elliptic absolute-root function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class EllipticAbsoluteRootFunction(OptFunction):
    r"""Elliptic absolute-root function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the elliptic absolute-root function."""
        _validate_two_dimensional(*x, function_name="EllipticAbsoluteRoot")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the elliptic absolute-root function at x."""
        x_1, x_2 = self._x
        return np.sqrt(1 + x_1**2) + np.sqrt(1 + x_2**2) - 2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the elliptic absolute-root function."""
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the elliptic absolute-root function at x.

__minima__ property

Return the minima of the elliptic absolute-root function.

__init__(*x)

Initialize the elliptic absolute-root function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the elliptic absolute-root function."""
    _validate_two_dimensional(*x, function_name="EllipticAbsoluteRoot")
    super().__init__(*x)

EllipticParaboloidFunction

Bases: OptFunction

Elliptic paraboloid function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class EllipticParaboloidFunction(OptFunction):
    r"""Elliptic paraboloid function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the elliptic paraboloid function."""
        _validate_two_dimensional(*x, function_name="EllipticParaboloid")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the elliptic paraboloid function at x."""
        x_1, x_2 = self._x
        return x_1**2 + 2 * x_2**2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the elliptic paraboloid function."""
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the elliptic paraboloid function at x.

__minima__ property

Return the minima of the elliptic paraboloid function.

__init__(*x)

Initialize the elliptic paraboloid function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the elliptic paraboloid function."""
    _validate_two_dimensional(*x, function_name="EllipticParaboloid")
    super().__init__(*x)

ExponentialNormFunction

Bases: OptFunction

Exponential norm function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class ExponentialNormFunction(OptFunction):
    r"""Exponential norm function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the exponential norm function."""
        _validate_three_or_higher(*x, function_name="ExponentialNorm")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the exponential norm function at x."""
        squared_norm = np.array(sum(axis**2 for axis in self._x))
        return np.exp(0.5 * squared_norm) - 1

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the exponential norm function."""
        return MinimaAPI(f_x=0.0, x=tuple(0.0 for _ in range(self.dimension)))

__eval__ property

Evaluate the exponential norm function at x.

__minima__ property

Return the minima of the exponential norm function.

__init__(*x)

Initialize the exponential norm function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the exponential norm function."""
    _validate_three_or_higher(*x, function_name="ExponentialNorm")
    super().__init__(*x)

OffsetQuadraticFunction

Bases: OptFunction

Offset quadratic function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class OffsetQuadraticFunction(OptFunction):
    r"""Offset quadratic function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the offset quadratic function."""
        _validate_two_dimensional(*x, function_name="OffsetQuadratic")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the offset quadratic function at x."""
        x_1, x_2 = self._x
        return (x_1 + 1) ** 2 + 3 * (x_2 - 2) ** 2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the offset quadratic function."""
        return MinimaAPI(f_x=0.0, x=(-1.0, 2.0))

__eval__ property

Evaluate the offset quadratic function at x.

__minima__ property

Return the minima of the offset quadratic function.

__init__(*x)

Initialize the offset quadratic function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the offset quadratic function."""
    _validate_two_dimensional(*x, function_name="OffsetQuadratic")
    super().__init__(*x)

PermBetaDFunction

Bases: OptFunction

Perm Beta D function.

The Perm Beta D function is a D-dimensional function with multimodal structure and sharp peaks.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.bowl_shaped import PermBetaDFunction
>>> x = np.linspace(-10, 10, 100)
>>> y = np.linspace(-10, 10, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = PermBetaDFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("PermBetaDFunction.png", dpi=300, transparent=True)
Notes

The Perm Beta D function is defined as:

\[ f(x) = \sum_{i=1}^D \left( \sum_{j=1}^D \frac{1}{j + \beta} \left( \frac{x_j}{j} \right)^i -1 \right)^2 \]

with constant \(\beta = 0.5\) and \(D\) the dimension of the input. The hypercube of the function is defined as \(x_i \in [-d, d]\) for all \(i\).

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class PermBetaDFunction(OptFunction):
    r"""Perm Beta D function.

    The Perm Beta D function is a D-dimensional function with multimodal structure
    and sharp peaks.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.bowl_shaped import PermBetaDFunction
        >>> x = np.linspace(-10, 10, 100)
        >>> y = np.linspace(-10, 10, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = PermBetaDFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("PermBetaDFunction.png", dpi=300, transparent=True)

    Notes:
        The Perm Beta D function is defined as:

        $$
            f(x) =  \sum_{i=1}^D \left( \sum_{j=1}^D \frac{1}{j +
            \beta} \left( \frac{x_j}{j} \right)^i  -1 \right)^2
        $$

        with constant $\beta = 0.5$ and $D$ the dimension of the input. The hypercube
        of the function is defined as $x_i \in [-d, d]$ for all $i$.

        > Reference: Original implementation can be found
        > [here](http://www.sfu.ca/~ssurjano/sumpow.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Perm Beta D function at x.

        Returns:
            UniversalArray: Evaluated function value.
        """
        beta = 0.5

        outer_sum = np.zeros(self._x[0].shape)

        for i in range(1, self.dimension + 1):
            inner_sum = sum(
                (j**i + beta) * ((self._x[j - 1] / j) ** i - 1)
                for j in range(1, self.dimension + 1)
            )
            outer_sum += inner_sum**2
        return outer_sum

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Perm Beta D function.

        Returns:
            MinimaAPI: Minima of the Perm Beta D function.
        """
        return MinimaAPI(f_x=0, x=tuple(np.arange(1, self.dimension + 1)))

__eval__ property

Evaluate Perm Beta D function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Evaluated function value.

__minima__ property

Return the minima of the Perm Beta D function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

Minima of the Perm Beta D function.

PermFunction

Bases: OptFunction

Perm function.

The Perm function is a D-dimensional function with multimodal structure and sharp peaks.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.bowl_shaped import PermFunction
>>> x = np.linspace(-1, 1, 100)
>>> y = np.linspace(-1, 1, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = PermFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("PermFunction.png", dpi=300, transparent=True)
Notes

The Perm function is defined as:

\[ f(x) = \sum_{i=1}^D \left( \sum_{j=1}^D j^{i+1} (j + \beta) \left( \frac{x_j}{j} \right)^i -1 \right)^2 \]

with constant \(\beta = 10\) and \(D\) the dimension of the input. The hypercube of the function is defined as \(x_i \in [-d, d]\) for all \(i\).

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
beta float

The beta parameter. Defaults to 10.

10
Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class PermFunction(OptFunction):
    r"""Perm function.

    The Perm function is a D-dimensional function with multimodal structure and
    sharp peaks.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.bowl_shaped import PermFunction
        >>> x = np.linspace(-1, 1, 100)
        >>> y = np.linspace(-1, 1, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = PermFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("PermFunction.png", dpi=300, transparent=True)

    Notes:
        The Perm function is defined as:

        $$
            f(x) = \sum_{i=1}^D \left( \sum_{j=1}^D j^{i+1} (j + \beta)
              \left( \frac{x_j}{j} \right)^i  -1 \right)^2
        $$

        with constant $\beta = 10$ and $D$ the dimension of the input. The hypercube
        of the function is defined as $x_i \in [-d, d]$ for all $i$.


    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
        beta (float, optional): The beta parameter. Defaults to 10.
    """

    def __init__(self, *x: UniversalArray, beta: float = 10) -> None:
        """Initialize the function."""
        super().__init__(*x)
        self.beta = beta

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Perm function at x.

        Returns:
            UniversalArray: Evaluated function value.
        """
        outer_sum = np.zeros(self._x[0].shape)

        for i in range(1, self.dimension + 1):
            inner_sum = sum(
                j ** (i + 1) * (j + self.beta) * ((self._x[j - 1] / j) ** i - 1)
                for j in range(1, self.dimension + 1)
            )
            outer_sum += inner_sum**2
        return outer_sum

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Perm function.

        Returns:
            MinimaAPI: Minima of the Perm function.
        """
        return MinimaAPI(f_x=0, x=tuple(np.arange(1, self.dimension + 1)))

__eval__ property

Evaluate Perm function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Evaluated function value.

__minima__ property

Return the minima of the Perm function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

Minima of the Perm function.

__init__(*x, beta=10)

Initialize the function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray, beta: float = 10) -> None:
    """Initialize the function."""
    super().__init__(*x)
    self.beta = beta

QuarticBowlFunction

Bases: OptFunction

Quartic bowl function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class QuarticBowlFunction(OptFunction):
    r"""Quartic bowl function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the quartic bowl function."""
        _validate_two_dimensional(*x, function_name="QuarticBowl")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the quartic bowl function at x."""
        x_1, x_2 = self._x
        return x_1**4 + x_2**4

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the quartic bowl function."""
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the quartic bowl function at x.

__minima__ property

Return the minima of the quartic bowl function.

__init__(*x)

Initialize the quartic bowl function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the quartic bowl function."""
    _validate_two_dimensional(*x, function_name="QuarticBowl")
    super().__init__(*x)

RippleBowlFunction

Bases: OptFunction

Ripple bowl function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class RippleBowlFunction(OptFunction):
    r"""Ripple bowl function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the ripple bowl function."""
        _validate_two_dimensional(*x, function_name="RippleBowl")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the ripple bowl function at x."""
        x_1, x_2 = self._x
        return x_1**2 + x_2**2 + 0.1 * np.sin(3 * x_1) ** 2 + 0.1 * np.sin(3 * x_2) ** 2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the ripple bowl function."""
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the ripple bowl function at x.

__minima__ property

Return the minima of the ripple bowl function.

__init__(*x)

Initialize the ripple bowl function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the ripple bowl function."""
    _validate_two_dimensional(*x, function_name="RippleBowl")
    super().__init__(*x)

RotatedHyperEllipseFunction

Bases: OptFunction

Rotated hyper-ellipse function.

The Rotated hyper-ellipse function is a D-dimensional function with multimodal structure and sharp peaks.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.bowl_shaped import (
... RotatedHyperEllipseFunction
... )
>>> x = np.linspace(-1, 1, 100)
>>> y = np.linspace(-1, 1, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = RotatedHyperEllipseFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("RotatedHyperEllipseFunction.png", dpi=300, transparent=True)
Notes

The Rotated hyper-ellipse function is defined as:

\[ f(x) = \sum_{i=1}^D \left( \sum_{j=1}^D a_{ij} x_j^2 \right)^2 \]

with \(D\) the dimension of the input and \(a_{ij}\) the rotation matrix. The hypercube of the function is defined as \(x_i \in [-d, d]\) for all \(i\).

Reference: Original implementation can be found here

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()

Raises:

Type Description
OutOfDimensionError

If the dimension of the input data is not 2.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class RotatedHyperEllipseFunction(OptFunction):
    r"""Rotated hyper-ellipse function.

    The Rotated hyper-ellipse function is a D-dimensional function with multimodal
    structure and sharp peaks.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.bowl_shaped import (
        ... RotatedHyperEllipseFunction
        ... )
        >>> x = np.linspace(-1, 1, 100)
        >>> y = np.linspace(-1, 1, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = RotatedHyperEllipseFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("RotatedHyperEllipseFunction.png", dpi=300, transparent=True)

    Notes:
        The Rotated hyper-ellipse function is defined as:

        $$
            f(x) = \sum_{i=1}^D \left( \sum_{j=1}^D a_{ij} x_j^2 \right)^2
        $$

        with $D$ the dimension of the input and $a_{ij}$ the rotation matrix. The
        hypercube of the function is defined as $x_i \in [-d, d]$ for all $i$.

        > Reference: Original implementation can be found
        > [here](http://www.sfu.ca/~ssurjano/rothyp.html)

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.

    Raises:
        OutOfDimensionError: If the dimension of the input data is not 2.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="RotatedHyperEllipse",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Rotated hyper-ellipse function at x.

        Returns:
            UniversalArray: Evaluated function value.
        """
        outer_sum = np.zeros(self._x[0].shape)
        for i in range(self.dimension):
            inner_sum = np.zeros(self._x[0].shape)
            for j in range(i + 1):
                inner_sum += self._x[j] ** 2
            outer_sum = outer_sum + inner_sum
        return outer_sum

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Rotated hyper-ellipse function.

        Returns:
            MinimaAPI: Minima of the Rotated hyper-ellipse function.
        """
        return MinimaAPI(f_x=0, x=tuple(np.zeros(self.dimension)))

__eval__ property

Evaluate Rotated hyper-ellipse function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Evaluated function value.

__minima__ property

Return the minima of the Rotated hyper-ellipse function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

Minima of the Rotated hyper-ellipse function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="RotatedHyperEllipse",
            dimension=__2d__,
        )
    super().__init__(*x)

RotatedQuadraticFunction

Bases: OptFunction

Rotated quadratic function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class RotatedQuadraticFunction(OptFunction):
    r"""Rotated quadratic function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the rotated quadratic function."""
        _validate_two_dimensional(*x, function_name="RotatedQuadratic")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the rotated quadratic function at x."""
        x_1, x_2 = self._x
        return x_1**2 + x_1 * x_2 + x_2**2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the rotated quadratic function."""
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the rotated quadratic function at x.

__minima__ property

Return the minima of the rotated quadratic function.

__init__(*x)

Initialize the rotated quadratic function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the rotated quadratic function."""
    _validate_two_dimensional(*x, function_name="RotatedQuadratic")
    super().__init__(*x)

SaddleSuppressedFunction

Bases: OptFunction

Saddle-suppressed function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class SaddleSuppressedFunction(OptFunction):
    r"""Saddle-suppressed function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the saddle-suppressed function."""
        _validate_two_dimensional(*x, function_name="SaddleSuppressed")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the saddle-suppressed function at x."""
        x_1, x_2 = self._x
        return (x_1**2 - x_2**2) ** 2 + 0.1 * (x_1**2 + x_2**2)

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the saddle-suppressed function."""
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the saddle-suppressed function at x.

__minima__ property

Return the minima of the saddle-suppressed function.

__init__(*x)

Initialize the saddle-suppressed function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the saddle-suppressed function."""
    _validate_two_dimensional(*x, function_name="SaddleSuppressed")
    super().__init__(*x)

ShiftedHyperSphereFunction

Bases: OptFunction

Shifted hypersphere function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class ShiftedHyperSphereFunction(OptFunction):
    r"""Shifted hypersphere function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the shifted hypersphere function."""
        _validate_three_or_higher(*x, function_name="ShiftedHyperSphere")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the shifted hypersphere function at x."""
        return np.array(sum((axis - 1) ** 2 for axis in self._x))

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the shifted hypersphere function."""
        return MinimaAPI(f_x=0.0, x=tuple(1.0 for _ in range(self.dimension)))

__eval__ property

Evaluate the shifted hypersphere function at x.

__minima__ property

Return the minima of the shifted hypersphere function.

__init__(*x)

Initialize the shifted hypersphere function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the shifted hypersphere function."""
    _validate_three_or_higher(*x, function_name="ShiftedHyperSphere")
    super().__init__(*x)

ShiftedSphere2DFunction

Bases: OptFunction

Shifted 2D sphere function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class ShiftedSphere2DFunction(OptFunction):
    r"""Shifted 2D sphere function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the shifted 2D sphere function."""
        _validate_two_dimensional(*x, function_name="ShiftedSphere2D")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the shifted 2D sphere function at x."""
        x_1, x_2 = self._x
        return (x_1 - 2) ** 2 + (x_2 + 1) ** 2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the shifted 2D sphere function."""
        return MinimaAPI(f_x=0.0, x=(2.0, -1.0))

__eval__ property

Evaluate the shifted 2D sphere function at x.

__minima__ property

Return the minima of the shifted 2D sphere function.

__init__(*x)

Initialize the shifted 2D sphere function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the shifted 2D sphere function."""
    _validate_two_dimensional(*x, function_name="ShiftedSphere2D")
    super().__init__(*x)

SphereFunction

Bases: OptFunction

Sphere function.

The Sphere function is a D-dimensional function with multimodal structure and sharp peaks.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.bowl_shaped import SphereFunction
>>> x = np.linspace(-2.5, 2.5, 100)
>>> y = np.linspace(-2.5, 2.5, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = SphereFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("SphereFunction.png", dpi=300, transparent=True)
Notes

The Sphere function is defined as:

\[ f(x) = \sum_{i=1}^D x_i^2 \]

with \(D\) the dimension of the input. The hypercube of the function is defined as \(x_i \in [-d, d]\) for all \(i\).

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class SphereFunction(OptFunction):
    r"""Sphere function.

    The Sphere function is a D-dimensional function with multimodal structure and
    sharp peaks.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.bowl_shaped import SphereFunction
        >>> x = np.linspace(-2.5, 2.5, 100)
        >>> y = np.linspace(-2.5, 2.5, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = SphereFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("SphereFunction.png", dpi=300, transparent=True)

    Notes:
        The Sphere function is defined as:

        $$
            f(x) = \sum_{i=1}^D x_i^2
        $$

        with $D$ the dimension of the input. The hypercube of the function is defined as
        $x_i \in [-d, d]$ for all $i$.

        Reference: Original implementation can be found
        [here](http://www.sfu.ca/~ssurjano/spheref.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Sphere function at x.

        Returns:
            UniversalArray: Evaluated function value.
        """
        return np.sum(np.power(self._x, 2), axis=0)

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Sphere function.

        Returns:
            MinimaAPI: Minima of the Sphere function.
        """
        return MinimaAPI(f_x=0, x=tuple(np.zeros(self.dimension)))

__eval__ property

Evaluate Sphere function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Evaluated function value.

__minima__ property

Return the minima of the Sphere function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

Minima of the Sphere function.

SumAndProductFunction

Bases: OptFunction

Sum-and-product function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class SumAndProductFunction(OptFunction):
    r"""Sum-and-product function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the sum-and-product function."""
        _validate_three_or_higher(*x, function_name="SumAndProduct")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the sum-and-product function at x."""
        sum_term = np.array(sum(np.abs(axis) for axis in self._x))
        product_term = np.ones_like(self._x[0])
        for axis in self._x:
            product_term *= np.abs(axis) + 1
        return sum_term + product_term - 1

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the sum-and-product function."""
        return MinimaAPI(f_x=0.0, x=tuple(0.0 for _ in range(self.dimension)))

__eval__ property

Evaluate the sum-and-product function at x.

__minima__ property

Return the minima of the sum-and-product function.

__init__(*x)

Initialize the sum-and-product function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the sum-and-product function."""
    _validate_three_or_higher(*x, function_name="SumAndProduct")
    super().__init__(*x)

SumOfDifferentPowersFunction

Bases: OptFunction

Sum of different powers function.

The Sum of different powers function is a D-dimensional function with multimodal structure and sharp peaks.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.bowl_shaped import (
... SumOfDifferentPowersFunction
... )
>>> x = np.linspace(-1, 1, 100)
>>> y = np.linspace(-1, 1, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = SumOfDifferentPowersFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("SumOfDifferentPowersFunction.png", dpi=300, transparent=True)
Notes

The Sum of different powers function is defined as:

\[ f(x) = \sum_{i=1}^D \left| x_i \right|^{i+1} \]

with \(D\) the dimension of the input. The hypercube of the function is defined as \(x_i \in [-d, d]\) for all \(i\).

_Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class SumOfDifferentPowersFunction(OptFunction):
    r"""Sum of different powers function.

    The Sum of different powers function is a D-dimensional function with multimodal
    structure and sharp peaks.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.bowl_shaped import (
        ... SumOfDifferentPowersFunction
        ... )
        >>> x = np.linspace(-1, 1, 100)
        >>> y = np.linspace(-1, 1, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = SumOfDifferentPowersFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("SumOfDifferentPowersFunction.png", dpi=300, transparent=True)

    Notes:
        The Sum of different powers function is defined as:

        $$
            f(x) = \sum_{i=1}^D \left| x_i \right|^{i+1}
        $$

        with $D$ the dimension of the input. The hypercube of the function is defined as
        $x_i \in [-d, d]$ for all $i$.

        _Reference: Original implementation can be found
        [here](http://www.sfu.ca/~ssurjano/sumpow.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Sum of different powers function at x.

        Returns:
            UniversalArray: Evaluated function value.
        """
        outer_sum = np.zeros(self._x[0].shape)

        for i in range(1, self.dimension + 1):
            inner_sum = abs(self._x[i - 1]) ** (i + 1)
            outer_sum += inner_sum
        return outer_sum

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Sum of different powers function.

        Returns:
            MinimaAPI: Minima of the Sum of different powers function.
        """
        return MinimaAPI(f_x=0, x=tuple(np.zeros(self.dimension)))

__eval__ property

Evaluate Sum of different powers function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Evaluated function value.

__minima__ property

Return the minima of the Sum of different powers function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

Minima of the Sum of different powers function.

SumSquaresFunction

Bases: OptFunction

Sum squares function.

The Sum squares function is a D-dimensional function with multimodal structure and sharp peaks.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.bowl_shaped import SumSquaresFunction
>>> x = np.linspace(-10, 10, 100)
>>> y = np.linspace(-10, 10, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = SumSquaresFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("SumSquaresFunction.png", dpi=300, transparent=True)
Notes

The Sum squares function is defined as:

\[ f(x) = \sum_{i=1}^D i x_i^2 \]

with \(D\) the dimension of the input. The hypercube of the function is defined as \(x_i \in [-d, d]\) for all \(i\).

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class SumSquaresFunction(OptFunction):
    r"""Sum squares function.

    The Sum squares function is a D-dimensional function with multimodal structure and
    sharp peaks.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.bowl_shaped import SumSquaresFunction
        >>> x = np.linspace(-10, 10, 100)
        >>> y = np.linspace(-10, 10, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = SumSquaresFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("SumSquaresFunction.png", dpi=300, transparent=True)

    Notes:
        The Sum squares function is defined as:

        $$
            f(x) = \sum_{i=1}^D i x_i^2
        $$

        with $D$ the dimension of the input. The hypercube of the function is defined as
        $x_i \in [-d, d]$ for all $i$.

        > Reference: Original implementation can be found
        > [here](http://www.sfu.ca/~ssurjano/sumsqu.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Sum squares function at x.

        Returns:
            UniversalArray: Evaluated function value.
        """
        outer_sum = np.zeros(self._x[0].shape)

        for i in range(1, self.dimension + 1):
            inner_sum = i * self._x[i - 1] ** 2
            outer_sum += inner_sum
        return outer_sum

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Sum squares function.

        Returns:
            MinimaAPI: Minima of the Sum squares function.
        """
        return MinimaAPI(f_x=0, x=tuple(np.zeros(self.dimension)))

__eval__ property

Evaluate Sum squares function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Evaluated function value.

__minima__ property

Return the minima of the Sum squares function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

Minima of the Sum squares function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    super().__init__(*x)

TridFunction

Bases: OptFunction

Trid function.

The Trid function is a D-dimensional function with multimodal structure and sharp peaks.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.bowl_shaped import TridFunction
>>> x = np.linspace(-10, 10, 100)
>>> y = np.linspace(-10, 10, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = TridFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("TridFunction.png", dpi=300, transparent=True)
Notes

The Trid function is defined as:

\[ f(x) = \sum_{i=1}^D \left( x_i - 1 \right)^2 - \sum_{i=2}^D x_i x_{i-1} \]

with \(D\) the dimension of the input. The hypercube of the function is defined as \(x_i \in [-d, d]\) for all \(i\).

Reference: Original implementation can be found here

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class TridFunction(OptFunction):
    r"""Trid function.

    The Trid function is a D-dimensional function with multimodal structure and sharp
    peaks.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.bowl_shaped import TridFunction
        >>> x = np.linspace(-10, 10, 100)
        >>> y = np.linspace(-10, 10, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = TridFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("TridFunction.png", dpi=300, transparent=True)

    Notes:
        The Trid function is defined as:

        $$
            f(x) = \sum_{i=1}^D \left( x_i - 1 \right)^2 - \sum_{i=2}^D x_i x_{i-1}
        $$

        with $D$ the dimension of the input. The hypercube of the function is defined
        as $x_i \in [-d, d]$ for all $i$.

        > Reference: Original implementation can be found
        > [here](http://www.sfu.ca/~ssurjano/trid.html)

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Trid function at x.

        Returns:
            UniversalArray: Evaluated function value.
        """
        outer_sum = np.zeros(self._x[0].shape)

        for i in range(1, self.dimension + 1):
            inner_sum = (self._x[i - 1] - 1) ** 2 - self._x[i - 1] * self._x[i - 2]
            outer_sum += inner_sum
        return outer_sum

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Trid function.

        Returns:
            MinimaAPI: Minima of the Trid function.
        """
        return MinimaAPI(
            f_x=-self.dimension * (self.dimension + 4) * (self.dimension - 1) / 6,
            x=tuple(i * (self.dimension + 1 - i) for i in range(1, self.dimension + 1)),
        )

__eval__ property

Evaluate Trid function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Evaluated function value.

__minima__ property

Return the minima of the Trid function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

Minima of the Trid function.

WeightedL1L2Function

Bases: OptFunction

Weighted mixed-norm function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class WeightedL1L2Function(OptFunction):
    r"""Weighted mixed-norm function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the weighted mixed-norm function."""
        _validate_two_dimensional(*x, function_name="WeightedL1L2")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the weighted mixed-norm function at x."""
        x_1, x_2 = self._x
        return x_1**2 + x_2**2 + np.abs(x_1 + x_2)

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the weighted mixed-norm function."""
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the weighted mixed-norm function at x.

__minima__ property

Return the minima of the weighted mixed-norm function.

__init__(*x)

Initialize the weighted mixed-norm function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the weighted mixed-norm function."""
    _validate_two_dimensional(*x, function_name="WeightedL1L2")
    super().__init__(*x)

ZirilliFunction

Bases: OptFunction

Zirilli function.

The Zirilli function is a 2D-dimensional function with multimodal structure and sharp peaks.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.bowl_shaped import ZirilliFunction
>>> x = np.linspace(-1, 1, 100)
>>> y = np.linspace(-1, 1, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = ZirilliFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("ZirilliFunction.png", dpi=300, transparent=True)
Notes

The Zirilli function is defined as:

\[ f(x) = 0.25 x_1^4 - 0.5 x_1^2 + 0.1 x_1 + 0.5 x_2^2 \]

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()

Raises:

Type Description
OutOfDimensionError

If the dimension of the input data is not 2.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class ZirilliFunction(OptFunction):
    r"""Zirilli function.

    The Zirilli function is a 2D-dimensional function with multimodal structure and
    sharp peaks.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.bowl_shaped import ZirilliFunction
        >>> x = np.linspace(-1, 1, 100)
        >>> y = np.linspace(-1, 1, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = ZirilliFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("ZirilliFunction.png", dpi=300, transparent=True)

    Notes:
        The Zirilli function is defined as:

        $$
            f(x) = 0.25 x_1^4 - 0.5 x_1^2 + 0.1 x_1 + 0.5 x_2^2
        $$


    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.

    Raises:
        OutOfDimensionError: If the dimension of the input data is not 2.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="Zirilli",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Zirilli function at x.

        Returns:
            UniversalArray: Evaluated function value.
        """
        x_1 = self._x[0]
        x_2 = self._x[1]
        return 0.25 * x_1**4 - 0.5 * x_1**2 + 0.1 * x_1 + 0.5 * x_2**2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Zirilli function.

        Returns:
            MinimaAPI: Minima of the Zirilli function.
        """
        return MinimaAPI(
            f_x=-0.352386073800034,
            x=(-1.046680576580755, 0),
        )

__eval__ property

Evaluate Zirilli function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Evaluated function value.

__minima__ property

Return the minima of the Zirilli function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

Minima of the Zirilli function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="Zirilli",
            dimension=__2d__,
        )
    super().__init__(*x)

Drop steps functions for the useful-math-functions library.

DeJongN5Function

Bases: OptFunction

De Jong N.5 Function.

The De Jong N.5 function is a two-dimensional function with a single global minimum.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.drops_steps import DeJongN5Function
>>> x = np.linspace(-65.536, 65.536, 1000)
>>> y = np.linspace(-65.536, 65.536, 1000)
>>> X, Y = np.meshgrid(x, y)
>>> Z = DeJongN5Function(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("DeJongN5Function.png", dpi=300, transparent=True)
Notes

The De Jong N.5 function is defined as:

\[ f(x, y) = \left( 0.0002 + \sum_{i=1}^{25} \frac{1}{ i + \left(x_1 - a_{1i} \right)^6 + \left(x_2 - a_{2i} \right)^6 } \right)^{-1} \]

where

\[ a = \left( \begin{matrix} -32 & -16 & 0 & 16 & 32 & ... & -16 & 0 & 16 & 32 \\ -32 & -32 & -32 & -32 & -32 & ... & 32 & 32 & 32 & 32 \end{matrix} \right) \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be one, two, three, or higher adddimensional.

()
A UniversalArray

Elements of the matrix a, which has to become are 2-dimensional with shape (2, 25). Defaults to None.

None
Source code in src/umf/functions/optimization/drops_steps.py
Python
class DeJongN5Function(OptFunction):
    r"""De Jong N.5 Function.

    The De Jong N.5 function is a two-dimensional function with a single global
    minimum.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.drops_steps import DeJongN5Function
        >>> x = np.linspace(-65.536, 65.536, 1000)
        >>> y = np.linspace(-65.536, 65.536, 1000)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = DeJongN5Function(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("DeJongN5Function.png", dpi=300, transparent=True)

    Notes:
        The De Jong N.5 function is defined as:

        $$
            f(x, y) = \left(
                0.0002 + \sum_{i=1}^{25}
                \frac{1}{
                    i + \left(x_1 - a_{1i} \right)^6 + \left(x_2 - a_{2i} \right)^6
                }
            \right)^{-1}
        $$

        where

        $$
            a = \left(
                \begin{matrix}
                -32 & -16 & 0   & 16  & 32  & ... & -16 & 0 & 16 & 32 \\
                -32 & -32 & -32 & -32 & -32 & ... & 32 & 32 & 32 & 32
                \end{matrix}
                \right)
        $$

        > Reference: Original implementation can be found
        > [here](http://www.sfu.ca/~ssurjano/dejong5.html).


    Args:
        *x (UniversalArray): Input data, which can be one, two, three, or higher
             adddimensional.
        A (UniversalArray, optional): Elements of the matrix a, which has to become are
            2-dimensional with shape (2, 25). Defaults to None.
    """

    def __init__(
        self,
        *x: UniversalArray,
        A: UniversalArray | None = None,
    ) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="De Jong N.5",
                dimension=__2d__,
            )
        super().__init__(*x)

        if A is None:
            row_1 = matlib.repmat(np.arange(-32, 33, 16), 1, 5)
            row_2 = matlib.repmat(np.arange(-32, 33, 16), 5, 1).T.ravel()
            self.a_matrix = np.vstack((row_1, row_2))
        elif A.shape != (2, 25):
            msg = "The shape of a has to be (2, 25)."
            raise ValueError(msg)
        else:
            self.a_matrix = A

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the De Jong N.5 function.

        Returns:
            UniversalArray: The value of the De Jong N.5 function.
        """
        x_1 = self._x[0]
        x_2 = self._x[1]

        a_1 = self.a_matrix[0, :]
        a_2 = self.a_matrix[1, :]

        sum_ = np.zeros_like(x_1)

        for i in range(25):
            sum_ += 1 / ((i + 1) + (x_1 - a_1[i]) ** 6 + (x_2 - a_2[i]) ** 6)

        return (0.0002 + sum_) ** -1

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the De Jong N.5 function.

        Returns:
            MinimaAPI: The minima of the De Jong N.5 function.
        """
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the De Jong N.5 function.

Returns:

Name Type Description
UniversalArray UniversalArray

The value of the De Jong N.5 function.

__minima__ property

Return the minima of the De Jong N.5 function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

The minima of the De Jong N.5 function.

__init__(*x, A=None)

Initialize the function.

Source code in src/umf/functions/optimization/drops_steps.py
Python
def __init__(
    self,
    *x: UniversalArray,
    A: UniversalArray | None = None,
) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="De Jong N.5",
            dimension=__2d__,
        )
    super().__init__(*x)

    if A is None:
        row_1 = matlib.repmat(np.arange(-32, 33, 16), 1, 5)
        row_2 = matlib.repmat(np.arange(-32, 33, 16), 5, 1).T.ravel()
        self.a_matrix = np.vstack((row_1, row_2))
    elif A.shape != (2, 25):
        msg = "The shape of a has to be (2, 25)."
        raise ValueError(msg)
    else:
        self.a_matrix = A

EasomFunction

Bases: OptFunction

Easom Function.

The Easom function is a two-dimensional function with a single global minimum.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.drops_steps import EasomFunction
>>> x = np.linspace(-100, 100, 1000)
>>> y = np.linspace(-100, 100, 1000)
>>> X, Y = np.meshgrid(x, y)
>>> Z = EasomFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("EasomFunction.png", dpi=300, transparent=True)
Notes

The Easom function is defined as:

\[ f(x, y) = -\cos(x)\cos(y)\exp\left(-\left(x-\pi\right)^2 - \left(y-\pi\right)^2\right) \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be one, two, three, or higher dimensional.

()
Source code in src/umf/functions/optimization/drops_steps.py
Python
class EasomFunction(OptFunction):
    r"""Easom Function.

    The Easom function is a two-dimensional function with a single global minimum.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.drops_steps import EasomFunction
        >>> x = np.linspace(-100, 100, 1000)
        >>> y = np.linspace(-100, 100, 1000)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = EasomFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("EasomFunction.png", dpi=300, transparent=True)

    Notes:
        The Easom function is defined as:

        $$
            f(x, y) = -\cos(x)\cos(y)\exp\left(-\left(x-\pi\right)^2
            - \left(y-\pi\right)^2\right)
        $$

        > Reference: Original implementation can be found
        > [here](http://www.sfu.ca/~ssurjano/easom.html).

    Args:
        *x (UniversalArray): Input data, which can be one, two, three, or higher
             dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="Easom",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the Easom function.

        Returns:
            UniversalArray: The value of the Easom function.
        """
        x_1 = self._x[0]
        x_2 = self._x[1]

        return np.array(
            -np.cos(x_1)
            * np.cos(x_2)
            * np.exp(-((x_1 - np.pi) ** 2) - (x_2 - np.pi) ** 2),
        )

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Easom function.

        Returns:
            MinimaAPI: The minima of the Easom function.
        """
        return MinimaAPI(
            f_x=-1.0,
            x=np.array([np.pi, np.pi]),
        )

__eval__ property

Evaluate the Easom function.

Returns:

Name Type Description
UniversalArray UniversalArray

The value of the Easom function.

__minima__ property

Return the minima of the Easom function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

The minima of the Easom function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/drops_steps.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="Easom",
            dimension=__2d__,
        )
    super().__init__(*x)

MichalewiczFunction

Bases: OptFunction

Michalewicz Function.

The Michalewicz function is a multi-dimensional function with a single global minimum.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.drops_steps import MichalewiczFunction
>>> x = np.linspace(0, np.pi, 1000)
>>> y = np.linspace(0, np.pi, 1000)
>>> X, Y = np.meshgrid(x, y)
>>> Z = MichalewiczFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("MichalewiczFunction.png", dpi=300, transparent=True)
Notes

The Michalewicz function is defined as:

\[ f(x, y) = -\sum_{i=1}^{2}\sin(x_i)\sin^2\left(\frac{i x_i^2}{\pi}\right) \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be one, two, three, or higher dimensional.

()
m int

The m parameter. Defaults to 10.

10
Source code in src/umf/functions/optimization/drops_steps.py
Python
class MichalewiczFunction(OptFunction):
    r"""Michalewicz Function.

    The Michalewicz function is a multi-dimensional function with a single
    global minimum.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.drops_steps import MichalewiczFunction
        >>> x = np.linspace(0, np.pi, 1000)
        >>> y = np.linspace(0, np.pi, 1000)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = MichalewiczFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("MichalewiczFunction.png", dpi=300, transparent=True)

    Notes:
        The Michalewicz function is defined as:

        $$
            f(x, y) = -\sum_{i=1}^{2}\sin(x_i)\sin^2\left(\frac{i x_i^2}{\pi}\right)
        $$

        > Reference: Original implementation can be found
        > [here](http://www.sfu.ca/~ssurjano/michal.html).

    Args:
        *x (UniversalArray): Input data, which can be one, two, three, or higher
             dimensional.
        m (int, optional): The m parameter. Defaults to 10.
    """

    def __init__(self, *x: UniversalArray, m: int = 10) -> None:
        """Initialize the function."""
        super().__init__(*x)

        self.m = m

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the Michalewicz function.

        Returns:
            UniversalArray: The value of the Michalewicz function.
        """
        sum_ = np.zeros_like(self._x[0])

        for i, x_i in enumerate(self._x, start=1):
            sum_ += np.sin(x_i) * np.sin((i * x_i**2) / np.pi) ** (2 * self.m)

        return -sum_

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Michalewicz function.

         The minima of the Michalewicz function is not unique and depends on the
            m parameter and dimensionality of the function.

        Returns:
            MinimaAPI: The minima of the Michalewicz function.
        """
        return MinimaAPI(
            f_x=-1.8013,
            x=(2.20, 1.57),
        )

__eval__ property

Evaluate the Michalewicz function.

Returns:

Name Type Description
UniversalArray UniversalArray

The value of the Michalewicz function.

__minima__ property

Return the minima of the Michalewicz function.

The minima of the Michalewicz function is not unique and depends on the m parameter and dimensionality of the function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

The minima of the Michalewicz function.

__init__(*x, m=10)

Initialize the function.

Source code in src/umf/functions/optimization/drops_steps.py
Python
def __init__(self, *x: UniversalArray, m: int = 10) -> None:
    """Initialize the function."""
    super().__init__(*x)

    self.m = m

One-dimensional line-shaped benchmark functions.

This module provides scalar one-dimensional optimization objectives of the form \(f(x)\), designed for testing gradient-based optimizers, autodiff pipelines, and least-squares style solvers.

AbsoluteLineFunction

Bases: OptFunction

Absolute-value line benchmark.

Notes
\[ f(x) = |x| \]
Source code in src/umf/functions/optimization/line_shaped.py
Python
class AbsoluteLineFunction(OptFunction):
    r"""Absolute-value line benchmark.

    Notes:
        $$
        f(x) = |x|
        $$
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the absolute line function."""
        _validate_one_dimensional(*x, function_name="AbsoluteLine")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the absolute line function."""
        x_1 = self._x[0]
        return np.abs(x_1)

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the global minimum."""
        return MinimaAPI(f_x=0.0, x=(0.0,))

__eval__ property

Evaluate the absolute line function.

__minima__ property

Return the global minimum.

__init__(*x)

Initialize the absolute line function.

Source code in src/umf/functions/optimization/line_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the absolute line function."""
    _validate_one_dimensional(*x, function_name="AbsoluteLine")
    super().__init__(*x)

ArctanSquareLineFunction

Bases: OptFunction

Arctangent-square line benchmark.

Notes
\[ f(x) = \arctan^2(x) \]
Source code in src/umf/functions/optimization/line_shaped.py
Python
class ArctanSquareLineFunction(OptFunction):
    r"""Arctangent-square line benchmark.

    Notes:
        $$
        f(x) = \arctan^2(x)
        $$
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the arctangent-square line function."""
        _validate_one_dimensional(*x, function_name="ArctanSquareLine")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the arctangent-square line function."""
        x_1 = self._x[0]
        return np.arctan(x_1) ** 2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the global minimum."""
        return MinimaAPI(f_x=0.0, x=(0.0,))

__eval__ property

Evaluate the arctangent-square line function.

__minima__ property

Return the global minimum.

__init__(*x)

Initialize the arctangent-square line function.

Source code in src/umf/functions/optimization/line_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the arctangent-square line function."""
    _validate_one_dimensional(*x, function_name="ArctanSquareLine")
    super().__init__(*x)

CauchyLossLineFunction

Bases: OptFunction

Cauchy-loss line benchmark.

Notes
\[ f(x) = \log(1 + x^2) \]
Source code in src/umf/functions/optimization/line_shaped.py
Python
class CauchyLossLineFunction(OptFunction):
    r"""Cauchy-loss line benchmark.

    Notes:
        $$
        f(x) = \log(1 + x^2)
        $$
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the Cauchy-loss line function."""
        _validate_one_dimensional(*x, function_name="CauchyLossLine")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the Cauchy-loss line function."""
        x_1 = self._x[0]
        return np.log1p(x_1**2)

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the global minimum."""
        return MinimaAPI(f_x=0.0, x=(0.0,))

__eval__ property

Evaluate the Cauchy-loss line function.

__minima__ property

Return the global minimum.

__init__(*x)

Initialize the Cauchy-loss line function.

Source code in src/umf/functions/optimization/line_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the Cauchy-loss line function."""
    _validate_one_dimensional(*x, function_name="CauchyLossLine")
    super().__init__(*x)

CosineBowlLineFunction

Bases: OptFunction

Cosine bowl line benchmark.

Notes
\[ f(x) = 1 - \cos(x) \]
Source code in src/umf/functions/optimization/line_shaped.py
Python
class CosineBowlLineFunction(OptFunction):
    r"""Cosine bowl line benchmark.

    Notes:
        $$
        f(x) = 1 - \cos(x)
        $$
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the cosine bowl line function."""
        _validate_one_dimensional(*x, function_name="CosineBowlLine")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the cosine bowl line function."""
        x_1 = self._x[0]
        return 1.0 - np.cos(x_1)

    @property
    def __minima__(self) -> MinimaAPI:
        """Return one global minimum."""
        return MinimaAPI(f_x=0.0, x=(0.0,))

__eval__ property

Evaluate the cosine bowl line function.

__minima__ property

Return one global minimum.

__init__(*x)

Initialize the cosine bowl line function.

Source code in src/umf/functions/optimization/line_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the cosine bowl line function."""
    _validate_one_dimensional(*x, function_name="CosineBowlLine")
    super().__init__(*x)

DampedOscillationLineFunction

Bases: OptFunction

Damped oscillation line benchmark.

Notes
\[ f(x) = \sin^2(3x) + 0.01x^2 \]
Source code in src/umf/functions/optimization/line_shaped.py
Python
class DampedOscillationLineFunction(OptFunction):
    r"""Damped oscillation line benchmark.

    Notes:
        $$
        f(x) = \sin^2(3x) + 0.01x^2
        $$
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the damped oscillation line function."""
        _validate_one_dimensional(*x, function_name="DampedOscillationLine")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the damped oscillation line function."""
        x_1 = self._x[0]
        return np.sin(3.0 * x_1) ** 2 + 0.01 * x_1**2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the global minimum."""
        return MinimaAPI(f_x=0.0, x=(0.0,))

__eval__ property

Evaluate the damped oscillation line function.

__minima__ property

Return the global minimum.

__init__(*x)

Initialize the damped oscillation line function.

Source code in src/umf/functions/optimization/line_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the damped oscillation line function."""
    _validate_one_dimensional(*x, function_name="DampedOscillationLine")
    super().__init__(*x)

DoubleWellLineFunction

Bases: OptFunction

Double-well line benchmark.

Notes
\[ f(x) = (x^2 - 1)^2 \]
Source code in src/umf/functions/optimization/line_shaped.py
Python
class DoubleWellLineFunction(OptFunction):
    r"""Double-well line benchmark.

    Notes:
        $$
        f(x) = (x^2 - 1)^2
        $$
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the double-well line function."""
        _validate_one_dimensional(*x, function_name="DoubleWellLine")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the double-well line function."""
        x_1 = self._x[0]
        return (x_1**2 - 1.0) ** 2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return representative global minima."""
        return MinimaAPI(f_x=0.0, x=(-1.0, 1.0))

__eval__ property

Evaluate the double-well line function.

__minima__ property

Return representative global minima.

__init__(*x)

Initialize the double-well line function.

Source code in src/umf/functions/optimization/line_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the double-well line function."""
    _validate_one_dimensional(*x, function_name="DoubleWellLine")
    super().__init__(*x)

ElasticNetLineFunction

Bases: OptFunction

Elastic-net style line benchmark.

Notes
\[ f(x) = |x| + 0.5x^2 \]
Source code in src/umf/functions/optimization/line_shaped.py
Python
class ElasticNetLineFunction(OptFunction):
    r"""Elastic-net style line benchmark.

    Notes:
        $$
        f(x) = |x| + 0.5x^2
        $$
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the elastic-net line function."""
        _validate_one_dimensional(*x, function_name="ElasticNetLine")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the elastic-net line function."""
        x_1 = self._x[0]
        return np.abs(x_1) + 0.5 * x_1**2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the global minimum."""
        return MinimaAPI(f_x=0.0, x=(0.0,))

__eval__ property

Evaluate the elastic-net line function.

__minima__ property

Return the global minimum.

__init__(*x)

Initialize the elastic-net line function.

Source code in src/umf/functions/optimization/line_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the elastic-net line function."""
    _validate_one_dimensional(*x, function_name="ElasticNetLine")
    super().__init__(*x)

ExponentialSquareLineFunction

Bases: OptFunction

Exponential square line benchmark.

Notes
\[ f(x) = e^{x^2} - 1 \]
Source code in src/umf/functions/optimization/line_shaped.py
Python
class ExponentialSquareLineFunction(OptFunction):
    r"""Exponential square line benchmark.

    Notes:
        $$
        f(x) = e^{x^2} - 1
        $$
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the exponential square line function."""
        _validate_one_dimensional(*x, function_name="ExponentialSquareLine")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the exponential square line function."""
        x_1 = self._x[0]
        return np.exp(x_1**2) - 1.0

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the global minimum."""
        return MinimaAPI(f_x=0.0, x=(0.0,))

__eval__ property

Evaluate the exponential square line function.

__minima__ property

Return the global minimum.

__init__(*x)

Initialize the exponential square line function.

Source code in src/umf/functions/optimization/line_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the exponential square line function."""
    _validate_one_dimensional(*x, function_name="ExponentialSquareLine")
    super().__init__(*x)

GaussianValleyLineFunction

Bases: OptFunction

Gaussian valley line benchmark.

Notes
\[ f(x) = 1 - \exp\left(-(x - 1)^2\right) \]
Source code in src/umf/functions/optimization/line_shaped.py
Python
class GaussianValleyLineFunction(OptFunction):
    r"""Gaussian valley line benchmark.

    Notes:
        $$
        f(x) = 1 - \exp\left(-(x - 1)^2\right)
        $$
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the gaussian valley line function."""
        _validate_one_dimensional(*x, function_name="GaussianValleyLine")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the gaussian valley line function."""
        x_1 = self._x[0]
        return 1.0 - np.exp(-((x_1 - 1.0) ** 2))

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the global minimum."""
        return MinimaAPI(f_x=0.0, x=(1.0,))

__eval__ property

Evaluate the gaussian valley line function.

__minima__ property

Return the global minimum.

__init__(*x)

Initialize the gaussian valley line function.

Source code in src/umf/functions/optimization/line_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the gaussian valley line function."""
    _validate_one_dimensional(*x, function_name="GaussianValleyLine")
    super().__init__(*x)

IdentitySquareLineFunction

Bases: OptFunction

Identity-square line benchmark.

Notes
\[ f(x) = x^2 \]

Parameters:

Name Type Description Default
*x UniversalArray

Input data with one dimension.

()

Raises:

Type Description
OutOfDimensionError

If input is not one-dimensional.

Source code in src/umf/functions/optimization/line_shaped.py
Python
class IdentitySquareLineFunction(OptFunction):
    r"""Identity-square line benchmark.

    Notes:
        $$
        f(x) = x^2
        $$

    Args:
        *x: Input data with one dimension.

    Raises:
        OutOfDimensionError: If input is not one-dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the identity-square line function."""
        _validate_one_dimensional(*x, function_name="IdentitySquareLine")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the identity-square line function."""
        x_1 = self._x[0]
        return x_1**2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the global minimum."""
        return MinimaAPI(f_x=0.0, x=(0.0,))

__eval__ property

Evaluate the identity-square line function.

__minima__ property

Return the global minimum.

__init__(*x)

Initialize the identity-square line function.

Source code in src/umf/functions/optimization/line_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the identity-square line function."""
    _validate_one_dimensional(*x, function_name="IdentitySquareLine")
    super().__init__(*x)

LogCoshLineFunction

Bases: OptFunction

Log-cosh line benchmark.

Notes
\[ f(x) = \log(\cosh(x)) \]
Source code in src/umf/functions/optimization/line_shaped.py
Python
class LogCoshLineFunction(OptFunction):
    r"""Log-cosh line benchmark.

    Notes:
        $$
        f(x) = \log(\cosh(x))
        $$
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the log-cosh line function."""
        _validate_one_dimensional(*x, function_name="LogCoshLine")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the log-cosh line function."""
        x_1 = self._x[0]
        return np.log(np.cosh(x_1))

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the global minimum."""
        return MinimaAPI(f_x=0.0, x=(0.0,))

__eval__ property

Evaluate the log-cosh line function.

__minima__ property

Return the global minimum.

__init__(*x)

Initialize the log-cosh line function.

Source code in src/umf/functions/optimization/line_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the log-cosh line function."""
    _validate_one_dimensional(*x, function_name="LogCoshLine")
    super().__init__(*x)

QuarticLineFunction

Bases: OptFunction

Quartic line benchmark.

Notes
\[ f(x) = x^4 \]
Source code in src/umf/functions/optimization/line_shaped.py
Python
class QuarticLineFunction(OptFunction):
    r"""Quartic line benchmark.

    Notes:
        $$
        f(x) = x^4
        $$
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the quartic line function."""
        _validate_one_dimensional(*x, function_name="QuarticLine")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the quartic line function."""
        x_1 = self._x[0]
        return x_1**4

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the global minimum."""
        return MinimaAPI(f_x=0.0, x=(0.0,))

__eval__ property

Evaluate the quartic line function.

__minima__ property

Return the global minimum.

__init__(*x)

Initialize the quartic line function.

Source code in src/umf/functions/optimization/line_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the quartic line function."""
    _validate_one_dimensional(*x, function_name="QuarticLine")
    super().__init__(*x)

RationalBowlLineFunction

Bases: OptFunction

Rational bowl line benchmark.

Notes
\[ f(x) = \frac{x^2}{1 + x^2} \]
Source code in src/umf/functions/optimization/line_shaped.py
Python
class RationalBowlLineFunction(OptFunction):
    r"""Rational bowl line benchmark.

    Notes:
        $$
        f(x) = \frac{x^2}{1 + x^2}
        $$
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the rational bowl line function."""
        _validate_one_dimensional(*x, function_name="RationalBowlLine")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the rational bowl line function."""
        x_1 = self._x[0]
        return x_1**2 / (1.0 + x_1**2)

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the global minimum."""
        return MinimaAPI(f_x=0.0, x=(0.0,))

__eval__ property

Evaluate the rational bowl line function.

__minima__ property

Return the global minimum.

__init__(*x)

Initialize the rational bowl line function.

Source code in src/umf/functions/optimization/line_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the rational bowl line function."""
    _validate_one_dimensional(*x, function_name="RationalBowlLine")
    super().__init__(*x)

SexticLineFunction

Bases: OptFunction

Sextic line benchmark.

Notes
\[ f(x) = x^6 \]
Source code in src/umf/functions/optimization/line_shaped.py
Python
class SexticLineFunction(OptFunction):
    r"""Sextic line benchmark.

    Notes:
        $$
        f(x) = x^6
        $$
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the sextic line function."""
        _validate_one_dimensional(*x, function_name="SexticLine")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the sextic line function."""
        x_1 = self._x[0]
        return x_1**6

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the global minimum."""
        return MinimaAPI(f_x=0.0, x=(0.0,))

__eval__ property

Evaluate the sextic line function.

__minima__ property

Return the global minimum.

__init__(*x)

Initialize the sextic line function.

Source code in src/umf/functions/optimization/line_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the sextic line function."""
    _validate_one_dimensional(*x, function_name="SexticLine")
    super().__init__(*x)

ShiftedElasticLineFunction

Bases: OptFunction

Shifted elastic line benchmark.

Notes
\[ f(x) = |x - 2| + 0.25(x - 2)^2 \]
Source code in src/umf/functions/optimization/line_shaped.py
Python
class ShiftedElasticLineFunction(OptFunction):
    r"""Shifted elastic line benchmark.

    Notes:
        $$
        f(x) = |x - 2| + 0.25(x - 2)^2
        $$
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the shifted elastic line function."""
        _validate_one_dimensional(*x, function_name="ShiftedElasticLine")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the shifted elastic line function."""
        x_1 = self._x[0]
        return np.abs(x_1 - 2.0) + 0.25 * (x_1 - 2.0) ** 2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the global minimum."""
        return MinimaAPI(f_x=0.0, x=(2.0,))

__eval__ property

Evaluate the shifted elastic line function.

__minima__ property

Return the global minimum.

__init__(*x)

Initialize the shifted elastic line function.

Source code in src/umf/functions/optimization/line_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the shifted elastic line function."""
    _validate_one_dimensional(*x, function_name="ShiftedElasticLine")
    super().__init__(*x)

ShiftedIdentitySquareLineFunction

Bases: OptFunction

Shifted identity-square line benchmark.

Notes
\[ f(x) = (x - 1)^2 \]
Source code in src/umf/functions/optimization/line_shaped.py
Python
class ShiftedIdentitySquareLineFunction(OptFunction):
    r"""Shifted identity-square line benchmark.

    Notes:
        $$
        f(x) = (x - 1)^2
        $$
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the shifted identity-square line function."""
        _validate_one_dimensional(*x, function_name="ShiftedIdentitySquareLine")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the shifted identity-square line function."""
        x_1 = self._x[0]
        return (x_1 - 1.0) ** 2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the global minimum."""
        return MinimaAPI(f_x=0.0, x=(1.0,))

__eval__ property

Evaluate the shifted identity-square line function.

__minima__ property

Return the global minimum.

__init__(*x)

Initialize the shifted identity-square line function.

Source code in src/umf/functions/optimization/line_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the shifted identity-square line function."""
    _validate_one_dimensional(*x, function_name="ShiftedIdentitySquareLine")
    super().__init__(*x)

SincSquareLineFunction

Bases: OptFunction

Sinc-square line benchmark.

Notes
\[ f(x) = 1 - \operatorname{sinc}(x/\pi) \]
Source code in src/umf/functions/optimization/line_shaped.py
Python
class SincSquareLineFunction(OptFunction):
    r"""Sinc-square line benchmark.

    Notes:
        $$
        f(x) = 1 - \operatorname{sinc}(x/\pi)
        $$
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the sinc-square line function."""
        _validate_one_dimensional(*x, function_name="SincSquareLine")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the sinc-square line function."""
        x_1 = self._x[0]
        return 1.0 - np.sinc(x_1 / np.pi)

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the global minimum."""
        return MinimaAPI(f_x=0.0, x=(0.0,))

__eval__ property

Evaluate the sinc-square line function.

__minima__ property

Return the global minimum.

__init__(*x)

Initialize the sinc-square line function.

Source code in src/umf/functions/optimization/line_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the sinc-square line function."""
    _validate_one_dimensional(*x, function_name="SincSquareLine")
    super().__init__(*x)

SineSquaredLineFunction

Bases: OptFunction

Sine-squared line benchmark.

Notes
\[ f(x) = \sin^2(x) \]
Source code in src/umf/functions/optimization/line_shaped.py
Python
class SineSquaredLineFunction(OptFunction):
    r"""Sine-squared line benchmark.

    Notes:
        $$
        f(x) = \sin^2(x)
        $$
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the sine-squared line function."""
        _validate_one_dimensional(*x, function_name="SineSquaredLine")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the sine-squared line function."""
        x_1 = self._x[0]
        return np.sin(x_1) ** 2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return one global minimum."""
        return MinimaAPI(f_x=0.0, x=(0.0,))

__eval__ property

Evaluate the sine-squared line function.

__minima__ property

Return one global minimum.

__init__(*x)

Initialize the sine-squared line function.

Source code in src/umf/functions/optimization/line_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the sine-squared line function."""
    _validate_one_dimensional(*x, function_name="SineSquaredLine")
    super().__init__(*x)

SoftplusSymmetricLineFunction

Bases: OptFunction

Symmetric softplus line benchmark.

Notes
\[ f(x) = \log(1 + e^x) + \log(1 + e^{-x}) - 2\log(2) \]
Source code in src/umf/functions/optimization/line_shaped.py
Python
class SoftplusSymmetricLineFunction(OptFunction):
    r"""Symmetric softplus line benchmark.

    Notes:
        $$
        f(x) = \log(1 + e^x) + \log(1 + e^{-x}) - 2\log(2)
        $$
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the symmetric softplus line function."""
        _validate_one_dimensional(*x, function_name="SoftplusSymmetricLine")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the symmetric softplus line function."""
        x_1 = self._x[0]
        return np.logaddexp(0.0, x_1) + np.logaddexp(0.0, -x_1) - 2.0 * np.log(2.0)

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the global minimum."""
        return MinimaAPI(f_x=0.0, x=(0.0,))

__eval__ property

Evaluate the symmetric softplus line function.

__minima__ property

Return the global minimum.

__init__(*x)

Initialize the symmetric softplus line function.

Source code in src/umf/functions/optimization/line_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the symmetric softplus line function."""
    _validate_one_dimensional(*x, function_name="SoftplusSymmetricLine")
    super().__init__(*x)

TiltedParabolaRippleLineFunction

Bases: OptFunction

Tilted parabola-ripple line benchmark.

Notes
\[ f(x) = (x - 0.5)^2 + 0.05\left(1 - \cos\left(6(x - 0.5)\right)\right) \]
Source code in src/umf/functions/optimization/line_shaped.py
Python
class TiltedParabolaRippleLineFunction(OptFunction):
    r"""Tilted parabola-ripple line benchmark.

    Notes:
        $$
        f(x) = (x - 0.5)^2 + 0.05\left(1 - \cos\left(6(x - 0.5)\right)\right)
        $$
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the tilted parabola-ripple line function."""
        _validate_one_dimensional(*x, function_name="TiltedParabolaRippleLine")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the tilted parabola-ripple line function."""
        x_1 = self._x[0]
        shifted = x_1 - 0.5
        return shifted**2 + 0.05 * (1.0 - np.cos(6.0 * shifted))

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the global minimum."""
        return MinimaAPI(f_x=0.0, x=(0.5,))

__eval__ property

Evaluate the tilted parabola-ripple line function.

__minima__ property

Return the global minimum.

__init__(*x)

Initialize the tilted parabola-ripple line function.

Source code in src/umf/functions/optimization/line_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the tilted parabola-ripple line function."""
    _validate_one_dimensional(*x, function_name="TiltedParabolaRippleLine")
    super().__init__(*x)

Many local minima functions for the useful-math-functions library.

AckleyFunction

Bases: OptFunction

Ackley function.

The Ackley function is a multi-dimensional function with many local minima.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.many_local_minima import AckleyFunction
>>> x = np.linspace(-50, 50, 1000)
>>> y = np.linspace(-50, 50, 1000)
>>> X, Y = np.meshgrid(x, y)
>>> Z = AckleyFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("AckleyFunction.png", dpi=300, transparent=True)
Notes

The Ackley function is defined as:

\[ f(x) = -\alpha \exp \left( -\beta \sqrt{\frac{1}{n} \sum_{i=1}^n x_i^2} \right) - \exp \left( \frac{1}{n} \sum_{i=1}^n \cos(\gamma x_i) \right) + e + \alpha \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which can be one, two, three, or higher dimensional.

()
alpha float

Scaling factor. Default is 20.0.

20.0
beta float

Scaling factor. Default is 0.2.

0.2
gamma float

Scaling factor. Default is 2.0 * np.pi.

2.0 * pi
Source code in src/umf/functions/optimization/many_local_minima.py
Python
class AckleyFunction(OptFunction):
    r"""Ackley function.

    The Ackley function is a multi-dimensional function with many local minima.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.many_local_minima import AckleyFunction
        >>> x = np.linspace(-50, 50, 1000)
        >>> y = np.linspace(-50, 50, 1000)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = AckleyFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("AckleyFunction.png", dpi=300, transparent=True)

    Notes:
        The Ackley function is defined as:

        $$
            f(x) = -\alpha \exp \left( -\beta \sqrt{\frac{1}{n} \sum_{i=1}^n x_i^2}
              \right) - \exp \left( \frac{1}{n} \sum_{i=1}^n \cos(\gamma x_i)
              \right) + e + \alpha
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/ackley.html).

    Args:
        *x (UniversalArray): Input data, which can be one, two, three, or higher
             dimensional.
        alpha (float): Scaling factor. Default is 20.0.
        beta (float): Scaling factor. Default is 0.2.
        gamma (float): Scaling factor. Default is 2.0 * np.pi.
    """

    def __init__(
        self,
        *x: UniversalArray,
        alpha: float = 20.0,
        beta: float = 0.2,
        gamma: float = 2.0 * np.pi,
    ) -> None:
        """Initialize the function."""
        super().__init__(*x)
        self._alpha = alpha
        self._beta = beta
        self._gamma = gamma

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Ackley function at x.

        Returns:
            UniversalArray: Function values as numpy arrays.
        """
        sum_1 = np.zeros_like(self._x[0])
        sum_2 = np.zeros_like(self._x[0])

        for _i, _x in enumerate(self._x, start=1):
            # Calculate sum of squares of x values
            sum_1 += _x**2
            # Calculate sum of cosines of x values
            sum_2 += np.cos(self._gamma * _x)

        # Calculate exponential terms
        terms_1 = -self._alpha * np.exp(-self._beta * np.sqrt(1 / _i * sum_1))
        terms_2 = -np.exp(1 / _i * sum_2)

        # Calculate Ackley function value
        terms_3 = np.e + self._alpha
        return terms_1 + terms_2 + terms_3

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Ackley function."""
        return MinimaAPI(f_x=0.0, x=tuple(np.zeros_like(self._x[0])))

__eval__ property

Evaluate Ackley function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Function values as numpy arrays.

__minima__ property

Return the minima of the Ackley function.

__init__(*x, alpha=20.0, beta=0.2, gamma=2.0 * np.pi)

Initialize the function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
def __init__(
    self,
    *x: UniversalArray,
    alpha: float = 20.0,
    beta: float = 0.2,
    gamma: float = 2.0 * np.pi,
) -> None:
    """Initialize the function."""
    super().__init__(*x)
    self._alpha = alpha
    self._beta = beta
    self._gamma = gamma

BukinN6Function

Bases: OptFunction

Bukin function number 6.

The Bukin function number 6 is a two-dimensional function with many local minima.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.many_local_minima import BukinN6Function
>>> x = np.linspace(-15, 5, 1000)
>>> y = np.linspace(-3, 3, 1000)
>>> X, Y = np.meshgrid(x, y)
>>> Z = BukinN6Function(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("BukinN6Function.png", dpi=300, transparent=True)
Notes

The Bukin function number 6 is defined as:

\[ f(x) = 100 \sqrt{\left| y - 0.01 x^2 \right|} + 0.01 \left| x + 10 \right| \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/many_local_minima.py
Python
class BukinN6Function(OptFunction):
    r"""Bukin function number 6.

    The Bukin function number 6 is a two-dimensional function with many local minima.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.many_local_minima import BukinN6Function
        >>> x = np.linspace(-15, 5, 1000)
        >>> y = np.linspace(-3, 3, 1000)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = BukinN6Function(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("BukinN6Function.png", dpi=300, transparent=True)

    Notes:
        The Bukin function number 6 is defined as:

        $$
            f(x) = 100 \sqrt{\left| y - 0.01 x^2 \right|} +
            0.01 \left| x + 10 \right|
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/bukin6.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="Bukin",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Bukin function at x.

        Returns:
            UniversalArray: Function values as numpy arrays.
        """
        x_1 = self._x[0]
        x_2 = self._x[1]

        term_1 = 100 * np.sqrt(np.abs(x_2 - 0.01 * x_1**2))
        term_2 = 0.01 * np.abs(x_1 + 10)

        return term_1 + term_2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the function.

        Returns:
            MinimaAPI: MinimaAPI object containing the minima of the function.
        """
        return MinimaAPI(
            f_x=0.0,
            x=(-10.0, 1.0),
        )

__eval__ property

Evaluate Bukin function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Function values as numpy arrays.

__minima__ property

Return the minima of the function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

MinimaAPI object containing the minima of the function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="Bukin",
            dimension=__2d__,
        )
    super().__init__(*x)

CosineMixtureFunction

Bases: OptFunction

Cosine mixture function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
class CosineMixtureFunction(OptFunction):
    r"""Cosine mixture function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the cosine mixture function."""
        _validate_two_dimensional(*x, function_name="CosineMixture")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the cosine mixture function at x."""
        x_1, x_2 = self._x
        return 0.1 * (x_1**2 + x_2**2) + (1 - np.cos(x_1)) + (1 - np.cos(x_2))

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the cosine mixture function."""
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the cosine mixture function at x.

__minima__ property

Return the minima of the cosine mixture function.

__init__(*x)

Initialize the cosine mixture function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the cosine mixture function."""
    _validate_two_dimensional(*x, function_name="CosineMixture")
    super().__init__(*x)

CosineProductSphereFunction

Bases: OptFunction

Cosine-product sphere function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
class CosineProductSphereFunction(OptFunction):
    r"""Cosine-product sphere function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the cosine-product sphere function."""
        _validate_three_or_higher(*x, function_name="CosineProductSphere")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the cosine-product sphere function at x."""
        indices = np.arange(1, self.dimension + 1)
        cosine_term = np.ones_like(self._x[0])
        for index, axis in zip(indices, self._x, strict=True):
            cosine_term *= np.cos(axis / np.sqrt(index))
        return np.array(sum(axis**2 for axis in self._x) - cosine_term + 1)

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the cosine-product sphere function."""
        return MinimaAPI(f_x=0.0, x=tuple(0.0 for _ in range(self.dimension)))

__eval__ property

Evaluate the cosine-product sphere function at x.

__minima__ property

Return the minima of the cosine-product sphere function.

__init__(*x)

Initialize the cosine-product sphere function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the cosine-product sphere function."""
    _validate_three_or_higher(*x, function_name="CosineProductSphere")
    super().__init__(*x)

CrossInTrayFunction

Bases: OptFunction

Cross-in-tray function.

The Cross-in-tray function is a two-dimensional function with many local minima.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.many_local_minima import CrossInTrayFunction
>>> x = np.linspace(-10, 10, 1000)
>>> y = np.linspace(-10, 10, 1000)
>>> X, Y = np.meshgrid(x, y)
>>> Z = CrossInTrayFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("CrossInTrayFunction.png", dpi=300, transparent=True)
Notes

The Cross-in-tray function is defined as:

\[ f(x) = -0.0001 \cdot \left( \left| \sin(x_1) \sin(x_2) \exp \left( \left| 100 - \sqrt{x_1^2 + x_2^2} / \pi \right| \right) \right| + 1 \right)^{0.1} \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/many_local_minima.py
Python
class CrossInTrayFunction(OptFunction):
    r"""Cross-in-tray function.

    The Cross-in-tray function is a two-dimensional function with many local minima.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.many_local_minima import CrossInTrayFunction
        >>> x = np.linspace(-10, 10, 1000)
        >>> y = np.linspace(-10, 10, 1000)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = CrossInTrayFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("CrossInTrayFunction.png", dpi=300, transparent=True)

    Notes:
        The Cross-in-tray function is defined as:

        $$
            f(x) = -0.0001 \cdot \left( \left| \sin(x_1) \sin(x_2)
            \exp \left( \left| 100 - \sqrt{x_1^2 + x_2^2} / \pi \right| \right) \right|
            + 1 \right)^{0.1}
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/crossit.html).


    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="Cross-in-tray",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Cross-in-tray function at x.

        Returns:
            UniversalArray: Function values as numpy arrays.
        """
        x_1 = self._x[0]
        x_2 = self._x[1]

        term_1 = np.sin(x_1) * np.sin(x_2)
        term_2 = np.exp(np.abs(100 - np.sqrt(x_1**2 + x_2**2) / np.pi))
        return -0.0001 * np.abs(term_1 * term_2 + 1) ** 0.1

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the function.

        Returns:
            MinimaAPI: MinimaAPI object containing the minima of the function.
        """
        return MinimaAPI(
            f_x=-2.06261,
            x=tuple(
                np.array([1.34941, 1.34941]),
                np.array([-1.34941, -1.34941]),
                np.array([1.34941, -1.34941]),
                np.array([-1.34941, 1.34941]),
            ),
        )

__eval__ property

Evaluate Cross-in-tray function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Function values as numpy arrays.

__minima__ property

Return the minima of the function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

MinimaAPI object containing the minima of the function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="Cross-in-tray",
            dimension=__2d__,
        )
    super().__init__(*x)

DropWaveFunction

Bases: OptFunction

Drop-wave function.

The Drop-wave function is a two-dimensional function with many local minima.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.many_local_minima import DropWaveFunction
>>> x = np.linspace(-5, 5, 1000)
>>> y = np.linspace(-5, 5, 1000)
>>> X, Y = np.meshgrid(x, y)
>>> Z = DropWaveFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("DropWaveFunction.png", dpi=300, transparent=True)
Notes

The Drop-wave function is defined as:

\[ f(x) = -\left( 1 + \cos(12 \sqrt{x_1^2 + x_2^2}) \right) / (0.5(x_1^2 + x_2^2) + 2) \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/many_local_minima.py
Python
class DropWaveFunction(OptFunction):
    r"""Drop-wave function.

    The Drop-wave function is a two-dimensional function with many local minima.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.many_local_minima import DropWaveFunction
        >>> x = np.linspace(-5, 5, 1000)
        >>> y = np.linspace(-5, 5, 1000)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = DropWaveFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("DropWaveFunction.png", dpi=300, transparent=True)

    Notes:
        The Drop-wave function is defined as:

        $$
            f(x) = -\left( 1 + \cos(12 \sqrt{x_1^2 + x_2^2}) \right)
            / (0.5(x_1^2 + x_2^2) + 2)
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/drop.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="Drop-wave",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Drop-wave function at x.

        Returns:
            UniversalArray: Function values as numpy arrays.
        """
        x_1 = self._x[0]
        x_2 = self._x[1]

        term_1 = 12 * np.sqrt(x_1**2 + x_2**2)
        term_2 = 0.5 * (x_1**2 + x_2**2) + 2

        return -((1 + np.cos(term_1)) / term_2)

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the function.

        Returns:
            MinimaAPI: MinimaAPI object containing the minima of the function.
        """
        return MinimaAPI(f_x=-1.0, x=tuple(0.0, 0.0))

__eval__ property

Evaluate Drop-wave function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Function values as numpy arrays.

__minima__ property

Return the minima of the function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

MinimaAPI object containing the minima of the function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="Drop-wave",
            dimension=__2d__,
        )
    super().__init__(*x)

EggHolderFunction

Bases: OptFunction

Egg-holder function.

The Egg-holder function is a two-dimensional function with many local minima.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.many_local_minima import EggHolderFunction
>>> x = np.linspace(-512, 512, 1000)
>>> y = np.linspace(-512, 512, 1000)
>>> X, Y = np.meshgrid(x, y)
>>> Z = EggHolderFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("EggHolderFunction.png", dpi=300, transparent=True)
Notes

The Egg-holder function is defined as:

\[ f(x) = -(x_2 + 47) \sin \left( \sqrt{\left| x_2 + \frac{x_1}{2} + 47 \right|} \right) - x_1 \sin \left( \sqrt{\left| x_1 - (x_2 + 47) \right|} \right) \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/many_local_minima.py
Python
class EggHolderFunction(OptFunction):
    r"""Egg-holder function.

    The Egg-holder function is a two-dimensional function with many local minima.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.many_local_minima import EggHolderFunction
        >>> x = np.linspace(-512, 512, 1000)
        >>> y = np.linspace(-512, 512, 1000)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = EggHolderFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("EggHolderFunction.png", dpi=300, transparent=True)

    Notes:
        The Egg-holder function is defined as:

        $$
            f(x) = -(x_2 + 47) \sin \left( \sqrt{\left| x_2 + \frac{x_1}{2}
            + 47 \right|} \right) - x_1 \sin \left( \sqrt{\left| x_1
            - (x_2 + 47) \right|} \right)
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/egg.html).


    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="Egg-holder",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Egg-holder function at x.

        Returns:
            UniversalArray: Function values as numpy arrays.
        """
        x_1 = self._x[0]
        x_2 = self._x[1]

        term_1 = np.sqrt(np.abs(x_2 + 47 + x_1 / 2))
        term_2 = np.sqrt(np.abs(x_1 - (x_2 + 47)))

        return -(x_2 + 47) * np.sin(term_1) - x_1 * np.sin(term_2)

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the function.

        Returns:
            MinimaAPI: MinimaAPI object containing the minima of the function.
        """
        return MinimaAPI(f_x=-959.6407, x=tuple(512, 404.2319))

__eval__ property

Evaluate Egg-holder function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Function values as numpy arrays.

__minima__ property

Return the minima of the function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

MinimaAPI object containing the minima of the function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="Egg-holder",
            dimension=__2d__,
        )
    super().__init__(*x)

GramacyLeeFunction

Bases: OptFunction

Gramacy and Lee function.

The Gramacy and Lee function is a one-dimensional function with many local minima.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.many_local_minima import GramacyLeeFunction
>>> x = np.linspace(-1, 2.5, 1000)
>>> y = GramacyLeeFunction(x).__eval__
>>> _ = plt.plot(x, y)
>>> plt.savefig("GramacyLeeFunction.png", dpi=300, transparent=True)
Notes

The Gramacy and Lee function is defined as:

\[ f(x) = \sin(10 \pi x_1) / (2 x_1) + (x_1 - 1)^4 \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be one dimensional.

()
Source code in src/umf/functions/optimization/many_local_minima.py
Python
class GramacyLeeFunction(OptFunction):
    r"""Gramacy and Lee function.

    The Gramacy and Lee function is a one-dimensional function with many local minima.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.many_local_minima import GramacyLeeFunction
        >>> x = np.linspace(-1, 2.5, 1000)
        >>> y = GramacyLeeFunction(x).__eval__
        >>> _ = plt.plot(x, y)
        >>> plt.savefig("GramacyLeeFunction.png", dpi=300, transparent=True)

    Notes:
        The Gramacy and Lee function is defined as:

        $$
            f(x) = \sin(10 \pi x_1) / (2 x_1) + (x_1 - 1)^4
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/gramacy.html).

    Args:
        *x (UniversalArray): Input data, which has to be one dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __1d__:
            raise OutOfDimensionError(
                function_name="Gramacy and Lee",
                dimension=__1d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Gramacy and Lee function at x.

        Returns:
            UniversalArray: Function values as numpy arrays.
        """
        x_1 = self._x[0]

        term_1 = np.sin(10 * np.pi * x_1) / (2 * x_1)
        term_2 = (x_1 - 1) ** 4

        return term_1 + term_2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the function.

        Returns:
            MinimaAPI: MinimaAPI object containing the minima of the function.
        """
        return MinimaAPI(f_x=None, x=None)

__eval__ property

Evaluate Gramacy and Lee function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Function values as numpy arrays.

__minima__ property

Return the minima of the function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

MinimaAPI object containing the minima of the function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __1d__:
        raise OutOfDimensionError(
            function_name="Gramacy and Lee",
            dimension=__1d__,
        )
    super().__init__(*x)

GriewankFunction

Bases: OptFunction

Griewank function.

The Griewank function is a multi-dimensional function with many local minima.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.many_local_minima import GriewankFunction
>>> x = np.linspace(-50, 50, 1000)
>>> y = np.linspace(-50, 50, 1000)
>>> X, Y = np.meshgrid(x, y)
>>> Z = GriewankFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("GriewankFunction.png", dpi=300, transparent=True)
Notes

The Griewank function is defined as:

\[ f(x) = \frac{1}{4000} \sum_{i=1}^n x_i^2 - \prod_{i=1}^n \cos \left( \frac{x_i}{\sqrt{i}} \right) + 1 \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/many_local_minima.py
Python
class GriewankFunction(OptFunction):
    r"""Griewank function.

    The Griewank function is a multi-dimensional function with many local minima.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.many_local_minima import GriewankFunction
        >>> x = np.linspace(-50, 50, 1000)
        >>> y = np.linspace(-50, 50, 1000)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = GriewankFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("GriewankFunction.png", dpi=300, transparent=True)

    Notes:
        The Griewank function is defined as:

        $$
            f(x) = \frac{1}{4000} \sum_{i=1}^n x_i^2 - \prod_{i=1}^n \cos
            \left( \frac{x_i}{\sqrt{i}} \right) + 1
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/griewank.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Griewank function at x.

        Returns:
            UniversalArray: Function values as numpy arrays.
        """
        sum_ = np.zeros_like(self._x[0])
        for i, x_i in enumerate(self._x, start=1):
            sum_ += 1 / 4000 * x_i**2
            if i == 1:
                prod_ = np.cos(x_i / np.sqrt(i))
            prod_ *= np.cos(x_i / np.sqrt(i))

        return sum_ - prod_ + 1

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the function.

        Returns:
            MinimaAPI: MinimaAPI object containing the minima of the function.
        """
        return MinimaAPI(f_x=0, x=tuple(np.zeros_like(self._x[0])))

__eval__ property

Evaluate Griewank function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Function values as numpy arrays.

__minima__ property

Return the minima of the function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

MinimaAPI object containing the minima of the function.

HolderTableFunction

Bases: OptFunction

Holder table function.

The Holder table function is a two-dimensional function with many local minima.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.many_local_minima import HolderTableFunction
>>> x = np.linspace(-10, 10, 1000)
>>> y = np.linspace(-10, 10, 1000)
>>> X, Y = np.meshgrid(x, y)
>>> Z = HolderTableFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("HolderTableFunction.png", dpi=300, transparent=True)
Notes

The Holder table function is defined as:

\[ f(x) = -\left| \sin(x_1) \cos(x_2) \exp \left| 1 - \sqrt{x_1^2 + x_2^2} / \pi \right| \right| \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/many_local_minima.py
Python
class HolderTableFunction(OptFunction):
    r"""Holder table function.

    The Holder table function is a two-dimensional function with many local minima.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.many_local_minima import HolderTableFunction
        >>> x = np.linspace(-10, 10, 1000)
        >>> y = np.linspace(-10, 10, 1000)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = HolderTableFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("HolderTableFunction.png", dpi=300, transparent=True)

    Notes:
        The Holder table function is defined as:

        $$
            f(x) = -\left| \sin(x_1) \cos(x_2) \exp \left| 1 - \sqrt{x_1^2 + x_2^2} /
            \pi \right| \right|
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/holder.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="Holder table",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Holder table function at x.

        Returns:
            UniversalArray: Function values as numpy arrays.
        """
        x_1 = self._x[0]
        x_2 = self._x[1]

        term_1 = np.sin(x_1) * np.cos(x_2)
        term_2 = np.abs(1 - np.sqrt(x_1**2 + x_2**2) / np.pi)
        term_3 = np.exp(term_2)

        return -np.abs(term_1 * term_3)

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the function.

        Returns:
            MinimaAPI: MinimaAPI object containing the minima of the function.
        """
        return MinimaAPI(
            f_x=-19.2085,
            x=tuple(
                np.array([8.05502, 9.66459]),
                np.array([8.05502, -9.66459]),
                np.array([-8.05502, 9.66459]),
                np.array([-8.05502, -9.66459]),
            ),
        )

__eval__ property

Evaluate Holder table function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Function values as numpy arrays.

__minima__ property

Return the minima of the function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

MinimaAPI object containing the minima of the function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="Holder table",
            dimension=__2d__,
        )
    super().__init__(*x)

LangermannFunction

Bases: OptFunction

Langermann function.

The Langermann function is a multi-dimensional function with many unevenly distributed local minima.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.many_local_minima import LangermannFunction
>>> x = np.linspace(0, 10, 1000)
>>> y = np.linspace(0, 10, 1000)
>>> X, Y = np.meshgrid(x, y)
>>> Z = LangermannFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("langermann.png", dpi=300, transparent=True)
Notes

The Langermann function is defined as:

\[ f(x) = \sum_{i=1}^{5} c_i \exp \left( -\frac{1}{\pi} \sum_{j=1}^{2} (x_j - a_{ij})^2 \right) \cos \left( \pi \sum_{j=1}^{2} (x_j - a_{ij})^2 \right) \]

with the constants :math:c_i and the :math:a_{ij} given by:

\[ c_i = \left\{ 1, 2, 5, 2, 3 \right\}, \quad a_{ij} = \left\{ 3, 5, 2, 1, 7 \right\} \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
A UniversalArray

Matrix of constants :math:a_{ij}. The numbers of rows has to be equal to the number of input data, respectively, dimensions. Defaults to :math:a_{ij} = \left\{ 3, 5, 2, 1, 7 \right\}.

None
c UniversalArray

Vector of constants :math:c_i. Defaults to :math:c_i = \left\{ 1, 2, 5, 2, 3 \right\}.

None
m int

Number of local minima. Defaults to 5.

5
Source code in src/umf/functions/optimization/many_local_minima.py
Python
class LangermannFunction(OptFunction):
    r"""Langermann function.

    The Langermann function is a multi-dimensional function with many unevenly
    distributed local minima.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.many_local_minima import LangermannFunction
        >>> x = np.linspace(0, 10, 1000)
        >>> y = np.linspace(0, 10, 1000)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = LangermannFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("langermann.png", dpi=300, transparent=True)

    Notes:
        The Langermann function is defined as:

        $$
            f(x) = \sum_{i=1}^{5} c_i \exp \left( -\frac{1}{\pi} \sum_{j=1}^{2}
            (x_j - a_{ij})^2 \right) \cos \left( \pi
            \sum_{j=1}^{2} (x_j - a_{ij})^2 \right)
        $$

        with the constants :math:`c_i` and the :math:`a_{ij}` given by:

        $$
            c_i = \left\{ 1, 2, 5, 2, 3 \right\}, \quad a_{ij} =
            \left\{ 3, 5, 2, 1, 7 \right\}
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/langer.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
        A (UniversalArray, optional): Matrix of constants :math:`a_{ij}`. The numbers
            of rows has to be equal to the number of input data, respectively,
            dimensions. Defaults to :math:`a_{ij} = \left\{ 3, 5, 2, 1, 7 \right\}`.
        c (UniversalArray, optional): Vector of constants :math:`c_i`. Defaults to
            :math:`c_i = \left\{ 1, 2, 5, 2, 3 \right\}`.
        m (int, optional): Number of local minima. Defaults to 5.
    """

    def __init__(
        self,
        *x: UniversalArray,
        A: UniversalArray = None,
        c: UniversalArray = None,
        m: int = 5,
    ) -> None:
        """Initialize the function."""
        super().__init__(*x)

        if A is None:
            A = np.array([[3, 5, 2, 1, 7], [5, 2, 1, 4, 9]], dtype=float)  # noqa: N806

        if c is None:
            c = np.array([1, 2, 5, 2, 3], dtype=float)

        if len(x) != A.shape[0]:
            msg = "Dimension of x must match number of rows in A."
            raise ValueError(msg)

        if len(A.shape) != __2d__:
            msg = (
                "A must be two dimensional array. In case of one input the  "
                "array must lool like 'np.array([[...]])'. "
            )
            raise ValueError(
                msg,
            )
        if A.shape[1] != m:
            raise MatchLengthError(_object="A", _target="m")

        if len(c) != m:
            raise MatchLengthError(_object="C", _target="m")

        if len(c.shape) != __1d__:
            msg = "c must be one dimensional array."
            raise ValueError(msg)

        self.a_matrix = A
        self._c = c
        self._m = m

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Langermann function at x.

        Returns:
            UniversalArray: Function values as numpy arrays.
        """
        outer_sum = np.zeros_like(self._x[0])
        for i in range(self._m):
            inner_sum = np.zeros_like(self._x[0])
            for j, _x in enumerate(self._x):
                inner_sum += (_x - self.a_matrix[j, i]) ** 2
            outer_sum += (
                self._c[i] * np.exp(-inner_sum / np.pi) * np.cos(np.pi * inner_sum)
            )
        return outer_sum

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the function.

        Returns:
            MinimaAPI: MinimaAPI object containing the minima of the function.
        """
        return MinimaAPI(
            f_x=0.0,
            x=tuple(
                np.array([self.a_matrix[0, i], self.a_matrix[1, i]])
                for i in range(self._m)
            ),
        )

__eval__ property

Evaluate Langermann function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Function values as numpy arrays.

__minima__ property

Return the minima of the function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

MinimaAPI object containing the minima of the function.

__init__(*x, A=None, c=None, m=5)

Initialize the function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
def __init__(
    self,
    *x: UniversalArray,
    A: UniversalArray = None,
    c: UniversalArray = None,
    m: int = 5,
) -> None:
    """Initialize the function."""
    super().__init__(*x)

    if A is None:
        A = np.array([[3, 5, 2, 1, 7], [5, 2, 1, 4, 9]], dtype=float)  # noqa: N806

    if c is None:
        c = np.array([1, 2, 5, 2, 3], dtype=float)

    if len(x) != A.shape[0]:
        msg = "Dimension of x must match number of rows in A."
        raise ValueError(msg)

    if len(A.shape) != __2d__:
        msg = (
            "A must be two dimensional array. In case of one input the  "
            "array must lool like 'np.array([[...]])'. "
        )
        raise ValueError(
            msg,
        )
    if A.shape[1] != m:
        raise MatchLengthError(_object="A", _target="m")

    if len(c) != m:
        raise MatchLengthError(_object="C", _target="m")

    if len(c.shape) != __1d__:
        msg = "c must be one dimensional array."
        raise ValueError(msg)

    self.a_matrix = A
    self._c = c
    self._m = m

LevyFunction

Bases: OptFunction

Levy function.

The Levy function is a multi-dimensional function with many local and harmonic distributed minima.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.many_local_minima import LevyFunction
>>> x = np.linspace(-10, 10, 1000)
>>> y = np.linspace(-10, 10, 1000)
>>> X, Y = np.meshgrid(x, y)
>>> Z = LevyFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("LevyFunction.png", dpi=300, transparent=True)
Notes

The Levy function is defined as:

\[ f(x) = \sin^2( \pi w_1 ) + \sum_{i=1}^{d-1} \left( w_i - 1 \right)^2 \left[ 1 + 10 \sin^2( \pi w_i + 1 ) \right] + \left( w_d - 1 \right)^2 \left[ 1 + \sin^2( 2 \pi w_d ) \right] \]

with the :math:w_i given by:

\[ w_i = 1 + \frac{1}{4} (x_i - 1) \quad \forall i \in \left\{ 1, \dots, d \right\} \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/many_local_minima.py
Python
class LevyFunction(OptFunction):
    r"""Levy function.

    The Levy function is a multi-dimensional function with many local and harmonic
    distributed minima.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.many_local_minima import LevyFunction
        >>> x = np.linspace(-10, 10, 1000)
        >>> y = np.linspace(-10, 10, 1000)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = LevyFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("LevyFunction.png", dpi=300, transparent=True)

    Notes:
        The Levy function is defined as:

        $$
            f(x) = \sin^2( \pi w_1 ) + \sum_{i=1}^{d-1} \left( w_i - 1 \right)^2 \left[
            1 + 10 \sin^2( \pi w_i + 1 ) \right]
            + \left( w_d - 1 \right)^2 \left[
            1 + \sin^2( 2 \pi w_d ) \right]
        $$

        with the :math:`w_i` given by:

        $$
            w_i = 1 + \frac{1}{4} (x_i - 1) \quad \forall i \in
            \left\{ 1, \dots, d \right\}
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/levy.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Levy function at x.

        Returns:
            UniversalArray: Function values as numpy arrays.
        """
        sum_ = np.zeros_like(self._x[0])

        term_1 = np.sin(np.pi * (1 + (1 / 4) * (self._x[0] - 1))) ** 2

        if len(self._x) == 1:
            return term_1

        for i in range(1, len(self._x) - 1):
            term_2 = (1 + (1 / 4) * (self._x[i] - 1)) ** 2
            term_3 = 1 + 10 * np.sin(np.pi * (1 + (1 / 4) * (self._x[i] - 1)) + 1) ** 2
            sum_ += term_2 * term_3

        term_4 = (1 + (1 / 4) * (self._x[-1] - 1)) ** 2
        term_5 = (1 + np.sin(2 * np.pi * (1 + (1 / 4) * (self._x[-1] - 1)))) ** 2
        sum_ += term_4 * term_5
        return term_1 + sum_

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the function.

        Returns:
            MinimaAPI: MinimaAPI object containing the minima of the function.
        """
        return MinimaAPI(
            f_x=0.0,
            x=tuple(np.array([1.0]) for _ in range(len(self._x))),
        )

__eval__ property

Evaluate Levy function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Function values as numpy arrays.

__minima__ property

Return the minima of the function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

MinimaAPI object containing the minima of the function.

LevyN13Function

Bases: OptFunction

Levy N. 13 function.

The Levy N. 13 function is a two-dimensional function with many local and harmonic and parabolic distributed minima.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.many_local_minima import LevyN13Function
>>> x = np.linspace(-10, 10, 1000)
>>> y = np.linspace(-10, 10, 1000)
>>> X, Y = np.meshgrid(x, y)
>>> Z = LevyN13Function(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("LevyN13Function.png", dpi=300, transparent=True)
Notes

The Levy N. 13 function is defined as:

\[ f(x) = \sin^2( 3 \pi x_1 ) + \left( x_1 - 1 \right)^2 \left[ 1 + \sin^2( 3 \pi x_2) \right] + \left( x_2 - 1 \right)^2 \left[ 1 + \sin^2( 2 \pi x_2 ) \right] \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/many_local_minima.py
Python
class LevyN13Function(OptFunction):
    r"""Levy N. 13 function.

    The Levy N. 13 function is a two-dimensional function with many local and harmonic
    and parabolic distributed minima.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.many_local_minima import LevyN13Function
        >>> x = np.linspace(-10, 10, 1000)
        >>> y = np.linspace(-10, 10, 1000)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = LevyN13Function(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("LevyN13Function.png", dpi=300, transparent=True)

    Notes:
        The Levy N. 13 function is defined as:

        $$
            f(x) = \sin^2( 3 \pi x_1 ) + \left( x_1 - 1 \right)^2 \left[ 1
            + \sin^2( 3 \pi x_2) \right] + \left( x_2 - 1 \right)^2 \left[ 1
            + \sin^2( 2 \pi x_2 ) \right]
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/levy13.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="Levy N. 13",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Levy N. 13 function at x.

        Returns:
            UniversalArray: Function values as numpy arrays.
        """
        x_1 = self._x[0]
        x_2 = self._x[1]

        term_1 = np.sin(3 * np.pi * x_1) ** 2
        term_2 = (x_1 - 1) ** 2
        term_3 = 1 + np.sin(3 * np.pi * x_2) ** 2
        term_4 = (x_2 - 1) ** 2
        term_5 = 1 + np.sin(2 * np.pi * x_2) ** 2
        return term_1 + term_2 * term_3 + term_4 * term_5

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the function.

        Returns:
            MinimaAPI: MinimaAPI object containing the minima of the function.
        """
        return MinimaAPI(
            f_x=0.0,
            x=(1.0, 1.0),
        )

__eval__ property

Evaluate Levy N. 13 function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Function values as numpy arrays.

__minima__ property

Return the minima of the function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

MinimaAPI object containing the minima of the function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="Levy N. 13",
            dimension=__2d__,
        )
    super().__init__(*x)

RastriginFunction

Bases: OptFunction

Rastrigin function.

The Rastrigin function is a multi-dimensional function with many local and harmonic and parabolic distributed minima.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.many_local_minima import RastriginFunction
>>> x = np.linspace(-5.12, 5.12, 1000)
>>> y = np.linspace(-5.12, 5.12, 1000)
>>> X, Y = np.meshgrid(x, y)
>>> Z = RastriginFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("RastriginFunction.png", dpi=300, transparent=True)
Notes

The Rastrigin function is defined as:

\[ f(x) = 10 n + \sum_{i=1}^n \left[ x_i^2 - 10 \cos(2 \pi x_i) \right] \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/many_local_minima.py
Python
class RastriginFunction(OptFunction):
    r"""Rastrigin function.

    The Rastrigin function is a multi-dimensional function with many local and harmonic
    and parabolic distributed minima.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.many_local_minima import RastriginFunction
        >>> x = np.linspace(-5.12, 5.12, 1000)
        >>> y = np.linspace(-5.12, 5.12, 1000)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = RastriginFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("RastriginFunction.png", dpi=300, transparent=True)

    Notes:
        The Rastrigin function is defined as:

        $$
            f(x) = 10 n + \sum_{i=1}^n \left[ x_i^2 - 10 \cos(2 \pi x_i) \right]
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/rastr.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Rastrigin function at x.

        Returns:
            UniversalArray: Function values as numpy arrays.
        """
        sum_ = np.zeros_like(self._x[0])
        for x_i in self._x:
            sum_ += x_i**2 - 10 * np.cos(2 * np.pi * x_i)
        return 10 * len(self._x) + sum_

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the function.

        Returns:
            MinimaAPI: MinimaAPI object containing the minima of the function.
        """
        return MinimaAPI(
            f_x=0.0,
            x=tuple(np.array([0.0]) for _ in range(len(self._x))),
        )

__eval__ property

Evaluate Rastrigin function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Function values as numpy arrays.

__minima__ property

Return the minima of the function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

MinimaAPI object containing the minima of the function.

SchafferN2Function

Bases: OptFunction

Schaffer N. 2 function.

The Schaffer N. 2 function is a two-dimensional function with a single global minimum and radial distributed local minima.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.many_local_minima import SchafferN2Function
>>> x = np.linspace(-100, 100, 1000)
>>> y = np.linspace(-100, 100, 1000)
>>> X, Y = np.meshgrid(x, y)
>>> Z = SchafferN2Function(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("SchafferN2Function.png", dpi=300, transparent=True)
Notes

The Schaffer N. 2 function is defined as:

\[ f(x) = \frac{1}{2} + \frac{ \sin^2 \left( \left| x_1^2 + x_2^2 \right| \right) - 0.5 }{ \left( 1 + 0.001 \left( x_1^2 + x_2^2 \right) \right)^2 } \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/many_local_minima.py
Python
class SchafferN2Function(OptFunction):
    r"""Schaffer N. 2 function.

    The Schaffer N. 2 function is a two-dimensional function with a
    single global minimum and radial distributed local minima.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.many_local_minima import SchafferN2Function
        >>> x = np.linspace(-100, 100, 1000)
        >>> y = np.linspace(-100, 100, 1000)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = SchafferN2Function(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("SchafferN2Function.png", dpi=300, transparent=True)

    Notes:
        The Schaffer N. 2 function is defined as:

        $$
            f(x) = \frac{1}{2} + \frac{ \sin^2 \left( \left| x_1^2 + x_2^2 \right|
            \right) - 0.5 }{ \left( 1 + 0.001 \left( x_1^2 + x_2^2 \right) \right)^2 }
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/schaffer2.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="Schaffer N. 2",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Schaffer N. 2 function at x.

        Returns:
            UniversalArray: Function values as numpy arrays.
        """
        x_1 = self._x[0]
        x_2 = self._x[1]
        return (
            0.5
            + (np.sin(np.abs(x_1**2 + x_2**2)) ** 2 - 0.5)
            / (1 + 0.001 * (x_1**2 + x_2**2)) ** 2
        )

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the function.

        Returns:
            MinimaAPI: MinimaAPI object containing the minima of the function.
        """
        return MinimaAPI(
            f_x=0.0,
            x=(0.0, 0.0),
        )

__eval__ property

Evaluate Schaffer N. 2 function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Function values as numpy arrays.

__minima__ property

Return the minima of the function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

MinimaAPI object containing the minima of the function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="Schaffer N. 2",
            dimension=__2d__,
        )
    super().__init__(*x)

SchafferN4Function

Bases: OptFunction

Schaffer N. 4 function.

The Schaffer N. 4 function is a two-dimensional function with a single global minimum and radial distributed local minima.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.many_local_minima import SchafferN4Function
>>> x = np.linspace(-100, 100, 1000)
>>> y = np.linspace(-100, 100, 1000)
>>> X, Y = np.meshgrid(x, y)
>>> Z = SchafferN4Function(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("SchafferN4Function.png", dpi=300, transparent=True)
Notes

The Schaffer N. 4 function is defined as:

\[ f(x) = 0.5 + \frac{ \sin^2 \left( \sqrt{ x_1^2 + x_2^2 } \right) - 0.5 } { \left( 1 + 0.001 \left( x_1^2 + x_2^2 \right) \right)^2 } \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/many_local_minima.py
Python
class SchafferN4Function(OptFunction):
    r"""Schaffer N. 4 function.

    The Schaffer N. 4 function is a two-dimensional function with a
    single global minimum and radial distributed local minima.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.many_local_minima import SchafferN4Function
        >>> x = np.linspace(-100, 100, 1000)
        >>> y = np.linspace(-100, 100, 1000)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = SchafferN4Function(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("SchafferN4Function.png", dpi=300, transparent=True)

    Notes:
        The Schaffer N. 4 function is defined as:

        $$
            f(x) = 0.5 + \frac{ \sin^2 \left( \sqrt{ x_1^2 + x_2^2 } \right) - 0.5 }
            { \left( 1 + 0.001 \left( x_1^2 + x_2^2 \right) \right)^2 }
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/schaffer4.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="Schaffer N. 4",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Schaffer N. 4 function at x.

        Returns:
            UniversalArray: Function values as numpy arrays.
        """
        x_1 = self._x[0]
        x_2 = self._x[1]
        return (
            0.5
            + (np.sin(np.sqrt(x_1**2 + x_2**2)) ** 2 - 0.5)
            / (1 + 0.001 * (x_1**2 + x_2**2)) ** 2
        )

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the function."""
        return MinimaAPI(
            f_x=0.0,
            x=(0.0, 0.0),
        )

__eval__ property

Evaluate Schaffer N. 4 function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Function values as numpy arrays.

__minima__ property

Return the minima of the function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="Schaffer N. 4",
            dimension=__2d__,
        )
    super().__init__(*x)

SchwefelFunction

Bases: OptFunction

Schwefel function.

The Schwefel function is a multi-dimensional function with a single global minimum.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.many_local_minima import SchwefelFunction
>>> x = np.linspace(-100, 100, 1000)
>>> y = np.linspace(-100, 100, 1000)
>>> X, Y = np.meshgrid(x, y)
>>> Z = SchwefelFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("SchwefelFunction.png", dpi=300, transparent=True)
Notes

The Schwefel function is defined as:

\[ f(x) = 418.9829 n - \sum_{i=1}^{n} x_i \sin \left( \sqrt{ \left| x_i \right| } \right) \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/many_local_minima.py
Python
class SchwefelFunction(OptFunction):
    r"""Schwefel function.

    The Schwefel function is a multi-dimensional function with a
    single global minimum.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.many_local_minima import SchwefelFunction
        >>> x = np.linspace(-100, 100, 1000)
        >>> y = np.linspace(-100, 100, 1000)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = SchwefelFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("SchwefelFunction.png", dpi=300, transparent=True)

    Notes:
        The Schwefel function is defined as:

        $$
            f(x) = 418.9829 n - \sum_{i=1}^{n} x_i \sin
            \left( \sqrt{ \left| x_i \right| } \right)
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/schwef.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Schwefel function at x.

        Returns:
            UniversalArray: Function values as numpy arrays.
        """
        return 418.9829 * len(self._x) - np.sum(
            self._x * np.sin(np.sqrt(np.abs(self._x))),
            axis=0,
        )

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the function."""
        return MinimaAPI(
            f_x=0.0,
            x=(420.968746, 420.968746),
        )

__eval__ property

Evaluate Schwefel function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Function values as numpy arrays.

__minima__ property

Return the minima of the function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    super().__init__(*x)

ShubertFunction

Bases: OptFunction

Shubert function.

The Shubert function is a two-dimensional function with a single global minimum.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.many_local_minima import ShubertFunction
>>> x = np.linspace(-10, 10, 1000)
>>> y = np.linspace(-10, 10, 1000)
>>> X, Y = np.meshgrid(x, y)
>>> Z = ShubertFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("ShubertFunction.png", dpi=300, transparent=True)
Notes

The Shubert function is defined as:

\[ f(x) = \sum_{i=1}^{5} i \cos \left( \left( i + 1 \right) x_1 + i \right) + \sum_{i=1}^{5} i \cos \left( \left( i + 1 \right) x_2 + i \right) \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/many_local_minima.py
Python
class ShubertFunction(OptFunction):
    r"""Shubert function.

    The Shubert function is a two-dimensional function with a
    single global minimum.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.many_local_minima import ShubertFunction
        >>> x = np.linspace(-10, 10, 1000)
        >>> y = np.linspace(-10, 10, 1000)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = ShubertFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("ShubertFunction.png", dpi=300, transparent=True)

    Notes:
        The Shubert function is defined as:

        $$
            f(x) = \sum_{i=1}^{5} i \cos \left( \left( i + 1 \right) x_1 + i \right) +
            \sum_{i=1}^{5} i \cos \left( \left( i + 1 \right) x_2 + i \right)
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/shubert.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="Shubert",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Shubert function at x.

        Returns:
            UniversalArray: Function values as numpy arrays.
        """
        x_1 = self._x[0]
        x_2 = self._x[1]
        return np.sum(
            np.array(
                [
                    i * np.cos((i + 1) * x_1 + i) + i * np.cos((i + 1) * x_2 + i)
                    for i in range(1, 6)
                ],
            ),
            axis=0,
        )

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the function."""
        return MinimaAPI(f_x=-186.7309, x=(-7.708309818, -0.800371886))

__eval__ property

Evaluate Shubert function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Function values as numpy arrays.

__minima__ property

Return the minima of the function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="Shubert",
            dimension=__2d__,
        )
    super().__init__(*x)

Plate shaped functions for the useful-math-functions library.

BoothFunction

Bases: OptFunction

Booth Function.

The Booth function is a two-dimensional function with a single global minimum.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.plate_shaped import BoothFunction
>>> x = np.linspace(-10, 10, 100)
>>> y = np.linspace(-10, 10, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = BoothFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("BoothFunction.png", dpi=300, transparent=True)
Notes

The Booth function is defined as:

\[ f(x) = (x_1 + 2x_2 - 7)^2 + (2x_1 + x_2 - 5)^2 \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two-dimensional.

()
Source code in src/umf/functions/optimization/plate_shaped.py
Python
class BoothFunction(OptFunction):
    r"""Booth Function.

    The Booth function is a two-dimensional function with a single global
    minimum.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.plate_shaped import BoothFunction
        >>> x = np.linspace(-10, 10, 100)
        >>> y = np.linspace(-10, 10, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = BoothFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("BoothFunction.png", dpi=300, transparent=True)

    Notes:
        The Booth function is defined as:

        $$
            f(x) = (x_1 + 2x_2 - 7)^2 + (2x_1 + x_2 - 5)^2
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/booth.html).

    Args:
        *x (UniversalArray): Input data, which has to be two-dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            msg = f"Expected 2 arguments, but got {len(x)}."
            raise ValueError(msg)
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the Booth function at x."""
        x_1 = self._x[0]
        x_2 = self._x[1]
        return (x_1 + 2 * x_2 - 7) ** 2 + (2 * x_1 + x_2 - 5) ** 2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Booth function."""
        return MinimaAPI(
            f_x=0.0,
            x=(1.0, 3.0),
        )

__eval__ property

Evaluate the Booth function at x.

__minima__ property

Return the minima of the Booth function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/plate_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        msg = f"Expected 2 arguments, but got {len(x)}."
        raise ValueError(msg)
    super().__init__(*x)

MatyasFunction

Bases: OptFunction

Matyas Function.

The Matyas function is a two-dimensional function with a single global minimum.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.plate_shaped import MatyasFunction
>>> x = np.linspace(-10, 10, 100)
>>> y = np.linspace(-10, 10, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = MatyasFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("MatyasFunction.png", dpi=300, transparent=True)
Notes

The Matyas function is defined as:

\[ f(x) = 0.26(x_1^2 + x_2^2) - 0.48x_1 x_2 \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two-dimensional.

()
Source code in src/umf/functions/optimization/plate_shaped.py
Python
class MatyasFunction(OptFunction):
    r"""Matyas Function.

    The Matyas function is a two-dimensional function with a single global
    minimum.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.plate_shaped import MatyasFunction
        >>> x = np.linspace(-10, 10, 100)
        >>> y = np.linspace(-10, 10, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = MatyasFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("MatyasFunction.png", dpi=300, transparent=True)

    Notes:
        The Matyas function is defined as:

        $$
            f(x) = 0.26(x_1^2 + x_2^2) - 0.48x_1 x_2
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/matya.html).

    Args:
        *x (UniversalArray): Input data, which has to be two-dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="Matyas",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the Matyas function at x."""
        x_1 = self._x[0]
        x_2 = self._x[1]
        return 0.26 * (x_1**2 + x_2**2) - 0.48 * x_1 * x_2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Matyas function."""
        return MinimaAPI(
            f_x=0.0,
            x=(0.0, 0.0),
        )

__eval__ property

Evaluate the Matyas function at x.

__minima__ property

Return the minima of the Matyas function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/plate_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="Matyas",
            dimension=__2d__,
        )
    super().__init__(*x)

McCormickFunction

Bases: OptFunction

McCormick Function.

The McCormick function is a two-dimensional function with a single global minimum.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.plate_shaped import McCormickFunction
>>> x = np.linspace(-1.5, 4, 100)
>>> y = np.linspace(-3, 4, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = McCormickFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("McCormickFunction.png", dpi=300, transparent=True)
Notes

The McCormick function is defined as:

\[ f(x) = \sin(x_1 + x_2) + (x_1 - x_2)^2 - 1.5x_1 + 2.5x_2 + 1 \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two-dimensional.

()
Source code in src/umf/functions/optimization/plate_shaped.py
Python
class McCormickFunction(OptFunction):
    r"""McCormick Function.

    The McCormick function is a two-dimensional function with a single global
    minimum.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.plate_shaped import McCormickFunction
        >>> x = np.linspace(-1.5, 4, 100)
        >>> y = np.linspace(-3, 4, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = McCormickFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("McCormickFunction.png", dpi=300, transparent=True)

    Notes:
        The McCormick function is defined as:

        $$
            f(x) = \sin(x_1 + x_2) + (x_1 - x_2)^2 - 1.5x_1 + 2.5x_2 + 1
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/mccorm.html).

    Args:
        *x (UniversalArray): Input data, which has to be two-dimensional.
    """

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the McCormick function at x."""
        x_1 = self._x[0]
        x_2 = self._x[1]
        return np.sin(x_1 + x_2) + (x_1 - x_2) ** 2 - 1.5 * x_1 + 2.5 * x_2 + 1

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the McCormick function."""
        return MinimaAPI(
            f_x=-1.9133,
            x=(-0.54719, -1.54719),
        )

__eval__ property

Evaluate the McCormick function at x.

__minima__ property

Return the minima of the McCormick function.

PowerSumFunction

Bases: OptFunction

Power Sum Function.

The Power Sum function is a two-dimensional function with a single global minimum.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.plate_shaped import PowerSumFunction
>>> x = np.linspace(-1, 1, 100)
>>> y = np.linspace(-1, 1, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = PowerSumFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("PowerSumFunction.png", dpi=300, transparent=True)
Notes

The Power Sum function is defined as:

\[ f(x) = x_1^2 + x_2^2 + x_1^4 + x_2^4 \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two-dimensional.

()
Source code in src/umf/functions/optimization/plate_shaped.py
Python
class PowerSumFunction(OptFunction):
    r"""Power Sum Function.

    The Power Sum function is a two-dimensional function with a single global
    minimum.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.plate_shaped import PowerSumFunction
        >>> x = np.linspace(-1, 1, 100)
        >>> y = np.linspace(-1, 1, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = PowerSumFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("PowerSumFunction.png", dpi=300, transparent=True)

    Notes:
        The Power Sum function is defined as:

        $$
            f(x) = x_1^2 + x_2^2 + x_1^4 + x_2^4
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/powersum.html).

    Args:
        *x (UniversalArray): Input data, which has to be two-dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="Power Sum",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArrayTuple:
        """Evaluate the Power Sum function at x."""
        x_1 = self._x[0]
        x_2 = self._x[1]
        return x_1**2 + x_2**2 + x_1**4 + x_2**4

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Power Sum function."""
        return MinimaAPI(
            f_x=0.0,
            x=(0.0, 0.0),
        )

__eval__ property

Evaluate the Power Sum function at x.

__minima__ property

Return the minima of the Power Sum function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/plate_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="Power Sum",
            dimension=__2d__,
        )
    super().__init__(*x)

ZakharovFunction

Bases: OptFunction

Zakharov Function.

The Zakharov function is a two-dimensional function with a single global minimum.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.plate_shaped import ZakharovFunction
>>> x = np.linspace(-10, 10, 100)
>>> y = np.linspace(-10, 10, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = ZakharovFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("ZakharovFunction.png", dpi=300, transparent=True)
Notes

The Zakharov function is defined as:

\[ f(x) = \sum_{i=1}^2 x_i^2 + \left(\sum_{i=1}^2 0.5ix_i\right)^2 + \left(\sum_{i=1}^2 0.5ix_i\right)^4 \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two-dimensional.

()
Source code in src/umf/functions/optimization/plate_shaped.py
Python
class ZakharovFunction(OptFunction):
    r"""Zakharov Function.

    The Zakharov function is a two-dimensional function with a single global
    minimum.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.plate_shaped import ZakharovFunction
        >>> x = np.linspace(-10, 10, 100)
        >>> y = np.linspace(-10, 10, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = ZakharovFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("ZakharovFunction.png", dpi=300, transparent=True)

    Notes:
        The Zakharov function is defined as:

        $$
            f(x) = \sum_{i=1}^2 x_i^2 + \left(\sum_{i=1}^2 0.5ix_i\right)^2
            + \left(\sum_{i=1}^2 0.5ix_i\right)^4
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/zakharov.html).

    Args:
        *x (UniversalArray): Input data, which has to be two-dimensional.
    """

    @property
    def __eval__(self) -> UniversalArrayTuple:
        """Evaluate the Zakharov function at x."""
        sum_1 = np.zeros_like(self._x[0])
        sum_2 = np.zeros_like(self._x[0])

        for i in range(self.dimension):
            sum_1 += self._x[i] ** 2
            sum_2 += 0.5 * (i + 1) * self._x[i]

        return sum_1 + sum_2**2 + sum_2**4

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Zakharov function."""
        return MinimaAPI(
            f_x=0.0,
            x=tuple(np.zeros_like(self.dimension)),
        )

__eval__ property

Evaluate the Zakharov function at x.

__minima__ property

Return the minima of the Zakharov function.

ZettlFunction

Bases: OptFunction

Zettl function.

The Zettl function is a D-dimensional function with multimodal structure and sharp peaks.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.plate_shaped import ZettlFunction
>>> x = np.linspace(-5, 10, 100)
>>> y = np.linspace(-5, 10, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = ZettlFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("ZettlFunction.png", dpi=300, transparent=True)
Notes

The Zettl function is defined as:

\[ f(x) = (x_1^2 + x_2^2 - 2 x_1)^2 + \frac{1}{4} x_1 \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/plate_shaped.py
Python
class ZettlFunction(OptFunction):
    r"""Zettl function.

    The Zettl function is a D-dimensional function with multimodal structure and sharp
    peaks.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.plate_shaped import ZettlFunction
        >>> x = np.linspace(-5, 10, 100)
        >>> y = np.linspace(-5, 10, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = ZettlFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("ZettlFunction.png", dpi=300, transparent=True)

    Notes:
        The Zettl function is defined as:

        $$
            f(x) = (x_1^2 + x_2^2 - 2 x_1)^2 + \frac{1}{4} x_1
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/zettl.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            msg = f"Expected 2 arguments, but got {len(x)}."
            raise ValueError(msg)
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Zettl function at x.

        Returns:
            UniversalArray: Evaluated function value.
        """
        return (
            self._x[0] ** 2 + self._x[1] ** 2 - 2 * self._x[0]
        ) ** 2 + 0.25 * self._x[0]

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Zettl function.

        Returns:
            MinimaAPI: Minima of the Zettl function.
        """
        return MinimaAPI(f_x=0, x=(0, 0))

__eval__ property

Evaluate Zettl function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Evaluated function value.

__minima__ property

Return the minima of the Zettl function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

Minima of the Zettl function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/plate_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        msg = f"Expected 2 arguments, but got {len(x)}."
        raise ValueError(msg)
    super().__init__(*x)

Special optimization functions for the useful-math-functions library.

BealeFunction

Bases: OptFunction

Beale function.

The Beale function is a two-dimensional function with multimodal structure and sharp peaks.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.special import BealeFunction
>>> x = np.linspace(-4.5, 4.5, 100)
>>> y = np.linspace(-4.5, 4.5, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = BealeFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("BealeFunction.png", dpi=300, transparent=True)
Notes

The Beale function is defined as:

\[ f(x, y) = (1.5 - x + xy)^2 + (2.25 - x + xy^2)^2 + (2.625 - x + xy^3)^2 \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()

Raises:

Type Description
OutOfDimensionError

If the dimension of the input data is not 2.

Source code in src/umf/functions/optimization/special.py
Python
class BealeFunction(OptFunction):
    r"""Beale function.

    The Beale function is a two-dimensional function with multimodal structure and
    sharp peaks.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.special import BealeFunction
        >>> x = np.linspace(-4.5, 4.5, 100)
        >>> y = np.linspace(-4.5, 4.5, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = BealeFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("BealeFunction.png", dpi=300, transparent=True)

    Notes:
        The Beale function is defined as:

        $$
            f(x, y) = (1.5 - x + xy)^2 + (2.25 - x + xy^2)^2 + (2.625 - x + xy^3)^2
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/beale.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.

    Raises:
        OutOfDimensionError: If the dimension of the input data is not 2.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="Beale",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Beale function at x.

        Returns:
            UniversalArray: Evaluated function value.
        """
        x, y = self._x[0], self._x[1]
        return (
            (1.5 - x + x * y) ** 2
            + (2.25 - x + x * y**2) ** 2
            + (2.625 - x + x * y**3) ** 2
        )

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Beale function.

        Returns:
            MinimaAPI: Minima of the Beale function.
        """
        return MinimaAPI(f_x=3, x=(0.5))

__eval__ property

Evaluate Beale function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Evaluated function value.

__minima__ property

Return the minima of the Beale function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

Minima of the Beale function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/special.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="Beale",
            dimension=__2d__,
        )
    super().__init__(*x)

BraninFunction

Bases: OptFunction

Branin function.

The Branin function is a two-dimensional function with multimodal structure and sharp peaks.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.special import BraninFunction
>>> x = np.linspace(-5, 10, 100)
>>> y = np.linspace(0, 15, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = BraninFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("BraninFunction.png", dpi=300, transparent=True)
Notes

The Branin function is defined as:

\[ f(x, y) = a(y - bx^2 + cx - r)^2 + s(1 - t) \cos(y) + s \]

where

\[ a = 1, b = 5.1/(4\pi^2), c = 5/\pi, r = 6, s = 10, t = 1/(8\pi) \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()

Raises:

Type Description
OutOfDimensionError

If the dimension of the input data is not 2.

Source code in src/umf/functions/optimization/special.py
Python
class BraninFunction(OptFunction):
    r"""Branin function.

    The Branin function is a two-dimensional function with multimodal structure and
    sharp peaks.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.special import BraninFunction
        >>> x = np.linspace(-5, 10, 100)
        >>> y = np.linspace(0, 15, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = BraninFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("BraninFunction.png", dpi=300, transparent=True)

    Notes:
        The Branin function is defined as:

        $$
            f(x, y) = a(y - bx^2 + cx - r)^2 + s(1 - t) \cos(y) + s
        $$

        where

        $$
            a = 1, b = 5.1/(4\pi^2), c = 5/\pi, r = 6, s = 10, t = 1/(8\pi)
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/branin.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.

    Raises:
        OutOfDimensionError: If the dimension of the input data is not 2.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="Branin",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Branin function at x.

        Returns:
            UniversalArray: Evaluated function value.
        """
        x, y = self._x[0], self._x[1]
        a = 1
        b = 5.1 / (4 * np.pi**2)
        c = 5 / np.pi
        r = 6
        s = 10
        t = 1 / (8 * np.pi)
        return a * (y - b * x**2 + c * x - r) ** 2 + s * (1 - t) * np.cos(y) + s

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Branin function.

        Returns:
            MinimaAPI: Minima of the Branin function.
        """
        return MinimaAPI(
            f_x=0.397887,
            x=tuple(
                np.array([-np.pi, 12.275]),
                np.array([np.pi, 2.275]),
                np.array([np.pi, 9.42478]),
                np.array([9.42478, 2.475]),
            ),
        )

__eval__ property

Evaluate Branin function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Evaluated function value.

__minima__ property

Return the minima of the Branin function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

Minima of the Branin function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/special.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="Branin",
            dimension=__2d__,
        )
    super().__init__(*x)

GoldsteinPriceFunction

Bases: OptFunction

Goldstein-Price function.

The Goldstein-Price function is a two-dimensional function.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.special import GoldsteinPriceFunction
>>> x = np.linspace(-2, 2, 100)
>>> y = np.linspace(-2, 2, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = GoldsteinPriceFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("GoldsteinPriceFunction.png", dpi=300, transparent=True)
Notes

The Goldstein-Price function is defined as:

\[ f(x) = \left( 1 + \left( x_1 + x_2 + 1 \right)^2 \left( 19 - 14 x_1 + 3 x_1^2 - 14 x_2 + 6 x_1 x_2 + 3 x_2^2 \right) \right) \left( 30 + \left( 2 x - 3 x_2 \right)^2 \left( 18 - 32 x_1 + 12 x^2 + 48 x_2 - 36 x_1 x_2 + 27 x_2^2 \right) \right) \]

The hypercube of the function is defined as \(x_1, x_2 \in [-2, 2]\).

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/special.py
Python
class GoldsteinPriceFunction(OptFunction):
    r"""Goldstein-Price function.

    The Goldstein-Price function is a two-dimensional function.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.special import GoldsteinPriceFunction
        >>> x = np.linspace(-2, 2, 100)
        >>> y = np.linspace(-2, 2, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = GoldsteinPriceFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("GoldsteinPriceFunction.png", dpi=300, transparent=True)

    Notes:
        The Goldstein-Price function is defined as:

        $$
            f(x) = \left( 1 + \left( x_1 + x_2 + 1 \right)^2
            \left( 19 - 14 x_1 + 3 x_1^2 - 14 x_2 + 6 x_1 x_2 + 3 x_2^2 \right) \right)
            \left( 30 + \left( 2 x - 3 x_2 \right)^2
            \left( 18 - 32 x_1 + 12 x^2 + 48 x_2 - 36 x_1 x_2 + 27 x_2^2 \right) \right)
        $$

        The hypercube of the function is defined as $x_1, x_2 \in [-2, 2]$.

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/goldpr.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="Goldstein-Price",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Goldstein-Price function at x.

        Returns:
            UniversalArray: Evaluated function value.
        """
        return (
            1
            + (self._x[0] + self._x[1] + 1) ** 2
            * (
                19
                - 14 * self._x[0]
                + 3 * self._x[0] ** 2
                - 14 * self._x[1]
                + 6 * self._x[0] * self._x[1]
                + 3 * self._x[1] ** 2
            )
        ) * (
            30
            + (2 * self._x[0] - 3 * self._x[1]) ** 2
            * (
                18
                - 32 * self._x[0]
                + 12 * self._x[0] ** 2
                + 48 * self._x[1]
                - 36 * self._x[0] * self._x[1]
                + 27 * self._x[1] ** 2
            )
        )

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Goldstein-Price function.

        Returns:
            MinimaAPI: Minima of the Goldstein-Price function.
        """
        return MinimaAPI(f_x=3, x=tuple(np.array([0, -1])))

__eval__ property

Evaluate Goldstein-Price function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Evaluated function value.

__minima__ property

Return the minima of the Goldstein-Price function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

Minima of the Goldstein-Price function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/special.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="Goldstein-Price",
            dimension=__2d__,
        )
    super().__init__(*x)

GoldsteinPriceLogFunction

Bases: OptFunction

Goldstein-Price function in logarithmic form.

The Goldstein-Price function in logarithmic form is a two-dimensional function. In this form, the function offers a better conditioning by using the logarithm.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.special import GoldsteinPriceLogFunction
>>> x = np.linspace(-2, 2, 100)
>>> y = np.linspace(-2, 2, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = GoldsteinPriceLogFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("GoldsteinPriceLogFunction.png", dpi=300, transparent=True)
Notes

The Goldstein-Price function in logarithmic form is defined as:

$$ f(x, y) = frac{1}{2.427} left[ log left( 1 + left( bar{x}_1 + bar{x}_2 + 1 right)^2 left( 19 - 14 x + 3 bar{x}_1^2 - 14 bar{x}_2 + 6 bar{x}_1 bar{x}_2 + 3 bar{x}_2^2 right) right) + log left( 30 + left( 2 bar{x}_1 - 3 bar{x}_2 right)^2 left( 18 - 32 bar{x}_1 + 12 bar{x}_1^2 + 48 bar{x}_2 - 36 bar{x}_1 bar{x}_2 + 27 y^2 right) right) - 8.683 right]

Scdoc
\text{with } \bar{x}_{1,2} = 4 x_{1,2} - 2

$$

The hypercube of the function is defined as \(x_1, x_2 \in [-2, 2]\).

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/special.py
Python
class GoldsteinPriceLogFunction(OptFunction):
    r"""Goldstein-Price function in logarithmic form.

    The Goldstein-Price function in logarithmic form is a two-dimensional function.
    In this form, the function offers a better conditioning by using the logarithm.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.special import GoldsteinPriceLogFunction
        >>> x = np.linspace(-2, 2, 100)
        >>> y = np.linspace(-2, 2, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = GoldsteinPriceLogFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("GoldsteinPriceLogFunction.png", dpi=300, transparent=True)

    Notes:
        The Goldstein-Price function in logarithmic form is defined as:

        $$
            f(x, y) = \frac{1}{2.427} \left[
            \log \left( 1 + \left( \bar{x}_1 + \bar{x}_2 + 1 \right)^2
            \left( 19 - 14 x + 3 \bar{x}_1^2 - 14 \bar{x}_2 + 6 \bar{x}_1 \bar{x}_2
            + 3 \bar{x}_2^2 \right) \right) + \log \left( 30 + \left( 2 \bar{x}_1 - 3
            \bar{x}_2 \right)^2 \left( 18 - 32 \bar{x}_1 + 12 \bar{x}_1^2 + 48
            \bar{x}_2 - 36 \bar{x}_1 \bar{x}_2 + 27 y^2 \right) \right) - 8.683 \right]

            \text{with } \bar{x}_{1,2} = 4 x_{1,2} - 2
        $$

        The hypercube of the function is defined as $x_1, x_2 \in [-2, 2]$.

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/goldpr.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="Goldstein-Price",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Goldstein-Price function in logarithmic form at x.

        Returns:
            UniversalArray: Evaluated function value.
        """
        x_1 = 4 * self._x[0] - 2
        x_2 = 4 * self._x[1] - 2
        return (
            1
            / 2.427
            * (
                np.log(
                    1
                    + (x_1 + x_2 + 1) ** 2
                    * (
                        19
                        - 14 * x_1
                        + 3 * x_1**2
                        - 14 * x_2
                        + 6 * x_1 * x_2
                        + 3 * x_2**2
                    ),
                )
                + np.log(
                    30
                    + (2 * x_1 - 3 * x_2) ** 2
                    * (
                        18
                        - 32 * x_1
                        + 12 * x_1**2
                        + 48 * x_2
                        - 36 * x_1 * x_2
                        + 27 * x_2**2
                    ),
                )
                - 8.683
            )
        )

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Goldstein-Price function in logarithmic form.

        Returns:
            MinimaAPI: Minima of the Goldstein-Price function in logarithmic form.
        """
        return MinimaAPI(f_x=3, x=tuple(np.array([0, -1])))

__eval__ property

Evaluate Goldstein-Price function in logarithmic form at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Evaluated function value.

__minima__ property

Return the minima of the Goldstein-Price function in logarithmic form.

Returns:

Name Type Description
MinimaAPI MinimaAPI

Minima of the Goldstein-Price function in logarithmic form.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/special.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="Goldstein-Price",
            dimension=__2d__,
        )
    super().__init__(*x)

HimmelblauFunction

Bases: OptFunction

Himmelblau function.

The Himmelblau function is a two-dimensional function with four global minima.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.special import HimmelblauFunction
>>> x = np.linspace(-5, 5, 100)
>>> y = np.linspace(-5, 5, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = HimmelblauFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("HimmelblauFunction.png", dpi=300, transparent=True)
Notes

The Himmelblau function is defined as:

\[ f(x, y) = (x^2 + y - 11)^2 + (x + y^2 - 7)^2 \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()

Raises:

Type Description
OutOfDimensionError

If the dimension of the input data is not 2.

Source code in src/umf/functions/optimization/special.py
Python
class HimmelblauFunction(OptFunction):
    r"""Himmelblau function.

    The Himmelblau function is a two-dimensional function with four global minima.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.special import HimmelblauFunction
        >>> x = np.linspace(-5, 5, 100)
        >>> y = np.linspace(-5, 5, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = HimmelblauFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("HimmelblauFunction.png", dpi=300, transparent=True)

    Notes:
        The Himmelblau function is defined as:

        $$
            f(x, y) = (x^2 + y - 11)^2 + (x + y^2 - 7)^2
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/himmel.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.

    Raises:
        OutOfDimensionError: If the dimension of the input data is not 2.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="Himmelblau",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Himmelblau function at x.

        Returns:
            UniversalArray: Evaluated function value.
        """
        x, y = self._x[0], self._x[1]
        return (x**2 + y - 11) ** 2 + (x + y**2 - 7) ** 2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Himmelblau function.

        Returns:
            MinimaAPI: Minima of the Himmelblau function.
        """
        return MinimaAPI(
            f_x=0.0,
            x=tuple(
                np.array([3.0, 2.0]),
                np.array([-2.805118, 3.131312]),
                np.array([-3.779310, -3.283186]),
                np.array([3.584428, -1.848126]),
            ),
        )

__eval__ property

Evaluate Himmelblau function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Evaluated function value.

__minima__ property

Return the minima of the Himmelblau function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

Minima of the Himmelblau function.

__init__(*x)

Initialize the function.

Source code in src/umf/functions/optimization/special.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="Himmelblau",
            dimension=__2d__,
        )
    super().__init__(*x)

StyblinskiTangFunction

Bases: OptFunction

Styblinski-Tang function.

The Styblinski-Tang function is a D-dimensional function.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.special import StyblinskiTangFunction
>>> x = np.linspace(-5, 5, 100)
>>> y = np.linspace(-5, 5, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = StyblinskiTangFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("StyblinskiTangFunction.png", dpi=300, transparent=True)
Notes

The Styblinski-Tang function is defined as:

\[ f(x) = \frac{1}{2} \sum_{i=1}^D \left( x_i^4 - 16 x_i^2 + 5 x_i \right) \]

with \(D\) the dimension of the input. The hypercube of the function is defined as \(x_i \in [-5, 5]\) for all \(i\).

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two dimensional.

()
Source code in src/umf/functions/optimization/special.py
Python
class StyblinskiTangFunction(OptFunction):
    r"""Styblinski-Tang function.

    The Styblinski-Tang function is a D-dimensional function.


    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.special import StyblinskiTangFunction
        >>> x = np.linspace(-5, 5, 100)
        >>> y = np.linspace(-5, 5, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = StyblinskiTangFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("StyblinskiTangFunction.png", dpi=300, transparent=True)

    Notes:
        The Styblinski-Tang function is defined as:

        $$
            f(x) = \frac{1}{2} \sum_{i=1}^D \left( x_i^4 - 16 x_i^2 + 5 x_i \right)
        $$

        with $D$ the dimension of the input. The hypercube of the function is defined
        as $x_i \in [-5, 5]$ for all $i$.

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/stybtang.html).

    Args:
        *x (UniversalArray): Input data, which has to be two dimensional.
    """

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Styblinski-Tang function at x.

        Returns:
            UniversalArray: Evaluated function value.
        """
        return np.array(
            0.5
            * sum(
                (self._x[i - 1] ** 4 - 16 * self._x[i - 1] ** 2 + 5 * self._x[i - 1])
                for i in range(1, self.dimension + 1)
            ),
        )

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the Styblinski-Tang function.

        Returns:
            MinimaAPI: Minima of the Styblinski-Tang function.
        """
        return MinimaAPI(
            f_x=-39.16616570377142,
            x=tuple(np.ones(self.dimension) * -2.903534),
        )

__eval__ property

Evaluate Styblinski-Tang function at x.

Returns:

Name Type Description
UniversalArray UniversalArray

Evaluated function value.

__minima__ property

Return the minima of the Styblinski-Tang function.

Returns:

Name Type Description
MinimaAPI MinimaAPI

Minima of the Styblinski-Tang function.

Valley shaped functions for the useful-math-functions library.

CubicValleyFunction

Bases: OptFunction

Cubic valley function.

Source code in src/umf/functions/optimization/valley_shaped.py
Python
class CubicValleyFunction(OptFunction):
    r"""Cubic valley function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the cubic valley function."""
        _validate_two_dimensional(*x, function_name="CubicValley")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the cubic valley function at x."""
        x_1, x_2 = self._x
        return (x_1 - 1) ** 2 + (x_2 - x_1**3) ** 2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the cubic valley function."""
        return MinimaAPI(f_x=0.0, x=(1.0, 1.0))

__eval__ property

Evaluate the cubic valley function at x.

__minima__ property

Return the minima of the cubic valley function.

__init__(*x)

Initialize the cubic valley function.

Source code in src/umf/functions/optimization/valley_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the cubic valley function."""
    _validate_two_dimensional(*x, function_name="CubicValley")
    super().__init__(*x)

DixonPriceFunction

Bases: OptFunction

Dixon-Price function.

The Dixon-Price function is a multi-dimensional function with a single global minimum.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.valley_shaped import DixonPriceFunction
>>> x = np.linspace(-10, 10, 100)
>>> y = np.linspace(-10, 10, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = DixonPriceFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("DixonPriceFunction.png", dpi=300, transparent=True)
Notes

The Dixon-Price function is defined as:

\[ f(x) = (x_1 - 1)^2 + \sum_{i=2}^n \left[ i(x_i - x_{i-1}^2)^2 \right] \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two-dimensional.

()

Raises:

Type Description
TooSmallDimensionError

If the dimension of the input data is smaller than 2.

Source code in src/umf/functions/optimization/valley_shaped.py
Python
class DixonPriceFunction(OptFunction):
    r"""Dixon-Price function.

    The Dixon-Price function is a multi-dimensional function with a single
    global minimum.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.valley_shaped import DixonPriceFunction
        >>> x = np.linspace(-10, 10, 100)
        >>> y = np.linspace(-10, 10, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = DixonPriceFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("DixonPriceFunction.png", dpi=300, transparent=True)

    Notes:
        The Dixon-Price function is defined as:

        $$
        f(x) = (x_1 - 1)^2 + \sum_{i=2}^n \left[ i(x_i - x_{i-1}^2)^2 \right]
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/dixonpr.html).

    Args:
        *x (UniversalArray): Input data, which has to be two-dimensional.

    Raises:
        TooSmallDimensionError: If the dimension of the input data is smaller than 2.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the Dixon-Price function."""
        if len(x) < __2d__:
            raise TooSmallDimensionError(
                function_name="DixonPrice",
                dimension=__2d__,
                len_x=len(x),
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Dixon-Price function at x."""
        x = self._x

        return (x[0] - 1) ** 2 + sum(
            (i + 1) * (x[i] - x[i - 1] ** 2) ** 2 for i in range(1, len(x))
        )

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the zero function."""
        return MinimaAPI(
            f_x=0.0,
            x=tuple(np.array([2 ** (-i) for i in range(1, len(self._x) + 1)])),
        )

__eval__ property

Evaluate Dixon-Price function at x.

__minima__ property

Return the zero function.

__init__(*x)

Initialize the Dixon-Price function.

Source code in src/umf/functions/optimization/valley_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the Dixon-Price function."""
    if len(x) < __2d__:
        raise TooSmallDimensionError(
            function_name="DixonPrice",
            dimension=__2d__,
            len_x=len(x),
        )
    super().__init__(*x)

ExponentialValleyFunction

Bases: OptFunction

Exponential valley function.

Source code in src/umf/functions/optimization/valley_shaped.py
Python
class ExponentialValleyFunction(OptFunction):
    r"""Exponential valley function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the exponential valley function."""
        _validate_two_dimensional(*x, function_name="ExponentialValley")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the exponential valley function at x."""
        x_1, x_2 = self._x
        return (x_1 + x_2 - 1) ** 2 + np.expm1((x_1 - x_2) ** 2)

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the exponential valley function."""
        return MinimaAPI(f_x=0.0, x=(0.5, 0.5))

__eval__ property

Evaluate the exponential valley function at x.

__minima__ property

Return the minima of the exponential valley function.

__init__(*x)

Initialize the exponential valley function.

Source code in src/umf/functions/optimization/valley_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the exponential valley function."""
    _validate_two_dimensional(*x, function_name="ExponentialValley")
    super().__init__(*x)

RosenbrockFunction

Bases: OptFunction

Rosenbrock function.

The Rosenbrock function is a multi-dimensional function with a single global minimum.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.valley_shaped import RosenbrockFunction
>>> x = np.linspace(-2, 2, 100)
>>> y = np.linspace(-1, 3, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = RosenbrockFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("RosenbrockFunction.png", dpi=300, transparent=True)
Notes

The Rosenbrock function is defined as:

\[ f(x) = \sum_{i=1}^{n-1} \left[ 100(x_{i+1} - x_i^2)^2 + (1 - x_i)^2 \right] \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two-dimensional.

()

Raises:

Type Description
TooSmallDimensionError

If the dimension of the input data is smaller than 2.

Source code in src/umf/functions/optimization/valley_shaped.py
Python
class RosenbrockFunction(OptFunction):
    r"""Rosenbrock function.

    The Rosenbrock function is a multi-dimensional function with a single
    global minimum.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.valley_shaped import RosenbrockFunction
        >>> x = np.linspace(-2, 2, 100)
        >>> y = np.linspace(-1, 3, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = RosenbrockFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("RosenbrockFunction.png", dpi=300, transparent=True)

    Notes:
        The Rosenbrock function is defined as:

        $$
        f(x) = \sum_{i=1}^{n-1} \left[ 100(x_{i+1} - x_i^2)^2 + (1 - x_i)^2 \right]
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/rosen.html).

    Args:
        *x (UniversalArray): Input data, which has to be two-dimensional.

    Raises:
        TooSmallDimensionError: If the dimension of the input data is smaller than 2.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the Rosenbrock function."""
        if len(x) < __2d__:
            raise TooSmallDimensionError(
                function_name="Rosenbrock",
                dimension=__2d__,
                len_x=len(x),
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate Rosenbrock function at x."""
        x = self._x

        return np.array(
            sum(
                100 * (x[i + 1] - x[i] ** 2) ** 2 + (1 - x[i]) ** 2
                for i in range(len(x) - 1)
            ),
        )

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the zero function."""
        return MinimaAPI(
            f_x=0.0,
            x=tuple(np.array([1.0 for _ in range(len(self._x))])),
        )

__eval__ property

Evaluate Rosenbrock function at x.

__minima__ property

Return the zero function.

__init__(*x)

Initialize the Rosenbrock function.

Source code in src/umf/functions/optimization/valley_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the Rosenbrock function."""
    if len(x) < __2d__:
        raise TooSmallDimensionError(
            function_name="Rosenbrock",
            dimension=__2d__,
            len_x=len(x),
        )
    super().__init__(*x)

SinusoidalRosenbrockFunction

Bases: OptFunction

Sinusoidal Rosenbrock-like function.

Source code in src/umf/functions/optimization/valley_shaped.py
Python
class SinusoidalRosenbrockFunction(OptFunction):
    r"""Sinusoidal Rosenbrock-like function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the sinusoidal Rosenbrock function."""
        _validate_two_dimensional(*x, function_name="SinusoidalRosenbrock")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the sinusoidal Rosenbrock function at x."""
        x_1, x_2 = self._x
        return (
            (1 - x_1) ** 2 + 100 * (x_2 - x_1**2) ** 2 + 0.1 * np.sin(np.pi * x_1) ** 2
        )

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the sinusoidal Rosenbrock function."""
        return MinimaAPI(f_x=0.0, x=(1.0, 1.0))

__eval__ property

Evaluate the sinusoidal Rosenbrock function at x.

__minima__ property

Return the minima of the sinusoidal Rosenbrock function.

__init__(*x)

Initialize the sinusoidal Rosenbrock function.

Source code in src/umf/functions/optimization/valley_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the sinusoidal Rosenbrock function."""
    _validate_two_dimensional(*x, function_name="SinusoidalRosenbrock")
    super().__init__(*x)

SixHumpCamelFunction

Bases: OptFunction

Six-hump camel function.

The six-hump camel function is a two-dimensional function with six minima, where two of them are global minima.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.valley_shaped import SixHumpCamelFunction
>>> x = np.linspace(-3, 3, 100)
>>> y = np.linspace(-2, 2, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = SixHumpCamelFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("SixHumpCamelFunction.png", dpi=300, transparent=True)
Notes

The six-hump camel function is defined as:

\[ f(x) = (4 - 2.1x_1^2 + \frac{x_1^4}{3})x_1^2 + x_1x_2 + (-4 + 4x_2^2)x_2^2 \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two-dimensional.

()

Raises:

Type Description
OutOfDimensionError

If the dimension of the input data is not 2.

Source code in src/umf/functions/optimization/valley_shaped.py
Python
class SixHumpCamelFunction(OptFunction):
    r"""Six-hump camel function.

    The six-hump camel function is a two-dimensional function with six
    minima, where two of them are global minima.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.valley_shaped import SixHumpCamelFunction
        >>> x = np.linspace(-3, 3, 100)
        >>> y = np.linspace(-2, 2, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = SixHumpCamelFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("SixHumpCamelFunction.png", dpi=300, transparent=True)

    Notes:
        The six-hump camel function is defined as:

        $$
        f(x) = (4 - 2.1x_1^2 + \frac{x_1^4}{3})x_1^2 + x_1x_2 + (-4 + 4x_2^2)x_2^2
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/camel6.html).

    Args:
        *x (UniversalArray): Input data, which has to be two-dimensional.

    Raises:
        OutOfDimensionError: If the dimension of the input data is not 2.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the six-hump camel function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="SixHumpCamel",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the six-hump camel function at x."""
        x_1 = self._x[0]
        x_2 = self._x[1]
        return (
            (4 - 2.1 * x_1**2 + (x_1**4) / 3) * x_1**2
            + x_1 * x_2
            + (-4 + 4 * x_2**2) * x_2**2
        )

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the six-hump camel function."""
        return MinimaAPI(
            f_x=-1.031628453489877,
            x=tuple(np.array([0.0898, -0.7126], [-0.0898, 0.7126])),
        )

__eval__ property

Evaluate the six-hump camel function at x.

__minima__ property

Return the minima of the six-hump camel function.

__init__(*x)

Initialize the six-hump camel function.

Source code in src/umf/functions/optimization/valley_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the six-hump camel function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="SixHumpCamel",
            dimension=__2d__,
        )
    super().__init__(*x)

ThreeHumpCamelFunction

Bases: OptFunction

Three-hump camel function.

The three-hump camel function is a two-dimensional function with three minima, where one of the minima is a global minimum.

Examples:

Python Console Session
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> from umf.functions.optimization.valley_shaped import ThreeHumpCamelFunction
>>> x = np.linspace(-5, 5, 100)
>>> y = np.linspace(-5, 5, 100)
>>> X, Y = np.meshgrid(x, y)
>>> Z = ThreeHumpCamelFunction(X, Y).__eval__
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection="3d")
>>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
>>> plt.savefig("ThreeHumpCamelFunction.png", dpi=300, transparent=True)
Notes

The three-hump camel function is defined as:

\[ f(x) = 2x_1^2 - 1.05x_1^4 + \frac{x_1^6}{6} + x_1x_2 + x_2^2 \]

Reference: Original implementation can be found here.

Parameters:

Name Type Description Default
*x UniversalArray

Input data, which has to be two-dimensional.

()

Raises:

Type Description
OutOfDimensionError

If the dimension of the input data is not 2.

Source code in src/umf/functions/optimization/valley_shaped.py
Python
class ThreeHumpCamelFunction(OptFunction):
    r"""Three-hump camel function.

    The three-hump camel function is a two-dimensional function with three
    minima, where one of the minima is a global minimum.

    Examples:
        >>> import matplotlib.pyplot as plt
        >>> import numpy as np
        >>> from umf.functions.optimization.valley_shaped import ThreeHumpCamelFunction
        >>> x = np.linspace(-5, 5, 100)
        >>> y = np.linspace(-5, 5, 100)
        >>> X, Y = np.meshgrid(x, y)
        >>> Z = ThreeHumpCamelFunction(X, Y).__eval__
        >>> fig = plt.figure()
        >>> ax = fig.add_subplot(111, projection="3d")
        >>> _ = ax.plot_surface(X, Y, Z, cmap="viridis")
        >>> plt.savefig("ThreeHumpCamelFunction.png", dpi=300, transparent=True)

    Notes:
        The three-hump camel function is defined as:

        $$
        f(x) = 2x_1^2 - 1.05x_1^4 + \frac{x_1^6}{6} + x_1x_2 + x_2^2
        $$

        > Reference: Original implementation can be found
        > [here](https://www.sfu.ca/~ssurjano/camel3.html).

    Args:
        *x (UniversalArray): Input data, which has to be two-dimensional.

    Raises:
        OutOfDimensionError: If the dimension of the input data is not 2.
    """

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the three-hump camel function."""
        if len(x) != __2d__:
            raise OutOfDimensionError(
                function_name="ThreeHumpCamel",
                dimension=__2d__,
            )
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the three-hump camel function at x."""
        x_1 = self._x[0]
        x_2 = self._x[1]
        return 2 * x_1**2 - 1.05 * x_1**4 + (x_1**6) / 6 + x_1 * x_2 + x_2**2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the three-hump camel function."""
        return MinimaAPI(
            f_x=np.array([0.0, 0.0]),
            x=tuple(np.array([0.0])),
        )

__eval__ property

Evaluate the three-hump camel function at x.

__minima__ property

Return the minima of the three-hump camel function.

__init__(*x)

Initialize the three-hump camel function.

Source code in src/umf/functions/optimization/valley_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the three-hump camel function."""
    if len(x) != __2d__:
        raise OutOfDimensionError(
            function_name="ThreeHumpCamel",
            dimension=__2d__,
        )
    super().__init__(*x)

Backward-compatible imports for newly categorized optimization functions.

AbsoluteBowlFunction

Bases: OptFunction

Absolute bowl function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class AbsoluteBowlFunction(OptFunction):
    r"""Absolute bowl function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the absolute bowl function."""
        _validate_two_dimensional(*x, function_name="AbsoluteBowl")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the absolute bowl function at x."""
        x_1, x_2 = self._x
        return np.abs(x_1) + np.abs(x_2)

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the absolute bowl function."""
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the absolute bowl function at x.

__minima__ property

Return the minima of the absolute bowl function.

__init__(*x)

Initialize the absolute bowl function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the absolute bowl function."""
    _validate_two_dimensional(*x, function_name="AbsoluteBowl")
    super().__init__(*x)

CosineMixtureFunction

Bases: OptFunction

Cosine mixture function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
class CosineMixtureFunction(OptFunction):
    r"""Cosine mixture function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the cosine mixture function."""
        _validate_two_dimensional(*x, function_name="CosineMixture")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the cosine mixture function at x."""
        x_1, x_2 = self._x
        return 0.1 * (x_1**2 + x_2**2) + (1 - np.cos(x_1)) + (1 - np.cos(x_2))

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the cosine mixture function."""
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the cosine mixture function at x.

__minima__ property

Return the minima of the cosine mixture function.

__init__(*x)

Initialize the cosine mixture function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the cosine mixture function."""
    _validate_two_dimensional(*x, function_name="CosineMixture")
    super().__init__(*x)

CosineProductSphereFunction

Bases: OptFunction

Cosine-product sphere function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
class CosineProductSphereFunction(OptFunction):
    r"""Cosine-product sphere function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the cosine-product sphere function."""
        _validate_three_or_higher(*x, function_name="CosineProductSphere")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the cosine-product sphere function at x."""
        indices = np.arange(1, self.dimension + 1)
        cosine_term = np.ones_like(self._x[0])
        for index, axis in zip(indices, self._x, strict=True):
            cosine_term *= np.cos(axis / np.sqrt(index))
        return np.array(sum(axis**2 for axis in self._x) - cosine_term + 1)

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the cosine-product sphere function."""
        return MinimaAPI(f_x=0.0, x=tuple(0.0 for _ in range(self.dimension)))

__eval__ property

Evaluate the cosine-product sphere function at x.

__minima__ property

Return the minima of the cosine-product sphere function.

__init__(*x)

Initialize the cosine-product sphere function.

Source code in src/umf/functions/optimization/many_local_minima.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the cosine-product sphere function."""
    _validate_three_or_higher(*x, function_name="CosineProductSphere")
    super().__init__(*x)

CrossQuadraticFunction

Bases: OptFunction

Cross-quadratic function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class CrossQuadraticFunction(OptFunction):
    r"""Cross-quadratic function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the cross-quadratic function."""
        _validate_two_dimensional(*x, function_name="CrossQuadratic")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the cross-quadratic function at x."""
        x_1, x_2 = self._x
        return (x_1 + x_2) ** 2 + (x_1 - x_2) ** 4

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the cross-quadratic function."""
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the cross-quadratic function at x.

__minima__ property

Return the minima of the cross-quadratic function.

__init__(*x)

Initialize the cross-quadratic function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the cross-quadratic function."""
    _validate_two_dimensional(*x, function_name="CrossQuadratic")
    super().__init__(*x)

CubicNormFunction

Bases: OptFunction

Cubic norm function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class CubicNormFunction(OptFunction):
    r"""Cubic norm function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the cubic norm function."""
        _validate_three_or_higher(*x, function_name="CubicNorm")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the cubic norm function at x."""
        return np.array(sum(np.abs(axis) ** 3 for axis in self._x))

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the cubic norm function."""
        return MinimaAPI(f_x=0.0, x=tuple(0.0 for _ in range(self.dimension)))

__eval__ property

Evaluate the cubic norm function at x.

__minima__ property

Return the minima of the cubic norm function.

__init__(*x)

Initialize the cubic norm function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the cubic norm function."""
    _validate_three_or_higher(*x, function_name="CubicNorm")
    super().__init__(*x)

CubicValleyFunction

Bases: OptFunction

Cubic valley function.

Source code in src/umf/functions/optimization/valley_shaped.py
Python
class CubicValleyFunction(OptFunction):
    r"""Cubic valley function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the cubic valley function."""
        _validate_two_dimensional(*x, function_name="CubicValley")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the cubic valley function at x."""
        x_1, x_2 = self._x
        return (x_1 - 1) ** 2 + (x_2 - x_1**3) ** 2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the cubic valley function."""
        return MinimaAPI(f_x=0.0, x=(1.0, 1.0))

__eval__ property

Evaluate the cubic valley function at x.

__minima__ property

Return the minima of the cubic valley function.

__init__(*x)

Initialize the cubic valley function.

Source code in src/umf/functions/optimization/valley_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the cubic valley function."""
    _validate_two_dimensional(*x, function_name="CubicValley")
    super().__init__(*x)

EllipticAbsoluteRootFunction

Bases: OptFunction

Elliptic absolute-root function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class EllipticAbsoluteRootFunction(OptFunction):
    r"""Elliptic absolute-root function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the elliptic absolute-root function."""
        _validate_two_dimensional(*x, function_name="EllipticAbsoluteRoot")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the elliptic absolute-root function at x."""
        x_1, x_2 = self._x
        return np.sqrt(1 + x_1**2) + np.sqrt(1 + x_2**2) - 2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the elliptic absolute-root function."""
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the elliptic absolute-root function at x.

__minima__ property

Return the minima of the elliptic absolute-root function.

__init__(*x)

Initialize the elliptic absolute-root function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the elliptic absolute-root function."""
    _validate_two_dimensional(*x, function_name="EllipticAbsoluteRoot")
    super().__init__(*x)

EllipticParaboloidFunction

Bases: OptFunction

Elliptic paraboloid function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class EllipticParaboloidFunction(OptFunction):
    r"""Elliptic paraboloid function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the elliptic paraboloid function."""
        _validate_two_dimensional(*x, function_name="EllipticParaboloid")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the elliptic paraboloid function at x."""
        x_1, x_2 = self._x
        return x_1**2 + 2 * x_2**2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the elliptic paraboloid function."""
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the elliptic paraboloid function at x.

__minima__ property

Return the minima of the elliptic paraboloid function.

__init__(*x)

Initialize the elliptic paraboloid function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the elliptic paraboloid function."""
    _validate_two_dimensional(*x, function_name="EllipticParaboloid")
    super().__init__(*x)

ExponentialNormFunction

Bases: OptFunction

Exponential norm function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class ExponentialNormFunction(OptFunction):
    r"""Exponential norm function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the exponential norm function."""
        _validate_three_or_higher(*x, function_name="ExponentialNorm")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the exponential norm function at x."""
        squared_norm = np.array(sum(axis**2 for axis in self._x))
        return np.exp(0.5 * squared_norm) - 1

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the exponential norm function."""
        return MinimaAPI(f_x=0.0, x=tuple(0.0 for _ in range(self.dimension)))

__eval__ property

Evaluate the exponential norm function at x.

__minima__ property

Return the minima of the exponential norm function.

__init__(*x)

Initialize the exponential norm function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the exponential norm function."""
    _validate_three_or_higher(*x, function_name="ExponentialNorm")
    super().__init__(*x)

ExponentialValleyFunction

Bases: OptFunction

Exponential valley function.

Source code in src/umf/functions/optimization/valley_shaped.py
Python
class ExponentialValleyFunction(OptFunction):
    r"""Exponential valley function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the exponential valley function."""
        _validate_two_dimensional(*x, function_name="ExponentialValley")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the exponential valley function at x."""
        x_1, x_2 = self._x
        return (x_1 + x_2 - 1) ** 2 + np.expm1((x_1 - x_2) ** 2)

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the exponential valley function."""
        return MinimaAPI(f_x=0.0, x=(0.5, 0.5))

__eval__ property

Evaluate the exponential valley function at x.

__minima__ property

Return the minima of the exponential valley function.

__init__(*x)

Initialize the exponential valley function.

Source code in src/umf/functions/optimization/valley_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the exponential valley function."""
    _validate_two_dimensional(*x, function_name="ExponentialValley")
    super().__init__(*x)

OffsetQuadraticFunction

Bases: OptFunction

Offset quadratic function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class OffsetQuadraticFunction(OptFunction):
    r"""Offset quadratic function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the offset quadratic function."""
        _validate_two_dimensional(*x, function_name="OffsetQuadratic")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the offset quadratic function at x."""
        x_1, x_2 = self._x
        return (x_1 + 1) ** 2 + 3 * (x_2 - 2) ** 2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the offset quadratic function."""
        return MinimaAPI(f_x=0.0, x=(-1.0, 2.0))

__eval__ property

Evaluate the offset quadratic function at x.

__minima__ property

Return the minima of the offset quadratic function.

__init__(*x)

Initialize the offset quadratic function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the offset quadratic function."""
    _validate_two_dimensional(*x, function_name="OffsetQuadratic")
    super().__init__(*x)

QuarticBowlFunction

Bases: OptFunction

Quartic bowl function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class QuarticBowlFunction(OptFunction):
    r"""Quartic bowl function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the quartic bowl function."""
        _validate_two_dimensional(*x, function_name="QuarticBowl")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the quartic bowl function at x."""
        x_1, x_2 = self._x
        return x_1**4 + x_2**4

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the quartic bowl function."""
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the quartic bowl function at x.

__minima__ property

Return the minima of the quartic bowl function.

__init__(*x)

Initialize the quartic bowl function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the quartic bowl function."""
    _validate_two_dimensional(*x, function_name="QuarticBowl")
    super().__init__(*x)

RippleBowlFunction

Bases: OptFunction

Ripple bowl function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class RippleBowlFunction(OptFunction):
    r"""Ripple bowl function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the ripple bowl function."""
        _validate_two_dimensional(*x, function_name="RippleBowl")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the ripple bowl function at x."""
        x_1, x_2 = self._x
        return x_1**2 + x_2**2 + 0.1 * np.sin(3 * x_1) ** 2 + 0.1 * np.sin(3 * x_2) ** 2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the ripple bowl function."""
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the ripple bowl function at x.

__minima__ property

Return the minima of the ripple bowl function.

__init__(*x)

Initialize the ripple bowl function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the ripple bowl function."""
    _validate_two_dimensional(*x, function_name="RippleBowl")
    super().__init__(*x)

RotatedQuadraticFunction

Bases: OptFunction

Rotated quadratic function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class RotatedQuadraticFunction(OptFunction):
    r"""Rotated quadratic function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the rotated quadratic function."""
        _validate_two_dimensional(*x, function_name="RotatedQuadratic")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the rotated quadratic function at x."""
        x_1, x_2 = self._x
        return x_1**2 + x_1 * x_2 + x_2**2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the rotated quadratic function."""
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the rotated quadratic function at x.

__minima__ property

Return the minima of the rotated quadratic function.

__init__(*x)

Initialize the rotated quadratic function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the rotated quadratic function."""
    _validate_two_dimensional(*x, function_name="RotatedQuadratic")
    super().__init__(*x)

SaddleSuppressedFunction

Bases: OptFunction

Saddle-suppressed function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class SaddleSuppressedFunction(OptFunction):
    r"""Saddle-suppressed function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the saddle-suppressed function."""
        _validate_two_dimensional(*x, function_name="SaddleSuppressed")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the saddle-suppressed function at x."""
        x_1, x_2 = self._x
        return (x_1**2 - x_2**2) ** 2 + 0.1 * (x_1**2 + x_2**2)

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the saddle-suppressed function."""
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the saddle-suppressed function at x.

__minima__ property

Return the minima of the saddle-suppressed function.

__init__(*x)

Initialize the saddle-suppressed function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the saddle-suppressed function."""
    _validate_two_dimensional(*x, function_name="SaddleSuppressed")
    super().__init__(*x)

ShiftedHyperSphereFunction

Bases: OptFunction

Shifted hypersphere function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class ShiftedHyperSphereFunction(OptFunction):
    r"""Shifted hypersphere function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the shifted hypersphere function."""
        _validate_three_or_higher(*x, function_name="ShiftedHyperSphere")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the shifted hypersphere function at x."""
        return np.array(sum((axis - 1) ** 2 for axis in self._x))

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the shifted hypersphere function."""
        return MinimaAPI(f_x=0.0, x=tuple(1.0 for _ in range(self.dimension)))

__eval__ property

Evaluate the shifted hypersphere function at x.

__minima__ property

Return the minima of the shifted hypersphere function.

__init__(*x)

Initialize the shifted hypersphere function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the shifted hypersphere function."""
    _validate_three_or_higher(*x, function_name="ShiftedHyperSphere")
    super().__init__(*x)

ShiftedSphere2DFunction

Bases: OptFunction

Shifted 2D sphere function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class ShiftedSphere2DFunction(OptFunction):
    r"""Shifted 2D sphere function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the shifted 2D sphere function."""
        _validate_two_dimensional(*x, function_name="ShiftedSphere2D")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the shifted 2D sphere function at x."""
        x_1, x_2 = self._x
        return (x_1 - 2) ** 2 + (x_2 + 1) ** 2

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the shifted 2D sphere function."""
        return MinimaAPI(f_x=0.0, x=(2.0, -1.0))

__eval__ property

Evaluate the shifted 2D sphere function at x.

__minima__ property

Return the minima of the shifted 2D sphere function.

__init__(*x)

Initialize the shifted 2D sphere function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the shifted 2D sphere function."""
    _validate_two_dimensional(*x, function_name="ShiftedSphere2D")
    super().__init__(*x)

SinusoidalRosenbrockFunction

Bases: OptFunction

Sinusoidal Rosenbrock-like function.

Source code in src/umf/functions/optimization/valley_shaped.py
Python
class SinusoidalRosenbrockFunction(OptFunction):
    r"""Sinusoidal Rosenbrock-like function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the sinusoidal Rosenbrock function."""
        _validate_two_dimensional(*x, function_name="SinusoidalRosenbrock")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the sinusoidal Rosenbrock function at x."""
        x_1, x_2 = self._x
        return (
            (1 - x_1) ** 2 + 100 * (x_2 - x_1**2) ** 2 + 0.1 * np.sin(np.pi * x_1) ** 2
        )

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the sinusoidal Rosenbrock function."""
        return MinimaAPI(f_x=0.0, x=(1.0, 1.0))

__eval__ property

Evaluate the sinusoidal Rosenbrock function at x.

__minima__ property

Return the minima of the sinusoidal Rosenbrock function.

__init__(*x)

Initialize the sinusoidal Rosenbrock function.

Source code in src/umf/functions/optimization/valley_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the sinusoidal Rosenbrock function."""
    _validate_two_dimensional(*x, function_name="SinusoidalRosenbrock")
    super().__init__(*x)

SumAndProductFunction

Bases: OptFunction

Sum-and-product function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class SumAndProductFunction(OptFunction):
    r"""Sum-and-product function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the sum-and-product function."""
        _validate_three_or_higher(*x, function_name="SumAndProduct")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the sum-and-product function at x."""
        sum_term = np.array(sum(np.abs(axis) for axis in self._x))
        product_term = np.ones_like(self._x[0])
        for axis in self._x:
            product_term *= np.abs(axis) + 1
        return sum_term + product_term - 1

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the sum-and-product function."""
        return MinimaAPI(f_x=0.0, x=tuple(0.0 for _ in range(self.dimension)))

__eval__ property

Evaluate the sum-and-product function at x.

__minima__ property

Return the minima of the sum-and-product function.

__init__(*x)

Initialize the sum-and-product function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the sum-and-product function."""
    _validate_three_or_higher(*x, function_name="SumAndProduct")
    super().__init__(*x)

WeightedL1L2Function

Bases: OptFunction

Weighted mixed-norm function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
class WeightedL1L2Function(OptFunction):
    r"""Weighted mixed-norm function."""

    def __init__(self, *x: UniversalArray) -> None:
        """Initialize the weighted mixed-norm function."""
        _validate_two_dimensional(*x, function_name="WeightedL1L2")
        super().__init__(*x)

    @property
    def __eval__(self) -> UniversalArray:
        """Evaluate the weighted mixed-norm function at x."""
        x_1, x_2 = self._x
        return x_1**2 + x_2**2 + np.abs(x_1 + x_2)

    @property
    def __minima__(self) -> MinimaAPI:
        """Return the minima of the weighted mixed-norm function."""
        return MinimaAPI(f_x=0.0, x=(0.0, 0.0))

__eval__ property

Evaluate the weighted mixed-norm function at x.

__minima__ property

Return the minima of the weighted mixed-norm function.

__init__(*x)

Initialize the weighted mixed-norm function.

Source code in src/umf/functions/optimization/bowl_shaped.py
Python
def __init__(self, *x: UniversalArray) -> None:
    """Initialize the weighted mixed-norm function."""
    _validate_two_dimensional(*x, function_name="WeightedL1L2")
    super().__init__(*x)