skopt.space.space.Space

class skopt.space.space.Space(dimensions)[source][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 (for Real or Integer dimensions),

  • a (lower_bound, upper_bound, "prior") tuple (for Real dimensions),

  • as a list of categories (for Categorical dimensions), or

  • an instance of a Dimension object (Real, Integer or Categorical).

Note

The upper and lower bounds are inclusive for Integer dimensions.

Attributes
bounds

The dimension bounds, in the original space.

is_categorical

Space contains exclusively categorical dimensions

is_partly_categorical

Space contains any categorical dimensions

is_real

Returns true if all dimensions are Real

n_dims

The dimensionality of the original space.

transformed_bounds

The dimension bounds, in the warped space.

transformed_n_dims

The dimensionality of the warped space.

Methods

distance(self, point_a, point_b)

Compute distance between two points in this space.

from_yaml(yml_path[, namespace])

Create Space from yaml configuration file

inverse_transform(self, Xt)

Inverse transform samples from the warped space back to the

rvs(self[, n_samples, random_state])

Draw random samples.

transform(self, X)

Transform samples from the original space into a warped space.

__init__(self, dimensions)[source][source]

Initialize self. See help(type(self)) for accurate signature.

property bounds

The dimension bounds, in the original space.

distance(self, point_a, point_b)[source][source]

Compute distance between two points in this space.

Parameters
point_aarray

First point.

point_barray

Second point.

classmethod from_yaml(yml_path, namespace=None)[source][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(self, Xt)[source][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_dims

The dimensionality of the original space.

rvs(self, n_samples=1, random_state=None)[source][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.

transform(self, X)[source][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.