skopt.space.space.Space#
- class skopt.space.space.Space(dimensions, constraint=None)[source]#
Initialize a search space from given specifications.
- Parameters:
- dimensionslist, shape=(n_dims,)
List of search space dimensions. Each search dimension can be defined either as
a
(lower_bound, upper_bound)tuple (forRealorIntegerdimensions),a
(lower_bound, upper_bound, "prior")tuple (forRealdimensions),as a list of categories (for
Categoricaldimensions), oran instance of a
Dimensionobject (Real,IntegerorCategorical).
Note
The upper and lower bounds are inclusive for
Integerdimensions.- constraintcallable or None, default: None
Constraint function. Should take a single list of parameters (i.e. a point in space) and return True if the point satisfies the constraints. If None, the space is not conditionally constrained.
- Attributes:
boundsThe dimension bounds, in the original space.
dimension_namesNames of all the dimensions in the search-space.
is_categoricalSpace contains exclusively categorical dimensions.
is_partly_categoricalSpace contains any categorical dimensions.
is_realReturns true if all dimensions are Real.
n_constant_dimensionsReturns the number of constant dimensions which have zero degree of freedom, e.g.
n_dimsThe dimensionality of the original space.
transformed_boundsThe dimension bounds, in the warped space.
transformed_n_dimsThe dimensionality of the warped space.
Methods
distance(point_a, point_b)Compute distance between two points in this space.
from_df(df[, priors, bases, transforms])Create Space from Pandas DataFrame object.
from_yaml(yml_path[, namespace])Create Space from yaml configuration file.
Returns all transformers as list.
Inverse transform samples from the warped space back to the original space.
rvs([n_samples, random_state])Draw random samples.
set_transformer(transform)Sets the transformer of all dimension objects to
transformset_transformer_by_type(transform, dim_type)Sets the transformer of
dim_typeobjects totransformtransform(X)Transform samples from the original space into a warped space.
- property bounds#
The dimension bounds, in the original space.
- property dimension_names#
Names of all the dimensions in the search-space.
- distance(point_a, point_b)[source]#
Compute distance between two points in this space.
- Parameters:
- point_aarray
First point.
- point_barray
Second point.
- classmethod from_df(df, priors=None, bases=None, transforms=None)[source]#
Create Space from Pandas DataFrame object. Dimensions will be inferred from the column type in the Pandas DataFrame. Real and Integer dimensions will be set from the minimum and maximum of their corresponding columns. Category dimensions will be constructed from the unique values present in the column. Note: requires
pandasinstallation. :param df: A PandasDataFrameobject :type df:pandas.DataFrame:param priors: A mapping ofDataFramecolumn names to corresponding priors :type priors: dict, default=None :param bases: A mapping ofDataFramecolumn names to corresponding bases :type bases: dict, default=None :param transforms: A mapping ofDataFramecolumn names to corresponding transforms :type transforms: dict, default=None- Returns:
space – Instantiated Space object
- Return type:
- classmethod from_yaml(yml_path, namespace=None)[source]#
Create Space from yaml configuration file.
- Parameters:
- yml_pathstr
Full path to yaml configuration file, example YaML below: Space:
Integer: low: -5 high: 5
Categorical: categories: - a - b
Real: low: 1.0 high: 5.0 prior: log-uniform
- namespacestr, default=None
Namespace within configuration file to use, will use first namespace if not provided
- Returns:
- spaceSpace
Instantiated Space object
- inverse_transform(Xt)[source]#
Inverse transform samples from the warped space back to the original space.
- Parameters:
- Xtarray of floats, shape=(n_samples, transformed_n_dims)
The samples to inverse transform.
- Returns:
- Xlist of lists, shape=(n_samples, n_dims)
The original samples.
- property is_categorical#
Space contains exclusively categorical dimensions.
- property is_partly_categorical#
Space contains any categorical dimensions.
- property is_real#
Returns true if all dimensions are Real.
- property n_constant_dimensions#
Returns the number of constant dimensions which have zero degree of freedom, e.g. an Integer dimensions with (0., 0.) as bounds.
- property n_dims#
The dimensionality of the original space.
- rvs(n_samples=1, random_state=None)[source]#
Draw random samples.
The samples are in the original space. They need to be transformed before being passed to a model or minimizer by
space.transform().- Parameters:
- n_samplesint, default=1
Number of samples to be drawn from the space.
- random_stateint, RandomState instance, or None (default)
Set random state to something other than None for reproducible results.
- Returns:
- pointslist of lists, shape=(n_points, n_dims)
Points sampled from the space.
- set_transformer(transform)[source]#
Sets the transformer of all dimension objects to
transform- Parameters:
- transformstr or list of str
Sets all transformer,, when
transformis a string. Otherwise, transform must be a list with strings with the same length asdimensions
- set_transformer_by_type(transform, dim_type)[source]#
Sets the transformer of
dim_typeobjects totransform- Parameters:
- transformstr
Sets all transformer of type
dim_typetotransform- dim_typetype
- Can be
skopt.space.Real,skopt.space.Integeror skopt.space.Categorical
- Can be
- transform(X)[source]#
Transform samples from the original space into a warped space.
- Note: this transformation is expected to be used to project samples
into a suitable space for numerical optimization.
- Parameters:
- Xlist of lists, shape=(n_samples, n_dims)
The samples to transform.
- Returns:
- Xtarray of floats, shape=(n_samples, transformed_n_dims)
The transformed samples.
- property transformed_bounds#
The dimension bounds, in the warped space.
- property transformed_n_dims#
The dimensionality of the warped space.