-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use number of bins instead of quantization interval in mlos_bench tun…
…ables (#835) Closes #803 > Future PR will rename the config schema in order to reduce confusion on the change in semantics, but also keep this PR smaller. --------- Co-authored-by: Brian Kroth <[email protected]> Co-authored-by: Brian Kroth <[email protected]>
- Loading branch information
1 parent
f3eb624
commit 2e4cfa2
Showing
12 changed files
with
179 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ | |
"type": "int", | ||
"default": 2000000, | ||
"range": [0, 1000000000], | ||
"quantization": 11, | ||
"log": false | ||
} | ||
} | ||
|
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
67 changes: 67 additions & 0 deletions
67
mlos_bench/mlos_bench/tests/tunables/tunable_to_configspace_quant_test.py
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,67 @@ | ||
# | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
# | ||
"""Unit tests for ConfigSpace quantization monkey patching.""" | ||
|
||
import numpy as np | ||
from ConfigSpace import UniformFloatHyperparameter, UniformIntegerHyperparameter | ||
from numpy.random import RandomState | ||
|
||
from mlos_bench.optimizers.convert_configspace import _monkey_patch_quantization | ||
from mlos_bench.tests import SEED | ||
|
||
|
||
def test_configspace_quant_int() -> None: | ||
"""Check the quantization of an integer hyperparameter.""" | ||
quantized_values = set(range(0, 101, 10)) | ||
hp = UniformIntegerHyperparameter("hp", lower=0, upper=100, log=False) | ||
|
||
# Before patching: expect that at least one value is not quantized. | ||
assert not set(hp.sample_value(100)).issubset(quantized_values) | ||
|
||
_monkey_patch_quantization(hp, 11) | ||
# After patching: *all* values must belong to the set of quantized values. | ||
assert hp.sample_value() in quantized_values # check scalar type | ||
assert set(hp.sample_value(100)).issubset(quantized_values) # batch version | ||
|
||
|
||
def test_configspace_quant_float() -> None: | ||
"""Check the quantization of a float hyperparameter.""" | ||
quantized_values = set(np.linspace(0, 1, num=5, endpoint=True)) | ||
hp = UniformFloatHyperparameter("hp", lower=0, upper=1, log=False) | ||
|
||
# Before patching: expect that at least one value is not quantized. | ||
assert not set(hp.sample_value(100)).issubset(quantized_values) | ||
|
||
# 5 is a nice number of bins to avoid floating point errors. | ||
_monkey_patch_quantization(hp, 5) | ||
# After patching: *all* values must belong to the set of quantized values. | ||
assert hp.sample_value() in quantized_values # check scalar type | ||
assert set(hp.sample_value(100)).issubset(quantized_values) # batch version | ||
|
||
|
||
def test_configspace_quant_repatch() -> None: | ||
"""Repatch the same hyperparameter with different number of bins.""" | ||
quantized_values = set(range(0, 101, 10)) | ||
hp = UniformIntegerHyperparameter("hp", lower=0, upper=100, log=False) | ||
|
||
# Before patching: expect that at least one value is not quantized. | ||
assert not set(hp.sample_value(100)).issubset(quantized_values) | ||
|
||
_monkey_patch_quantization(hp, 11) | ||
# After patching: *all* values must belong to the set of quantized values. | ||
samples = hp.sample_value(100, seed=RandomState(SEED)) | ||
assert set(samples).issubset(quantized_values) | ||
|
||
# Patch the same hyperparameter again and check that the results are the same. | ||
_monkey_patch_quantization(hp, 11) | ||
# After patching: *all* values must belong to the set of quantized values. | ||
assert all(samples == hp.sample_value(100, seed=RandomState(SEED))) | ||
|
||
# Repatch with the higher number of bins and make sure we get new values. | ||
_monkey_patch_quantization(hp, 21) | ||
samples_set = set(hp.sample_value(100, seed=RandomState(SEED))) | ||
quantized_values_new = set(range(5, 96, 10)) | ||
assert samples_set.issubset(set(range(0, 101, 5))) | ||
assert len(samples_set - quantized_values_new) < len(samples_set) |
Oops, something went wrong.