optilab.data_classes package
Submodules
optilab.data_classes.bounds module
Class representing bounds of the search space.
- class Bounds(lower: float, upper: float)[source]
Bases:
objectClass representing bounds of the search space.
- lower: float
The lower bound of search space.
- upper: float
The upper bound of search space.
- to_list() List[float][source]
Return the bounds as a list of two floats.
- Returns:
List containing the lower and upper bound.
- __len__() float[source]
Returns the width of the search space - the distance between the lower and upper bound.
- Returns:
The width of the search space.
- __str__() str[source]
Express the bounds as a string.
- Returns:
Simple, printable string representation of this object.
- is_valid() bool[source]
Check if the bounds are valid, i.e. if lower bound is below upper bound.
- Returns:
True if bounds are valid, false otherwise.
- __contains__(point: Point) bool[source]
Check if a point lies in the bounds. This method overrides the “in” operator.
- Returns:
True if point lies in the bounds.
- random_point(dim: int) Point[source]
Sample the bounds for a random point of given dimensionality.
- Parameters:
dim – The dimensionality of the point.
- Returns:
Randomly sampled point from the search space.
- random_point_list(num_points: int, dim: int) PointList[source]
Sample the bounds for a list of random points of given dimensionality.
- Parameters:
num_points – The number of points to sample.
dim – The dimensionality of the points.
- Returns:
List of randomly sampled points from the search space.
- reflect(point: Point) Point[source]
Handle bounds by reflecting the point back into the search area.
- Parameters:
point – The point to handle.
- Returns:
Reflected point.
- wrap(point: Point) Point[source]
Handle bounds by wrapping the point around the search area.
- Parameters:
point – The point to handle.
- Returns:
Wrapped point.
optilab.data_classes.function_metadata module
Metadata of objective function.
optilab.data_classes.optimization_run module
Class containing information about an optimization run.
- class OptimizationRun(model_metadata: OptimizerMetadata, function_metadata: FunctionMetadata, bounds: Bounds, tolerance: float, logs: List[PointList])[source]
Bases:
objectDataclass containing information about an optimization run.
- model_metadata: OptimizerMetadata
Metadata describing the model used in optimization.
- function_metadata: FunctionMetadata
Metadata describing the optimized function.
- tolerance: float
Tolerated error value to stop the search.
- bests_y(raw_values: bool = False) List[float][source]
Get a list of best y values from each log.
- Parameters:
raw_values – If false, values below tolerance values are set to tolerance, else return real y values. Default is false.
- Returns:
List of the best values from each log.
optilab.data_classes.optimizer_metadata module
Metadata of an optimizer model.
- class OptimizerMetadata(name: str, population_size: int, hyperparameters: Dict[str, Any] | None = None)[source]
Bases:
objectMetadata of an optimizer model.
- name: str
Name of the optimizer.
- population_size: int
Number of points generated in each generation.
- hyperparameters: Dict[str, Any] | None = None
Other hyperparameters of the optimizer, optional.
optilab.data_classes.point module
Point dataclass, representing a point in the search space.
- class Point(x: ndarray | None, y: float | None = None, is_evaluated: bool = False)[source]
Bases:
objectPoint dataclass, representing a point in the search space.
- x: 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.
- dim() int[source]
Return the dimensionality of the point.
- Returns:
Dimensionality of the point, equal to length of x.
optilab.data_classes.point_list module
Class holding a list of points.
- class PointList(points: List[Point])[source]
Bases:
objectClass holding a list of points. Might be used as optimization run result log or as a train set for surrogate function.
- classmethod from_list(xs: List[ndarray]) PointList[source]
Alternative constructor that takes a list of x values.
- Parameters:
xs – List of x values.
- Returns:
Object of class PointList containing points with given x.
- append(new_point: Point) None[source]
Add new point to the list.
- Parameters:
new_point – Point to append to this object.
- extend(new_points: PointList) None[source]
Append a list of points to this PointList.
- Parameters:
new_points – A list of point to append to this object.
- x() ndarray[source]
Get all x values of points in this list.
- Returns:
List containing x values of all points.
- y() ndarray[source]
Get all y values of points in this list.
- Returns:
List of y values of all points.
- pairs() Tuple[ndarray, ndarray][source]
Return the contents of this point list as list of x and list of y values. This is potentially useful for quickly accesing point values for training surrofates.
- Returns:
Lists of x and y values.
- only_evaluated() PointList[source]
Return list of only those points that have been evaluated.
- Returns:
List containing evaluated points.
- __getitem__(index: int | slice) Point | PointList[source]
Allows indexing and slicing this object like a list.
- Parameters:
index – The index or slice of objects to fetch.
- Returns:
- A single Point object for integer index,
or a new PointList instance for slicing.
- __len__() int[source]
Return number of points stored in the list.
- Returns:
Number of points stored in the list.
- rank(*, reverse: bool = False) None[source]
Sort points by y value in place ascending.
- Parameters:
reverse – If true, sorting is done descending. Default False.
- x_difference(other) PointList[source]
Return list of points in self that do not appear in other based on their x values.
- Parameters:
other – Another PointList to compare against.
- Returns:
List of points in self that are not in other.
- remove_x() None[source]
Set x values of points to None. This is done to save memory since xs are rarely used.
- best() Point[source]
Get the best point by y value from the PointList.
- Returns:
The Point with the lowest y value in the list.
- best_index() int[source]
Get the index of the best point by y value in the PointList.
- Returns:
The index of the point with the lowest y value.
Module contents
Classes used for data exchange.