ConfigurationSpace

class ConfigSpace.configuration_space.ConfigurationSpace(name=None, seed=None, meta=None, *, space=None)[source]

A collection-like object containing a set of hyperparameter definitions and conditions.

A configuration space organizes all hyperparameters and its conditions as well as its forbidden clauses. Configurations can be sampled from this configuration space. As underlying data structure, the configuration space uses a tree-based approach to represent the conditions and restrictions between hyperparameters.

Parameters:
  • name (str | dict, optional) – Name of the configuration space. If a dict is passed, this is considered the same as the space arg.

  • seed (int, optional) – Random seed

  • meta (dict, optional) – Field for holding meta data provided by the user. Not used by the configuration space.

  • space

    A simple configuration space to use:

    ConfigurationSpace(
        name="myspace",
        space={
            "uniform_integer": (1, 10),
            "uniform_float": (1.0, 10.0),
            "categorical": ["a", "b", "c"],
            "constant": 1337,
        }
    )
    

__eq__(other)[source]

Override the default Equals behavior.

Parameters:

other (Any) –

Return type:

bool

__hash__()[source]

Override the default hash behavior (that returns the id or the object).

Return type:

int

__iter__()[source]

Iterate over the hyperparameter names in the right order.

Return type:

Iterator[str]

add_condition(condition)[source]

Add a condition to the configuration space.

Check if adding the condition is legal:

  • The parent in a condition statement must exist

  • The condition must add no cycles

The internal array keeps track of all edges which must be added to the DiGraph; if the checks don’t raise any Exception, these edges are finally added at the end of the function.

Parameters:

condition (Conditions) – Condition to add

Returns:

Same condition as input

Return type:

Conditions

add_conditions(conditions)[source]

Add a list of conditions to the configuration space.

They must be legal. Take a look at add_condition().

Parameters:

conditions (list(Conditions)) – collection of conditions to add

Returns:

Same as input conditions

Return type:

list(Conditions)

add_configuration_space(prefix, configuration_space, delimiter=':', parent_hyperparameter=None)[source]

Combine two configuration space by adding one the other configuration space. The contents of the configuration space, which should be added, are renamed to prefix + delimiter + old_name.

Parameters:
  • prefix (str) – The prefix for the renamed hyperparameter | conditions | forbidden clauses

  • configuration_space (ConfigurationSpace) – The configuration space which should be added

  • delimiter (str, optional) – Defaults to ‘:’

  • parent_hyperparameter (dict | None = None) – Adds for each new hyperparameter the condition, that parent_hyperparameter is active. Must be a dictionary with two keys “parent” and “value”, meaning that the added configuration space is active when parent is equal to value

Returns:

The configuration space, which was added

Return type:

ConfigurationSpace

add_forbidden_clause(clause)[source]

Add a forbidden clause to the configuration space.

Parameters:

clause (Forbidden Clauses) – Forbidden clause to add

Returns:

Same as input forbidden clause

Return type:

Forbidden Clauses

add_forbidden_clauses(clauses)[source]

Add a list of forbidden clauses to the configuration space.

Parameters:

clauses (list(Forbidden Clauses)) – Collection of forbidden clauses to add

Returns:

Same as input clauses

Return type:

list(Forbidden Clauses)

add_hyperparameter(hyperparameter)[source]

Add a hyperparameter to the configuration space.

Parameters:

hyperparameter (Hyperparameters) – The hyperparameter to add

Returns:

The added hyperparameter

Return type:

Hyperparameters

add_hyperparameters(hyperparameters)[source]

Add hyperparameters to the configuration space.

Parameters:

hyperparameters (Iterable(Hyperparameters)) – Collection of hyperparameters to add

Returns:

List of added hyperparameters (same as input)

Return type:

list(Hyperparameters)

check_configuration(configuration)[source]

Check if a configuration is legal. Raises an error if not.

Parameters:

configuration (Configuration) – Configuration to check

Return type:

None

check_configuration_vector_representation(vector)[source]

Raise error if configuration in vector representation is not legal.

Parameters:

vector (np.ndarray) – Configuration in vector representation

Return type:

None

estimate_size()[source]

Estimate the size of the current configuration space (i.e. unique configurations).

This is np.inf in case if there is a single hyperparameter of size np.inf (i.e. a UniformFloatHyperparameter), otherwise it is the product of the size of all hyperparameters. The function correctly guesses the number of unique configurations if there are no condition and forbidden statements in the configuration spaces. Otherwise, this is an upper bound. Use generate_grid() to generate all valid configurations if required.

Return type:

Union[float, int]

generate_all_continuous_from_bounds(bounds)[source]

Generate UniformFloatHyperparameter from a list containing lists with lower and upper bounds.

The generated hyperparameters are added to the configuration space.

Parameters:

bounds (list[tuple([float, float])]) – List containing lists with two elements: lower and upper bound

Return type:

None

get(k[, d]) D[k] if k in D, else d.  d defaults to None.
get_active_hyperparameters(configuration)[source]

Set of active hyperparameter for a given configuration.

Parameters:

configuration (Configuration) – Configuration for which the active hyperparameter are returned

Returns:

The set of all active hyperparameter

Return type:

set(Configuration)

get_all_conditional_hyperparameters()[source]

Names of all conditional hyperparameters.

Returns:

Set with all conditional hyperparameter

Return type:

set[Hyperparameters]

get_all_unconditional_hyperparameters()[source]

Names of unconditional hyperparameters.

Returns:

List with all parent hyperparameters, which are not part of a condition

Return type:

list[Hyperparameters]

get_child_conditions_of(name)[source]

Return a list with conditions of all children of a given hyperparameter referenced by its name.

Parameters:

name (str, Hyperparameters) – Hyperparameter or its name, for which conditions are requested

Returns:

List with the conditions on the children of the given hyperparameter

Return type:

list(Conditions)

get_children_of(name)[source]

Return a list with all children of a given hyperparameter.

Parameters:

name (str, Hyperparameters) – Hyperparameter or its name, for which all children are requested

Returns:

Children of the hyperparameter

Return type:

list(Hyperparameters)

get_conditions()[source]

All conditions from the configuration space.

Returns:

Conditions of the configuration space

Return type:

list(Conditions)

get_default_configuration()[source]

Configuration containing hyperparameters with default values.

Returns:

Configuration with the set default values

Return type:

Configuration

get_forbiddens()[source]

All forbidden clauses from the configuration space.

Returns:

List with the forbidden clauses

Return type:

list(Forbidden Clauses)

get_hyperparameter(name)[source]

Hyperparameter from the space with a given name.

Parameters:

name (str) – Name of the searched hyperparameter

Returns:

Hyperparameter with the name name

Return type:

Hyperparameters

get_hyperparameter_by_idx(idx)[source]

Name of a hyperparameter from the space given its id.

Parameters:

idx (int) – Id of a hyperparameter

Returns:

Name of the hyperparameter

Return type:

str

get_hyperparameter_names()[source]

Names of all the hyperparameter in the space.

Returns:

List of hyperparameter names

Return type:

list(str)

get_hyperparameters()[source]

All hyperparameters in the space.

Returns:

A list with all hyperparameters stored in the configuration space object

Return type:

list(Hyperparameters)

get_hyperparameters_dict()[source]

All the (name, Hyperparameter) contained in the space.

Returns:

An OrderedDict of names and hyperparameters

Return type:

dict(str, Hyperparameters)

get_idx_by_hyperparameter_name(name)[source]

The id of a hyperparameter by its name.

Parameters:

name (str) – Name of a hyperparameter

Returns:

Id of the hyperparameter with name name

Return type:

int

get_parent_conditions_of(name)[source]

The conditions of all parents of a given hyperparameter.

Parameters:

name (str, Hyperparameters) – Can either be the name of a hyperparameter or the hyperparameter object

Returns:

List with all conditions on parent hyperparameters

Return type:

list[Conditions]

get_parents_of(name)[source]

The parents hyperparameters of a given hyperparameter.

Parameters:

name (str, Hyperparameters) – Can either be the name of a hyperparameter or the hyperparameter object.

Returns:

List with all parent hyperparameters

Return type:

list[Conditions]

items() a set-like object providing a view on D's items
keys()[source]

Return the hyperparameter names in the right order.

Return type:

KeysView[str]

remove_hyperparameter_priors()[source]

Produces a new ConfigurationSpace where all priors on parameters are removed.

Non-uniform hyperpararmeters are replaced with uniform ones, and CategoricalHyperparameters with weights have their weights removed.

Returns:

The resulting configuration space, without priors on the hyperparameters

Return type:

ConfigurationSpace

sample_configuration(size: None = None) Configuration[source]
sample_configuration(size: int) list[Configuration]

Sample size configurations from the configuration space object.

Parameters:

size (int, optional) – Number of configurations to sample. Default to 1

Returns:

list[Configuration]: A single configuration if size 1 else a list of Configurations

Return type:

Configuration,

seed(seed)[source]

Set the random seed to a number.

Parameters:

seed (int) – The random seed

Return type:

None

static substitute_hyperparameters_in_conditions(conditions, new_configspace)[source]

Takes a set of conditions and generates a new set of conditions with the same structure, where each hyperparameter is replaced with its namesake in new_configspace. As such, the set of conditions remain unchanged, but the included hyperparameters are changed to match those types that exist in new_configspace.

Parameters:
  • new_configspace (ConfigurationSpace) – A ConfigurationSpace containing hyperparameters with the same names as those in the conditions.

  • conditions (Iterable[ConditionComponent]) –

Returns:

The list of conditions, adjusted to fit the new ConfigurationSpace

Return type:

list[ConditionComponent]

static substitute_hyperparameters_in_forbiddens(forbiddens, new_configspace)[source]

Takes a set of forbidden clauses and generates a new set of forbidden clauses with the same structure, where each hyperparameter is replaced with its namesake in new_configspace. As such, the set of forbidden clauses remain unchanged, but the included hyperparameters are changed to match those types that exist in new_configspace.

Parameters:
  • forbiddens (Iterable[AbstractForbiddenComponent]) – An iterable of forbiddens

  • new_configspace (ConfigurationSpace) – A ConfigurationSpace containing hyperparameters with the same names as those in the forbidden clauses.

Returns:

The list of forbidden clauses, adjusted to fit the new ConfigurationSpace

Return type:

list[AbstractForbiddenComponent]

values() an object providing a view on D's values