Beispiel #1
0
def impute_default_values(
        configuration_space: ConfigurationSpace,
        configs_array: np.ndarray
) -> np.ndarray:
    """Impute inactive hyperparameters in configuration array with their default.

    Necessary to apply an EPM to the data.

    Parameters
    ----------
    configuration_space : ConfigurationSpace
    
    configs_array : np.ndarray
        Array of configurations.

    Returns
    -------
    np.ndarray
        Array with configuration hyperparameters. Inactive values are imputed
        with their default value.
    """
    for hp in configuration_space.get_hyperparameters():
        default = hp.normalized_default_value
        idx = configuration_space.get_idx_by_hyperparameter_name(hp.name)
        nonfinite_mask = ~np.isfinite(configs_array[:, idx])
        configs_array[nonfinite_mask, idx] = default

    return configs_array
Beispiel #2
0
def config_space2string(config_space: ConfigurationSpace):
    pattern = r'[,|{}\'=<>&]'
    for hp in config_space.get_hyperparameters():
        if re.search(pattern, hp.name):
            raise NameError('Invalid character in hyperparameter name!')
        if hasattr(hp, 'choices'):
            for value in hp.choices:
                if re.search(pattern, value):
                    raise NameError('Invalid character in categorical hyperparameter value!')
    return str(config_space)