"""
Point dataclass, representing a point in the search space.
"""
from dataclasses import dataclass
import numpy as np
[docs]
@dataclass
class Point:
"""
Point dataclass, representing a point in the search space.
"""
x: np.ndarray | None
"1D vector representing the point from the search space"
y: float | None = None
"Function value for this point."
is_evaluated: bool = False
"Wheather the value was generated by the objective function."
[docs]
def __post_init__(self):
"""
Post init hook to ensure that the x value is float 64.
"""
if self.x is not None:
self.x = np.asarray(self.x, dtype=np.float64)
[docs]
def dim(self) -> int:
"""
Return the dimensionality of the point.
Returns:
Dimensionality of the point, equal to length of x.
"""
return len(self.x)
[docs]
def remove_x(self) -> None:
"""
Set x to None. This is done mostly to save memory and storage space since x is rarely used.
"""
self.x = None
[docs]
def __eq__(self, other) -> bool:
"""
Compare with other point. Points are considered equal if their x values are equal.
Other properites are not compared.
Args:
other: Another instance of Point class.
Returns:
True if x values of self and other are equal, False otherwise.
"""
return np.array_equal(self.x, other.x)