syne_tune.optimizer.schedulers.searchers.utils.hp_ranges module
- class syne_tune.optimizer.schedulers.searchers.utils.hp_ranges.HyperparameterRanges(config_space, name_last_pos=None, value_for_last_pos=None, active_config_space=None, prefix_keys=None)[source]
Bases:
objectWraps configuration space, provides services around encoding of hyperparameters (mapping configurations to
[0, 1]vectors and vice versa).If
name_last_posis given, the hyperparameter of that name is assigned the final position in the vector returned byto_ndarray(). This can be used to single out the (time) resource for a GP model, where that component has to come last.If in this case (
name_last_posgiven),value_for_last_posis also given, some methods are modified:random_config()samples a config as normal, but then overwrites thename_last_poscomponent byvalue_for_last_posget_ndarray_bounds()works as normal, but returns bound(a, a)forname_last_pos component, where a is the internal value corresponding tovalue_for_last_pos
The use case is HPO with a resource attribute. This attribute should be fixed when optimizing the acquisition function, but can take different values in the evaluation data (coming from all previous searches).
If
active_config_spaceis given, it contains a subset of non-constant hyperparameters inconfig_space, and the range of each entry is a subset of the range of the correspondingconfig_spaceentry. These active ranges affect the choice of new configs (by sampling). While the internal encoding is based on original ranges, search is restricted to active ranges (e.g., optimization of surrogate model). This option is required to implement transfer tuning, where domain ranges inconfig_spacemay be narrower than what data from past tuning jobs requires.- Parameters:
config_space (
Dict[str,Any]) – Configuration space. Constant hyperparameters are filtered out herename_last_pos (
Optional[str]) – See above, optionalvalue_for_last_pos – See above, optional
active_config_space (
Optional[dict]) – See above, optionalprefix_keys (
Optional[List[str]]) – If given, these keys intoconfig_spacecome first in the internal ordering, which determines the internal encoding. Optional
- property internal_keys: List[str]
- property config_space_for_sampling: Dict[str, Any]
- to_ndarray(config)[source]
Map configuration to
[0, 1]encoded vector- Parameters:
config (
Dict[str,Union[str,float,int]]) – Configuration to encode- Return type:
ndarray- Returns:
Encoded vector
- to_ndarray_matrix(configs)[source]
Map configurations to
[0, 1]encoded matrix- Parameters:
configs (
Iterable[Dict[str,Union[str,float,int]]]) – Configurations to encode- Return type:
ndarray- Returns:
Matrix of encoded vectors (rows)
- property ndarray_size: int
- Returns:
Dimensionality of encoded vector returned by
to_ndarray
- from_ndarray(enc_config)[source]
Maps encoded vector back to configuration (can involve rounding)
The encoded vector
enc_configneed to be in the image ofto_ndarray. In fact, any[0, 1]valued vector of dimensionalityndarray_sizeis allowed.- Parameters:
enc_config (
ndarray) – Encoded vector- Return type:
Dict[str,Union[str,float,int]]- Returns:
Configuration corresponding to encoded vector
- property encoded_ranges: Dict[str, Tuple[int, int]]
Encoded ranges are
[0, 1]or closed subintervals thereof, in caseactive_config_spaceis used.- Returns:
Ranges of hyperparameters in the encoded ndarray representation
- random_config(random_state)[source]
Draws random configuration
- Parameters:
random_state (
RandomState) – Random state- Return type:
Dict[str,Union[str,float,int]]- Returns:
Random configuration
- random_configs(random_state, num_configs)[source]
Draws random configurations
- Parameters:
random_state – Random state
num_configs (
int) – Number of configurations to sample
- Return type:
List[Dict[str,Union[str,float,int]]]- Returns:
Random configurations
- get_ndarray_bounds()[source]
- Return type:
List[Tuple[float,float]]- Returns:
List of
(lower, upper)bounds for each dimension in encoded vector representation.
- filter_for_last_pos_value(configs)[source]
If
is_attribute_fixed,configsis filtered by removing entries whosename_last_pos attributevalue is different fromvalue_for_last_pos. Otherwise, it is returned unchanged.- Parameters:
configs (
List[Dict[str,Union[str,float,int]]]) – List of configs to be filtered- Return type:
List[Dict[str,Union[str,float,int]]]- Returns:
Filtered list of configs
- config_to_tuple(config, keys=None, skip_last=False)[source]
- Parameters:
config (
Dict[str,Union[str,float,int]]) – Configurationkeys (
Optional[List[str]]) – Overrides_internal_keysskip_last (
bool) – If True andname_last_posis used, the corresponding attribute is skipped, so that config and tuple are non-extended
- Return type:
Tuple[Union[str,int,float],...]- Returns:
Tuple representation
- tuple_to_config(config_tpl, keys=None, skip_last=False)[source]
Reverse of
config_to_tuple().- Parameters:
config_tpl (
Tuple[Union[str,int,float],...]) – Tuple representationkeys (
Optional[List[str]]) – Overrides_internal_keysskip_last (
bool) – If True andname_last_posis used, the corresponding attribute is skipped, so that config and tuple are non-extended
- Return type:
Dict[str,Union[str,float,int]]- Returns:
Configuration corresponding to
config_tpl
- config_to_match_string(config, keys=None, skip_last=False)[source]
Maps configuration to match string, used to compare for approximate equality. Two configurations are considered to be different if their match strings are not the same.
- Parameters:
config (
Dict[str,Union[str,float,int]]) – Configurationkeys (
Optional[List[str]]) – Overrides_internal_keysskip_last (
bool) – If True andname_last_posis used, the corresponding attribute is skipped, so that config and match string are non-extended
- Return type:
str- Returns:
Match string