function.so.sphere

function.so.sphere(X)

N-dimensional Sphere function.

The Sphere function is a simple test function for optimization algorithms. It is characterized by a parabolic-shaped valley. The global minimum is inside the valley and is easy to find for many algorithms.

For the 2D case

f(x, y) = x^2 + y^2

The generalized form for N dimensions

f(X) = sum_{i=1}^{N} x_i^2

Parameters

Name Type Description Default
X array - like Input points with shape (n_samples, n_features) or (n_features,). Can be a 1D array for a single point or 2D array for multiple points. required

Returns

Name Type Description
np.ndarray np.ndarray: Function values at the input points with shape (n_samples,).

Raises

Name Type Description
ValueError If X has fewer than 1 dimension.

Note

  • Global minimum: f(0, 0, …, 0) = 0
  • Typical search domain: [-5, 10]^N or [-2, 2]^N
  • Characteristics: Convex, unimodal

Examples

from spotoptim.function import sphere
import numpy as np
X = np.array([1.0, 1.0])
sphere(X)
array([2.])
from spotoptim.function import sphere
import numpy as np
X = np.array([[0.0, 0.0], [1.0, 1.0], [0.5, 0.5]])
sphere(X)
array([0. , 2. , 0.5])