function.forr08a.branin

function.forr08a.branin(x)

Branin’s test function that takes a 2D input vector x in the range [0, 1] for each dimension and returns the corresponding scalar function value. The function is vectorized to handle multiple inputs.

The function is defined as

f(x) = a * (X2 - b * X1^2 + c * X1 - d)^2 + e * (1 - ff) * cos(X1) + e + 5 * x1

where: X1 = 15 * x1 - 5 X2 = 15 * x2

Parameters

Name Type Description Default
x np.ndarray A 2D NumPy array of shape (n_samples, 2) where each row is a 2D input vector. required

Returns

Name Type Description
np.ndarray np.ndarray: The calculated function values for the input x.

Raises

Name Type Description
ValueError If x does not have exactly 2 columns or if any value in x is outside the range [0, 1].

Examples

>>> import numpy as np
>>> from spotpython.surrogate.functions.forr08a import branin
>>> # Single input
>>> print(branin(np.array([[0.5, 0.5]])))
[26.63]
>>> # Multiple inputs
>>> x = np.array([[0.0, 0.0], [0.25, 0.25], [0.5, 0.5], [0.75, 0.75], [1.0, 1.0]])
>>> print(branin(x))
[308.1291, 34.0028, 26.63, 126.3879, 150.8722]