deephyper.problem.ConfigurationSpace#
- class deephyper.problem.ConfigurationSpace(name: str | Dict | None = None, seed: int | None = None, meta: Dict | None = None, *, space: Dict[str, Tuple[int, int] | Tuple[float, float] | List[int | float | str] | int | float | str] | None = None)#
Bases:
Mapping
Methods
Add a condition to the configuration space.
Add a list of conditions to the configuration space.
Combine two configuration space by adding one the other configuration space.
Add a forbidden clause to the configuration space.
Add a list of forbidden clauses to the configuration space.
Add a hyperparameter to the configuration space.
Add hyperparameters to the configuration space.
Check if a configuration is legal.
Raise error if configuration in vector representation is not legal.
Estimate the size of the current configuration space (i.e.
Generate
UniformFloatHyperparameter
from a list containing lists with lower and upper bounds.Return a set of active hyperparameter for a given configuration.
Return a list with names of all conditional hyperparameters.
Return a list with names of unconditional hyperparameters.
Return a list with conditions of all children of a given hyperparameter referenced by its
name
.Return a list with all children of a given hyperparameter.
Return a list with all conditions from the configuration space.
Return a configuration containing hyperparameters with default values.
Return a list with all forbidden clauses from the configuration space.
Gives the hyperparameter from the configuration space given its name.
Return the name of a hyperparameter from the configuration space given its id.
Return a list with all names of hyperparameter, which are contained in the configuration space object.
Return a list with all the hyperparameter, which are contained in the configuration space object.
Return an OrderedDict with all the
(name, Hyperparameter)
contained in the configuration space object.Return the id of a hyperparameter by its
name
.Return a list with conditions of all parents of a given hyperparameter.
Return the parent hyperparameters of a given hyperparameter.
Produces a new ConfigurationSpace where all priors on parameters are removed.
Sample
size
configurations from the configuration space object.Set the random seed to a number.
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.
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.
- add_condition(condition: ConditionComponent) ConditionComponent #
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: List[ConditionComponent]) List[ConditionComponent] #
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: unicode, configuration_space: ConfigurationSpace, delimiter: unicode = ':', parent_hyperparameter: dict = None) ConfigurationSpace #
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 addeddelimiter (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:
- add_forbidden_clause(clause: AbstractForbiddenComponent) AbstractForbiddenComponent #
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: List[AbstractForbiddenComponent]) List[AbstractForbiddenComponent] #
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: Hyperparameter) Hyperparameter #
Add a hyperparameter to the configuration space.
- Parameters:
hyperparameter (Hyperparameters) – The hyperparameter to add
- Returns:
The added hyperparameter
- Return type:
Hyperparameters
- add_hyperparameters(hyperparameters: List[Hyperparameter]) List[Hyperparameter] #
Add hyperparameters to the configuration space.
- Parameters:
hyperparameters (list(Hyperparameters)) – Collection of hyperparameters to add
- Returns:
List of added hyperparameters (same as input)
- Return type:
list(Hyperparameters)
- check_configuration(configuration: Configuration) None #
Check if a configuration is legal. Raises an error if not.
- Parameters:
configuration (
Configuration
) – Configuration to check
- check_configuration_vector_representation(vector: ndarray) None #
Raise error if configuration in vector representation is not legal.
- Parameters:
vector (np.ndarray) – Configuration in vector representation
- estimate_size() float | int #
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 sizenp.inf
(i.e. aUniformFloatHyperparameter
), 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. Usegenerate_grid()
to generate all valid configurations if required.
- generate_all_continuous_from_bounds(bounds: List[List[Any]]) None #
Generate
UniformFloatHyperparameter
from a list containing lists with lower and upper bounds. The generated hyperparameters are added to the configuration space.
- get(k[, d]) D[k] if k in D, else d. d defaults to None. #
- get_active_hyperparameters(configuration: Configuration) Set #
Return a 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() List[str] #
Return a list with names of all conditional hyperparameters.
- Returns:
List with all conditional hyperparameter
- Return type:
list[Hyperparameters]
- get_all_unconditional_hyperparameters() List[str] #
Return a list with 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: str | Hyperparameter) List[AbstractCondition] #
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: str | Hyperparameter) List[Hyperparameter] #
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() List[AbstractCondition] #
Return a list with all conditions from the configuration space.
- Returns:
Conditions of the configuration space
- Return type:
list(Conditions)
- get_default_configuration() Configuration #
Return a configuration containing hyperparameters with default values.
- Returns:
Configuration with the set default values
- Return type:
- get_forbiddens() List[AbstractForbiddenComponent] #
Return a list with all forbidden clauses from the configuration space.
- Returns:
List with the forbidden clauses
- Return type:
list(Forbidden clauses)
- get_hyperparameter(name: unicode) Hyperparameter #
Gives the hyperparameter from the configuration space given its name.
- Parameters:
name (str) – Name of the searched hyperparameter
- Returns:
Hyperparameter with the name
name
- Return type:
Hyperparameters
- get_hyperparameter_by_idx(idx: int) unicode #
Return the name of a hyperparameter from the configuration space given its id.
- get_hyperparameter_names() List[str] #
Return a list with all names of hyperparameter, which are contained in the configuration space object.
- get_hyperparameters() List[Hyperparameter] #
Return a list with all the hyperparameter, which are contained in the configuration space object.
- Returns:
A list with all hyperparameters stored in the configuration space object
- Return type:
list(Hyperparameters)
- get_hyperparameters_dict() Dict[str, Hyperparameter] #
Return an OrderedDict with all the
(name, Hyperparameter)
contained in the configuration space object.- Returns:
An OrderedDict of names and hyperparameters
- Return type:
OrderedDict(str, Hyperparameters)
- get_parent_conditions_of(name: str | Hyperparameter) List[AbstractCondition] #
Return a list with 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: str | Hyperparameter) List[Hyperparameter] #
Return the parent 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() a set-like object providing a view on D's keys #
- remove_hyperparameter_priors() ConfigurationSpace #
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:
- sample_configuration(size: int = 1) Configuration | 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 ifsize
1 else a list of Configurations- Return type:
- static substitute_hyperparameters_in_conditions(conditions, new_configspace) List[ConditionComponent] #
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.
- Returns:
The list of conditions, adjusted to fit the new ConfigurationSpace
- Return type:
List[ConditionComponent]
- static substitute_hyperparameters_in_forbiddens(forbiddens, new_configspace) List[ConditionComponent] #
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:
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 #