1
|
|
|
"""Test module for issue #34 reproduction.""" |
2
|
|
|
|
3
|
|
|
import numpy as np |
4
|
|
|
|
5
|
|
|
from hyperactive import Hyperactive |
6
|
|
|
|
7
|
|
|
""" --- test search spaces with mixed int/float types --- """ |
8
|
|
|
n_iter = 100 |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
def test_mixed_type_search_space_0(): |
12
|
|
|
"""Test search space with integer type validation.""" |
13
|
|
|
|
14
|
|
|
def objective_function(para): |
15
|
|
|
assert isinstance(para["x1"], int) |
16
|
|
|
|
17
|
|
|
return 1 |
18
|
|
|
|
19
|
|
|
search_space = { |
20
|
|
|
"x1": list(range(10, 20)), |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
hyper = Hyperactive() |
24
|
|
|
hyper.add_search(objective_function, search_space, n_iter=n_iter) |
25
|
|
|
hyper.run() |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
def test_mixed_type_search_space_1(): |
29
|
|
|
"""Test search space with float type validation.""" |
30
|
|
|
|
31
|
|
|
def objective_function(para): |
32
|
|
|
assert isinstance(para["x2"], float) |
33
|
|
|
|
34
|
|
|
return 1 |
35
|
|
|
|
36
|
|
|
search_space = { |
37
|
|
|
"x2": list(np.arange(1, 2, 0.1)), |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
hyper = Hyperactive() |
41
|
|
|
hyper.add_search(objective_function, search_space, n_iter=n_iter) |
42
|
|
|
hyper.run() |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
def test_mixed_type_search_space_2(): |
46
|
|
|
"""Test search space with mixed integer and float type validation.""" |
47
|
|
|
|
48
|
|
|
def objective_function(para): |
49
|
|
|
assert isinstance(para["x1"], int) |
50
|
|
|
assert isinstance(para["x2"], float) |
51
|
|
|
|
52
|
|
|
return 1 |
53
|
|
|
|
54
|
|
|
search_space = { |
55
|
|
|
"x1": list(range(10, 20)), |
56
|
|
|
"x2": list(np.arange(1, 2, 0.1)), |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
hyper = Hyperactive() |
60
|
|
|
hyper.add_search(objective_function, search_space, n_iter=n_iter) |
61
|
|
|
hyper.run() |
62
|
|
|
|
63
|
|
|
|
64
|
|
|
def test_mixed_type_search_space_3(): |
65
|
|
|
"""Test search space with mixed integer, float, and string type validation.""" |
66
|
|
|
|
67
|
|
|
def objective_function(para): |
68
|
|
|
assert isinstance(para["x1"], int) |
69
|
|
|
assert isinstance(para["x2"], float) |
70
|
|
|
assert isinstance(para["x3"], float) |
71
|
|
|
assert isinstance(para["x4"], str) |
72
|
|
|
|
73
|
|
|
return 1 |
74
|
|
|
|
75
|
|
|
search_space = { |
76
|
|
|
"x1": list(range(10, 20)), |
77
|
|
|
"x2": list(np.arange(1, 2, 0.1)), |
78
|
|
|
"x3": list(np.arange(1, 2, 0.1)), |
79
|
|
|
"x4": ["str1", "str2", "str3"], |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
hyper = Hyperactive() |
83
|
|
|
hyper.add_search(objective_function, search_space, n_iter=n_iter) |
84
|
|
|
hyper.run() |
85
|
|
|
|