Source code for optilab.functions.unimodal.sphere_function

"""
Sphere function. y is the sum of squares of elements of x vector.
"""

from ...data_classes import Point
from ..objective_function import ObjectiveFunction


[docs] class SphereFunction(ObjectiveFunction): """ Sphere function. y is the sum of squares of elements of x vector. """
[docs] def __init__(self, dim: int): """ Class constructor. Args: dim: Dimensionality of the function. """ super().__init__("sphere", dim)
[docs] def __call__(self, point: Point) -> Point: """ Evaluate a single point with the objective function. Args: point: Point to evaluate. Raises: ValueError: If dimensionality of x doesn't match self.dim. Returns: Evaluated point. """ super().__call__(point) return Point( x=point.x, y=sum(point.x**2), is_evaluated=True, )