Utils

Functions defined in the utils module can be helpful to develop custom tools that create configurations from a given configuration space or modify a given configuration space.

ConfigSpace.util.deactivate_inactive_hyperparameters(configuration, configuration_space, vector=None)[source]

Remove inactive hyperparameters from a given configuration.

Parameters:
  • configuration (dict) – a configuration as a dictionary. Key: name of the hyperparameter. Value: value of this hyperparamter configuration from which inactive hyperparameters will be removed

  • configuration_space (ConfigurationSpace) – The defined configuration space. It is necessary to find the inactive hyperparameters by iterating through the conditions of the configuration space.

  • vector ((np.ndarray, optional)) – Efficient represantation of a configuration. Either configuration or vector must be specified. If both are specified only configuration will be used.

Returns:

A configuration that is equivalent to the given configuration, except that inactivate hyperparameters have been removed.

Return type:

Configuration

ConfigSpace.util.fix_types(configuration, configuration_space)[source]

Iterate over all hyperparameters in the ConfigSpace and fix the types of the parameter values in configuration.

Parameters:
  • configuration (dict) – a configuration as a dictionary. Key: name of the hyperparameter. Value: value of this hyperparamter

  • configuration_space (ConfigurationSpace) – Configuration space which knows the types for all parameter values

Returns:

configuration with fixed types of parameter values

Return type:

dict

ConfigSpace.util.generate_grid(configuration_space, num_steps_dict=None)[source]

Generates a grid of Configurations for a given ConfigurationSpace. Can be used, for example, for grid search.

Parameters:
  • configuration_space (ConfigurationSpace) – The Configuration space over which to create a grid of HyperParameter Configuration values. It knows the types for all parameter values.

  • num_steps_dict (dict) – A dict containing the number of points to divide the grid side formed by Hyperparameters which are either of type UniformFloatHyperparameter or type UniformIntegerHyperparameter. The keys in the dict should be the names of the corresponding Hyperparameters and the values should be the number of points to divide the grid side formed by the corresponding Hyperparameter in to.

Returns:

List containing Configurations. It is a cartesian product of tuples of HyperParameter values. Each tuple lists the possible values taken by the corresponding HyperParameter. Within the cartesian product, in each element, the ordering of HyperParameters is the same for the OrderedDict within the ConfigurationSpace.

Return type:

list

ConfigSpace.util.get_one_exchange_neighbourhood(configuration, seed, num_neighbors=4, stdev=0.2)[source]

Return all configurations in a one-exchange neighborhood.

The method is implemented as defined by: Frank Hutter, Holger H. Hoos and Kevin Leyton-Brown Sequential Model-Based Optimization for General Algorithm Configuration In Proceedings of the conference on Learning and Intelligent Optimization(LION 5)

Parameters:
  • configuration (Configuration) – for this Configuration object num_neighbors neighbors are computed

  • seed (int) – Sets the random seed to a fixed value

  • num_neighbors ((int, optional)) – number of configurations, which are sampled from the neighbourhood of the input configuration

  • stdev ((float, optional)) – The standard deviation is used to determine the neigbours of UniformFloatHyperparameter and UniformIntegerHyperparameter.

Returns:

It contains configurations, with values being situated around the given configuration.

Return type:

Iterator

ConfigSpace.util.get_random_neighbor(configuration, seed)[source]

Draw a random neighbor by changing one parameter of a configuration.

  • If the parameter is categorical, it changes it to another value.

  • If the parameter is ordinal, it changes it to the next higher or lower value.

  • If parameter is a float, draw a random sample

If changing a parameter activates new parameters or deactivates previously active parameters, the configuration will be rejected. If more than 10000 configurations were rejected, this function raises a ValueError.

Parameters:
  • configuration (Configuration) – a configuration for which a random neigbour is calculated

  • seed (int) – Used to generate a random state.

Returns:

The new neighbor

Return type:

Configuration

ConfigSpace.util.impute_inactive_values(configuration, strategy='default')[source]

Impute inactive parameters.

Iterate through the hyperparameters of a Configuration and set the values of the inactive hyperparamters to their default values if the choosen strategy is ‘default’. Otherwise strategy contains a float number. Set the hyperparameters’ value to this number.

Parameters:
  • configuration (Configuration) – For this configuration inactive values will be imputed.

  • strategy ((str, float, optional)) – The imputation strategy. Defaults to ‘default’ If ‘default’, replace inactive parameters by their default. If float, replace inactive parameters by the given float value, which should be able to be splitted apart by a tree-based model.

Returns:

A new configuration with the imputed values. In this new configuration inactive values are included.

Return type:

Configuration