deephyper.problem.ConfigurationSpace
deephyper.problem.ConfigurationSpace#
-
class
deephyper.problem.
ConfigurationSpace
(name: Optional[str] = None, seed: Optional[int] = None, meta: Optional[Dict] = None)# Bases:
collections.abc.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.
keys
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: ConfigSpace.conditions.ConditionComponent) → ConfigSpace.conditions.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[ConfigSpace.conditions.ConditionComponent]) → List[ConfigSpace.conditions.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: ConfigSpace.hyperparameters.Hyperparameter = 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 (Hyperparameters, optional) – Adds for each new hyperparameter the condition, that
parent_hyperparameter
is active
- Returns
The configuration space, which was added
- Return type
ConfigurationSpace
-
add_forbidden_clause
(clause: ConfigSpace.forbidden.AbstractForbiddenComponent) → ConfigSpace.forbidden.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[ConfigSpace.forbidden.AbstractForbiddenComponent]) → List[ConfigSpace.forbidden.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: ConfigSpace.hyperparameters.Hyperparameter) → ConfigSpace.hyperparameters.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[ConfigSpace.hyperparameters.Hyperparameter]) → List[ConfigSpace.hyperparameters.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: ConfigSpace.configuration_space.Configuration) → None# Check if a configuration is legal. Raises an error if not.
- Parameters
configuration (
Configuration
) – Configuration to check
-
check_configuration_vector_representation
(vector: numpy.ndarray) → None# Raise error if configuration in vector representation is not legal.
- Parameters
vector (np.ndarray) – Configuration in vector representation
-
estimate_size
() → Union[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: ConfigSpace.configuration_space.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: Union[str, ConfigSpace.hyperparameters.Hyperparameter]) → List[ConfigSpace.conditions.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: Union[str, ConfigSpace.hyperparameters.Hyperparameter]) → List[ConfigSpace.hyperparameters.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[ConfigSpace.conditions.AbstractCondition]# Return a list with all conditions from the configuration space.
- Returns
Conditions of the configuration space
- Return type
list(Conditions)
-
get_default_configuration
() → ConfigSpace.configuration_space.Configuration# Return a configuration containing hyperparameters with default values.
- Returns
Configuration with the set default values
- Return type
Configuration
-
get_forbiddens
() → List[ConfigSpace.forbidden.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) → ConfigSpace.hyperparameters.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[ConfigSpace.hyperparameters.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, ConfigSpace.hyperparameters.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: Union[str, ConfigSpace.hyperparameters.Hyperparameter]) → List[ConfigSpace.conditions.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: Union[str, ConfigSpace.hyperparameters.Hyperparameter]) → List[ConfigSpace.hyperparameters.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#
-
remove_hyperparameter_priors
() → ConfigSpace.configuration_space.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
ConfigurationSpace
-
sample_configuration
(size: int = 1) → Union[ConfigSpace.configuration_space.Configuration, List[ConfigSpace.configuration_space.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
Configuration
,
-
static
substitute_hyperparameters_in_conditions
(conditions, new_configspace) → List[ConfigSpace.conditions.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[ConfigSpace.conditions.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#
-