SubspaceContinuous

class baybe.searchspace.continuous.SubspaceContinuous[source]

Bases: SerialMixin

Class for managing continuous subspaces.

Builds the subspace from parameter definitions, keeps track of search metadata, and provides access to candidate sets and different parameter views.

Public methods

__init__(parameters[, constraints_lin_eq, ...])

Method generated by attrs for class SubspaceContinuous.

empty()

Create an empty continuous subspace.

from_bounds(bounds)

Create a hyperrectangle-shaped continuous subspace with given bounds.

from_dataframe(df[, parameters])

Create a hyperrectangle-shaped continuous subspace from a dataframe.

from_dict(dictionary)

Create an object from its dictionary representation.

from_json(string)

Create an object from its JSON representation.

from_parameter(parameter)

Create a subspace from a single parameter.

from_product(parameters[, constraints])

See baybe.searchspace.core.SearchSpace.

get_parameters_by_name(names)

Return parameters with the specified names.

sample_from_full_factorial([batch_size])

Draw parameter configurations from the full factorial of the space.

sample_uniform([batch_size])

Draw uniform random parameter configurations from the continuous space.

samples_full_factorial([n_points])

Deprecated!

samples_random([n_points])

Deprecated!

to_dict()

Create an object's dictionary representation.

to_json()

Create an object's JSON representation.

to_searchspace()

Turn the subspace into a search space with no discrete part.

transform([df, allow_missing, allow_extra, data])

See baybe.searchspace.core.SearchSpace.transform().

Public attributes and properties

parameters

The parameters of the subspace.

constraints_lin_eq

Linear equality constraints.

constraints_lin_ineq

Linear inequality constraints.

constraints_nonlin

Nonlinear constraints.

constraints_cardinality

Cardinality constraints.

full_factorial

Get the full factorial of the continuous space.

is_empty

Return whether this subspace is empty.

param_bounds_comp

Return bounds as numpy array.

param_names

Return list of parameter names.

__init__(parameters: Sequence, constraints_lin_eq: Sequence = NOTHING, constraints_lin_ineq: Sequence = NOTHING, constraints_nonlin: Sequence = NOTHING)

Method generated by attrs for class SubspaceContinuous.

For details on the parameters, see Public attributes and properties.

classmethod empty()[source]

Create an empty continuous subspace.

Return type:

SubspaceContinuous

classmethod from_bounds(bounds: DataFrame)[source]

Create a hyperrectangle-shaped continuous subspace with given bounds.

Parameters:

bounds (DataFrame) – The bounds of the parameters.

Return type:

SubspaceContinuous

Returns:

The constructed subspace.

classmethod from_dataframe(df: DataFrame, parameters: Sequence[ContinuousParameter] | None = None)[source]

Create a hyperrectangle-shaped continuous subspace from a dataframe.

More precisely, create the smallest axis-aligned hyperrectangle-shaped continuous subspace that contains the points specified in the given dataframe.

Parameters:
Raises:

ValueError – If parameter types other than baybe.parameters.numerical.NumericalContinuousParameter are provided.

Return type:

SubspaceContinuous

Returns:

The created continuous subspace.

classmethod from_dict(dictionary: dict)

Create an object from its dictionary representation.

Parameters:

dictionary (dict) – The dictionary representation.

Return type:

TypeVar(_T)

Returns:

The reconstructed object.

classmethod from_json(string: str)

Create an object from its JSON representation.

Parameters:

string (str) – The JSON representation of the object.

Return type:

TypeVar(_T)

Returns:

The reconstructed object.

classmethod from_parameter(parameter: ContinuousParameter)[source]

Create a subspace from a single parameter.

Parameters:

parameter (ContinuousParameter) – The parameter to span the subspace.

Return type:

SubspaceContinuous

Returns:

The created subspace.

classmethod from_product(parameters: Sequence[ContinuousParameter], constraints: Sequence[ContinuousConstraint] | None = None)[source]

See baybe.searchspace.core.SearchSpace.

Return type:

SubspaceContinuous

get_parameters_by_name(names: Sequence[str])[source]

Return parameters with the specified names.

Parameters:

names (Sequence[str]) – Sequence of parameter names.

Return type:

tuple[NumericalContinuousParameter, ...]

Returns:

The named parameters.

sample_from_full_factorial(batch_size: int = 1)[source]

Draw parameter configurations from the full factorial of the space.

Parameters:

batch_size (int) – The number of parameter configurations to be sampled.

Return type:

DataFrame

Returns:

A dataframe containing the parameter configurations as rows with columns corresponding to the parameter names.

Raises:

ValueError – If there are not enough points to sample from.

sample_uniform(batch_size: int = 1)[source]

Draw uniform random parameter configurations from the continuous space.

Parameters:

batch_size (int) – The number of parameter configurations to be sampled.

Return type:

DataFrame

Returns:

A dataframe containing the parameter configurations as rows with columns corresponding to the parameter names.

Raises:

ValueError – If the subspace contains unsupported nonlinear constraints.

samples_full_factorial(n_points: int = 1)[source]

Deprecated!

Return type:

DataFrame

samples_random(n_points: int = 1)[source]

Deprecated!

Return type:

DataFrame

to_dict()

Create an object’s dictionary representation.

Return type:

dict

to_json()

Create an object’s JSON representation.

Return type:

str

Returns:

The JSON representation as a string.

to_searchspace()[source]

Turn the subspace into a search space with no discrete part.

Return type:

SearchSpace

transform(df: DataFrame | None = None, /, *, allow_missing: bool = False, allow_extra: bool | None = None, data: DataFrame | None = None)[source]

See baybe.searchspace.core.SearchSpace.transform().

Return type:

DataFrame

property constraints_cardinality: tuple[ContinuousCardinalityConstraint, ...]

Cardinality constraints.

constraints_lin_eq: tuple[ContinuousLinearEqualityConstraint, ...]

Linear equality constraints.

constraints_lin_ineq: tuple[ContinuousLinearInequalityConstraint, ...]

Linear inequality constraints.

constraints_nonlin: tuple[ContinuousNonlinearConstraint, ...]

Nonlinear constraints.

property full_factorial: DataFrame

Get the full factorial of the continuous space.

property is_empty: bool

Return whether this subspace is empty.

property param_bounds_comp: ndarray

Return bounds as numpy array.

property param_names: tuple[str, ...]

Return list of parameter names.

parameters: tuple[NumericalContinuousParameter, ...]

The parameters of the subspace.