-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathtest_gfo_search_space.py
More file actions
64 lines (49 loc) · 1.75 KB
/
test_gfo_search_space.py
File metadata and controls
64 lines (49 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""Integration tests for GFO search_space formats."""
import pytest
def _make_experiment():
from hyperactive.experiment.func import FunctionExperiment
def objective(params):
return params["x"] + params["y"]
return FunctionExperiment(objective)
def _make_optimizer(search_space, experiment):
from hyperactive.opt import GridSearch
return GridSearch(
search_space=search_space,
n_iter=5,
experiment=experiment,
)
def test_gfo_search_space_list_coercion():
experiment = _make_experiment()
search_space = {"x": [1], "y": [2]}
optimizer = _make_optimizer(search_space, experiment)
best_params = optimizer.solve()
assert isinstance(best_params, dict)
assert "x" in best_params
assert "y" in best_params
assert best_params["x"] == 1
assert best_params["y"] == 2
def test_gfo_search_space_union_grids_list():
experiment = _make_experiment()
search_space = [
{"x": [0], "y": [0]},
{"x": [1], "y": [2]},
]
optimizer = _make_optimizer(search_space, experiment)
best_params = optimizer.solve()
assert isinstance(best_params, dict)
assert "x" in best_params
assert "y" in best_params
assert best_params["x"] == 1
assert best_params["y"] == 2
def test_gfo_search_space_param_grid():
sklearn = pytest.importorskip("sklearn.model_selection")
ParameterGrid = sklearn.ParameterGrid
experiment = _make_experiment()
search_space = ParameterGrid([{"x": [1], "y": [2]}])
optimizer = _make_optimizer(search_space, experiment)
best_params = optimizer.solve()
assert isinstance(best_params, dict)
assert "x" in best_params
assert "y" in best_params
assert best_params["x"] == 1
assert best_params["y"] == 2