vopy.design_space
- class vopy.design_space.DesignSpace
Abstract base class for design spaces.
This class defines the interface for design spaces, which are used to represent the space of possible designs in an optimization problem. Subclasses must implement the update method to update the design space based on a given model.
Discrete Design Spaces
- class vopy.design_space.DiscreteDesignSpace
Represents a design space that consists of dicrete points.
This class is an abstract implementation of the DesignSpace abstract base class. It represents a design space where the points are discrete. The class also maintains a list of confidence regions associated with the design points.
A derived class must define the following attributes:
points
:np.ndarray
confidence_regions
:list[ConfidenceRegion]
- locate_points(x: numpy.ndarray, atol: float = 1e-06) list[int]
Find indices of points given as x in the design space.
This method finds the indices of the points given as x in the design space. Instead of exact equality, the method uses np.allclose for tolerated comparisons. If any of the distances to the points found is larger than atol, an error is raised.
- Parameters:
x (np.ndarray) – An array of points to locate in the design space.
atol (float) – The absolute tolerance parameter, defaults to \(1e-6\).
- Returns:
A list of indices representing the positions of the points in the design space.
- Return type:
list[int]
- Raises:
ValueError – If any of the distances to the points found is larger than the specified tolerance.
FixedPointsDesignSpace
- class vopy.design_space.FixedPointsDesignSpace(points: numpy.ndarray, objective_dim: int, confidence_type: Literal['hyperrectangle', 'hyperellipsoid'] = 'hyperrectangle')
Represents a design space that has fixed number points.
This class is a concrete implementation of the DiscreteDesignSpace abstract class. It represents a design space where the points are fixed and does not get updated.
- Parameters:
points (np.ndarray) – An array representing the points in the design space.
objective_dim (int) – The dimension of the objective space.
confidence_type (str) – The type of confidence region to use. Can be “hyperrectangle” or “hyperellipsoid”, defaults to “hyperrectangle”.
- Raises:
NotImplementedError – If an unsupported confidence type is provided.
- update(model: Model, scale: numpy.ndarray, indices_to_update: list | None = None)
Update the confidence regions based on the given model and scale.
This method updates the confidence regions for the specified points in the design space based on the predictions from the given model and the provided scale.
- Parameters:
model (Model) – The model used to predict the means and covariances for the points.
scale (np.ndarray) – An array representing the scale for each objective. Can be a scalar, a vector with size output dim, or a 2D array with shape (N_indices, output dim).
indices_to_update (Optional[list]) – A list of indices of the points to update. If None, all points are updated. Defaults to None.
- Raises:
AssertionError – If the shape of the scale array is invalid.
AdaptivelyDiscretizedDesignSpace
- class vopy.design_space.AdaptivelyDiscretizedDesignSpace(domain_dim: int, objective_dim: int, delta: float, max_depth: int, confidence_type: Literal['hyperrectangle'] = 'hyperrectangle')
Represents an adaptively discretized design space.
This class is a concrete implementation of the DiscreteDesignSpace class. It represents a design space where the domain is adaptively discretized based on a given model. The class maintains a list of points in a tree like structure as a representation of the design space, and allows for refinement of the design space based on the model’s predictions. Note that the design space is assumed to be the unit hypercube.
- Parameters:
domain_dim (int) – The dimension of the input space.
objective_dim (int) – The dimension of the objective space.
delta (float) – Determines confidence level for the confidence regions.
max_depth (int) – The maximum depth for the adaptive discretization. Number of points increases exponentially with depth.
confidence_type (Literal["hyperrectangle"]) – The type of confidence region to use, defaults to “hyperrectangle”.
- Raises:
NotImplementedError – If an unsupported confidence type is provided. Currently, only the “hyperrectangle” confidence type is supported.
- calculate_design_vh(model: GPModel, design_index: int, depth_offset: int = 0) numpy.ndarray
Calculate the Vh value for the design at the specified index.
This method calculates the Vh value for the design at the specified index based on the model’s predictions and the depth offset. Vh value is a measure of the uncertainty for the design point depending on its depth.
- Parameters:
model (GPModel) – The model used to predict the means and covariances for the points.
design_index (int) – The index of the design to calculate the Vh value for.
depth_offset (int) – The depth offset for the calculation, defaults to 0. If given as -1, the Vh value is calculated for the parent design.
- Returns:
The calculated Vh value.
- Return type:
np.ndarray
- Raises:
ValueError – If a value for the kernel type of the model is not defined.
- generate_child_designs(design_index: int) list
Generate child designs for the specified design index.
This method generates child designs for the specified design index by splitting the design along each dimension and creating new designs at the midpoints.
- Parameters:
design_index (int) – The index of the design to generate child designs for.
- Returns:
A list of indices representing the new child designs.
- Return type:
list
- refine_design(index_to_refine: int) list
Refine the design space by generating child designs for the point specified by its index index_to_refine.
This method generates child designs for the specified index in the design space, effectively refining the design space.
- Parameters:
index_to_refine (int) – The index of the design to refine.
- Returns:
A list of indices representing the new child designs.
- Return type:
list
- should_refine_design(model: GPModel, design_index: int, scale: numpy.ndarray) bool
Determine whether the design at the specified index should be refined.
This method determines whether the design at the specified index should be refined based on the model’s predictions and the provided scale.
- Parameters:
model (GPModel) – The model used to predict the means and covariances for the points.
design_index (int) – The index of the design to check for refinement.
scale (np.ndarray) – An array representing the scale for each objective. Can be a scalar and a vector with size output dim.
- Returns:
True if the design should be refined, False otherwise.
- Return type:
bool
- update(model: GPModel, scale: numpy.ndarray, indices_to_update: list | None = None)
Update the confidence regions based on the given model and scale.
This method updates the confidence regions for the specified points in the design space based on the predictions from the given model and the provided scale.
- Parameters:
model (GPModel) – The model used to predict the means and covariances for the points.
scale (np.ndarray) – An array representing the scale for each objective. Can be a scalar, a vector with size output dim, or a 2D array with shape (N_indices, output dim).
indices_to_update (Optional[list]) – A list of indices of the points to update. If None, all points are updated. Defaults to None.
- Raises:
AssertionError – If the shape of the scale array is invalid.
- visualize_design_space(path: str | PathLike | None = None)
Visualize the design space’s current cell structure.
This method visualizes the cells that are defined by their centers at self.points and their bounds at self.cells. It uses Matplotlib to create a plot of the design space.
- Parameters:
path (Optional[Union[str, PathLike]]) – The path to save the plot to. If not provided, the plot will only be displayed. Defaults to None.
- Returns:
The Matplotlib figure object containing the plot.
- Return type:
plt.Figure