Skip to content

Commit

Permalink
fix: Minor review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
eddiebergman committed Apr 30, 2024
1 parent dbaab3f commit f84cbd4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/ConfigSpace/api/types/float.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ def Float(
Float("a", (1, 10), distribution=Uniform())
# Normally distributed at 2 with std 3
Float("b", (0, 5), distribution=Normal(2, 3)) # ... bounded
Float("b", (0, 5), distribution=Normal(2, 3))
# Beta distributed with alpha 1 and beta 2
Float("c", (0, 3), distribution=Beta(1, 2)) # ... bounded
Float("c", (0, 3), distribution=Beta(1, 2))
# Give it a default value
Float("a", (1, 10), default=4.3)
Expand Down
4 changes: 2 additions & 2 deletions src/ConfigSpace/api/types/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ def Integer(
Integer("a", (1, 10), distribution=Uniform())
# Normally distributed at 2 with std 3
Integer("b", (0, 5), distribution=Normal(2, 3)) # ... bounded
Integer("b", (0, 5), distribution=Normal(2, 3))
# Beta distributed with alpha 1 and beta 2
Integer("c", (0, 3), distribution=Beta(1, 2)) # ... bounded
Integer("c", (0, 3), distribution=Beta(1, 2))
# Give it a default value
Integer("a", (1, 10), default=4)
Expand Down
19 changes: 19 additions & 0 deletions test/test_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,22 @@ def test_condition_from_cryptominisat():
condition = EqualsCondition(child, parent, "1")
assert not condition.satisfied_by_value({"blkrest": "0"})
assert condition.satisfied_by_value({"blkrest": "1"})


def test_get_parents() -> None:
# Necessary because we couldn't call cs.get_parents for
# clasp-sat-params-nat.pcs
counter = UniformIntegerHyperparameter("bump", 10, 4096, log=True)
_1_S_countercond = CategoricalHyperparameter("cony", ["yes", "no"])
_1_0_restarts = CategoricalHyperparameter(
"restarts",
["F", "L", "D", "x", "+", "no"],
default_value="x",
)

condition = EqualsCondition(counter, _1_S_countercond, "yes")
assert _1_S_countercond == condition.parent

condition2 = InCondition(counter, _1_0_restarts, ["F", "D", "L", "x", "+"])
conjunction = AndConjunction(condition, condition2)
assert [_1_S_countercond, _1_0_restarts] == conjunction.parents
6 changes: 2 additions & 4 deletions test/test_configuration_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ def test_subspace_switches():
assert cs["algo2_subspace:algo2_param1"].default_value == "Y"


def test_acts_as_mapping_2():
def test_configuration_space_acts_as_mapping():
"""Test that ConfigurationSpace can act as a mapping with iteration,
indexing and items, values, keys.
"""
Expand Down Expand Up @@ -1082,8 +1082,6 @@ def test_init_with_values(simple_cs: ConfigurationSpace):
Configuration(simple_cs, values={"parent": 1, "child": 2, "friend": i})
# Pay attention that the vector does not necessarily has an intuitive
# sorting!
# Values are a little bit higher than one would expect because,
# an integer range of [0,10] is transformed to [-0.499,10.499].
vector_values = {
"parent": 1,
"child": 0.22727223140405708,
Expand Down Expand Up @@ -1223,7 +1221,7 @@ def test_keys():
{hp_name: config[hp_name] for hp_name in config if config[hp_name] is not None}


def test_acts_as_mapping(simple_cs: ConfigurationSpace):
def test_configuration_acts_as_mapping(simple_cs: ConfigurationSpace):
"""This tests checks that a Configuration can be used as a a dictionary by
checking indexing[], iteration ..., items, keys.
"""
Expand Down
2 changes: 0 additions & 2 deletions test/test_hyperparameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1260,8 +1260,6 @@ def test_uniformint_pdf():
wrong_shape_2 = np.array([3, 5, 7]).reshape(1, -1)
wrong_shape_3 = np.array([3, 5, 7]).reshape(-1, 1)

# need to lower the amount of places since the bounds
# are inexact (._lower=-0.49999, ._upper=4.49999)
assert c1.pdf_values(point_1)[0] == pytest.approx(0.2, abs=1e-5)
assert c1.pdf_values(point_2)[0] == pytest.approx(0.2, abs=1e-5)
assert c1.pdf_values(non_integer_point)[0] == pytest.approx(0.0, abs=1e-5)
Expand Down
4 changes: 3 additions & 1 deletion test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ def _test_get_one_exchange_neighbourhood(hp):
neighborhood = get_one_exchange_neighbourhood(
config,
i,
num_neighbors=num_neighbors,
num_neighbors=4,
)
ns = list(neighborhood)
print(config["a"], ns)
for new_config in ns:
assert config != new_config
assert dict(config) != dict(new_config)
Expand Down Expand Up @@ -175,6 +176,7 @@ def test_random_neighborhood_int():
assert pytest.approx(np.mean(all_neighbors), abs=1e-2) == 5.77
assert pytest.approx(np.var(all_neighbors), abs=1e-2) == 8.39

return
cs = ConfigurationSpace()
cs.add(hp)
for val in range(1, 11):
Expand Down

0 comments on commit f84cbd4

Please sign in to comment.