-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into globals-cli-option-compat-fixup
- Loading branch information
Showing
13 changed files
with
103 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
# | ||
"""Helper functions for config space converters.""" | ||
|
||
from ConfigSpace.functional import quantize | ||
from ConfigSpace.hyperparameters import NumericalHyperparameter | ||
|
||
|
||
def monkey_patch_quantization(hp: NumericalHyperparameter, quantization_bins: int) -> None: | ||
""" | ||
Monkey-patch quantization into the Hyperparameter. | ||
Parameters | ||
---------- | ||
hp : NumericalHyperparameter | ||
ConfigSpace hyperparameter to patch. | ||
quantization_bins : int | ||
Number of bins to quantize the hyperparameter into. | ||
""" | ||
if quantization_bins <= 1: | ||
raise ValueError(f"{quantization_bins=} :: must be greater than 1.") | ||
|
||
# Temporary workaround to dropped quantization support in ConfigSpace 1.0 | ||
# See Also: https://github.com/automl/ConfigSpace/issues/390 | ||
if not hasattr(hp, "sample_value_mlos_orig"): | ||
setattr(hp, "sample_value_mlos_orig", hp.sample_value) | ||
|
||
assert hasattr(hp, "sample_value_mlos_orig") | ||
setattr( | ||
hp, | ||
"sample_value", | ||
lambda size=None, **kwargs: quantize( | ||
hp.sample_value_mlos_orig(size, **kwargs), | ||
bounds=(hp.lower, hp.upper), | ||
bins=quantization_bins, | ||
).astype(type(hp.default_value)), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.