Developer API for design spaces¶
- class smt.utils.design_space.BaseDesignSpace(design_variables: List[DesignVariable] = None)[source]¶
Interface for specifying (hierarchical) design spaces.
This class itself only specifies the functionality that any design space definition should implement: - a way to specify the design variables, their types, and their bounds or options - a way to correct a set of design vectors such that they satisfy all design space hierarchy constraints - a way to query which design variables are acting for a set of design vectors - a way to impute a set of design vectors such that non-acting design variables are assigned some default value - a way to sample n valid design vectors from the design space
If you want to actually define a design space, use the DesignSpace class!
Note that the correction, querying, and imputation mechanisms should all be implemented in one function (correct_get_acting), as usually these operations are tightly related.
- Attributes:
- design_variables
is_all_cont
Whether or not the space is continuous
is_cat_mask
Boolean mask specifying for each design variable whether it is a categorical variable
is_conditionally_acting
Boolean mask specifying for each design variable whether it is conditionally acting (can be non-acting)
n_dv
Get the number of design variables
Methods
correct_get_acting
(x)Correct the given matrix of design vectors and return the corrected vectors and the is_acting matrix.
decode_values
(x[, i_dv])Return decoded values: converts ordinal and categorical back to their original values.
fold_x
(x[, is_acting, fold_mask])Fold x and optionally is_acting.
get_num_bounds
()Get bounds for the design space.
get_unfolded_num_bounds
()Get bounds for the unfolded continuous space.
get_x_limits
()Returns the variable limit definitions in SMT < 2.0 style
sample_valid_x
(n[, unfolded, random_state])Sample n design vectors and additionally return the is_acting matrix.
unfold_x
(x[, is_acting, fold_mask])Unfold x and optionally is_acting.
- _get_design_variables() List[DesignVariable] [source]¶
Return the design variables defined in this design space if not provided upon initialization of the class
- _is_conditionally_acting() ndarray [source]¶
Return for each design variable whether it is conditionally acting or not. A design variable is conditionally acting if it MAY be non-acting.
- Returns:
- is_conditionally_acting: np.ndarray [dim]
Boolean vector specifying for each design variable whether it is conditionally acting
- _correct_get_acting(x: ndarray) Tuple[ndarray, ndarray] [source]¶
Correct the given matrix of design vectors and return the corrected vectors and the is_acting matrix.
- Parameters:
- x: np.ndarray [n_obs, dim]
Input variables
- Returns:
- x_corrected: np.ndarray [n_obs, dim]
Corrected and imputed input variables
- is_acting: np.ndarray [n_obs, dim]
Boolean matrix specifying for each variable whether it is acting or non-acting
- _sample_valid_x(n: int, random_state=None) Tuple[ndarray, ndarray] [source]¶
Sample n design vectors and additionally return the is_acting matrix.
- Returns:
- x: np.ndarray [n, dim]
Valid design vectors
- is_acting: np.ndarray [n, dim]
Boolean matrix specifying for each variable whether it is acting or non-acting