1 | import numpy as np |
||
2 | import pandas as pd |
||
3 | |||
4 | from hyperactive import Hyperactive |
||
5 | |||
6 | |||
7 | View Code Duplication | def test_search_space_0(): |
|
0 ignored issues
–
show
Duplication
introduced
by
![]() |
|||
8 | def objective_function(opt): |
||
9 | score = -opt["x1"] * opt["x1"] |
||
10 | return score |
||
11 | |||
12 | search_space = { |
||
13 | "x1": list(range(0, 3, 1)), |
||
14 | } |
||
15 | |||
16 | hyper = Hyperactive() |
||
17 | hyper.add_search( |
||
18 | objective_function, |
||
19 | search_space, |
||
20 | n_iter=15, |
||
21 | ) |
||
22 | hyper.run() |
||
23 | |||
24 | assert isinstance(hyper.search_data(objective_function), pd.DataFrame) |
||
25 | assert hyper.best_para(objective_function)["x1"] in search_space["x1"] |
||
26 | |||
27 | |||
28 | View Code Duplication | def test_search_space_1(): |
|
0 ignored issues
–
show
|
|||
29 | def objective_function(opt): |
||
30 | score = -opt["x1"] * opt["x1"] |
||
31 | return score |
||
32 | |||
33 | search_space = { |
||
34 | "x1": list(np.arange(0, 0.003, 0.001)), |
||
35 | } |
||
36 | |||
37 | hyper = Hyperactive() |
||
38 | hyper.add_search( |
||
39 | objective_function, |
||
40 | search_space, |
||
41 | n_iter=15, |
||
42 | ) |
||
43 | hyper.run() |
||
44 | |||
45 | assert isinstance(hyper.search_data(objective_function), pd.DataFrame) |
||
46 | assert hyper.best_para(objective_function)["x1"] in search_space["x1"] |
||
47 | |||
48 | |||
49 | View Code Duplication | def test_search_space_2(): |
|
0 ignored issues
–
show
|
|||
50 | def objective_function(opt): |
||
51 | score = -opt["x1"] * opt["x1"] |
||
52 | return score |
||
53 | |||
54 | search_space = { |
||
55 | "x1": list(range(0, 100, 1)), |
||
56 | "str1": ["0", "1", "2"], |
||
57 | } |
||
58 | |||
59 | hyper = Hyperactive() |
||
60 | hyper.add_search( |
||
61 | objective_function, |
||
62 | search_space, |
||
63 | n_iter=15, |
||
64 | ) |
||
65 | hyper.run() |
||
66 | |||
67 | assert isinstance(hyper.search_data(objective_function), pd.DataFrame) |
||
68 | assert hyper.best_para(objective_function)["str1"] in search_space["str1"] |
||
69 | |||
70 | |||
71 | def test_search_space_3(): |
||
72 | def func1(): |
||
73 | pass |
||
74 | |||
75 | def func2(): |
||
76 | pass |
||
77 | |||
78 | def func3(): |
||
79 | pass |
||
80 | |||
81 | def objective_function(opt): |
||
82 | score = -opt["x1"] * opt["x1"] |
||
83 | return score |
||
84 | |||
85 | search_space = { |
||
86 | "x1": list(range(0, 100, 1)), |
||
87 | "func1": [func1, func2, func3], |
||
88 | } |
||
89 | |||
90 | hyper = Hyperactive() |
||
91 | hyper.add_search( |
||
92 | objective_function, |
||
93 | search_space, |
||
94 | n_iter=15, |
||
95 | ) |
||
96 | hyper.run() |
||
97 | |||
98 | assert isinstance(hyper.search_data(objective_function), pd.DataFrame) |
||
99 | assert hyper.best_para(objective_function)["func1"] in search_space["func1"] |
||
100 | |||
101 | |||
102 | def test_search_space_4(): |
||
103 | class class1: |
||
104 | pass |
||
105 | |||
106 | class class2: |
||
107 | pass |
||
108 | |||
109 | class class3: |
||
110 | pass |
||
111 | |||
112 | def objective_function(opt): |
||
113 | score = -opt["x1"] * opt["x1"] |
||
114 | return score |
||
115 | |||
116 | search_space = { |
||
117 | "x1": list(range(0, 100, 1)), |
||
118 | "class1": [class1, class2, class3], |
||
119 | } |
||
120 | |||
121 | hyper = Hyperactive() |
||
122 | hyper.add_search( |
||
123 | objective_function, |
||
124 | search_space, |
||
125 | n_iter=15, |
||
126 | ) |
||
127 | hyper.run() |
||
128 | |||
129 | assert isinstance(hyper.search_data(objective_function), pd.DataFrame) |
||
130 | assert hyper.best_para(objective_function)["class1"] in search_space["class1"] |
||
131 | |||
132 | |||
133 | def test_search_space_5(): |
||
134 | class class1: |
||
135 | def __init__(self): |
||
136 | pass |
||
137 | |||
138 | class class2: |
||
139 | def __init__(self): |
||
140 | pass |
||
141 | |||
142 | class class3: |
||
143 | def __init__(self): |
||
144 | pass |
||
145 | |||
146 | def class_f1(): |
||
147 | return class1 |
||
148 | |||
149 | def class_f2(): |
||
150 | return class2 |
||
151 | |||
152 | def class_f3(): |
||
153 | return class3 |
||
154 | |||
155 | def objective_function(opt): |
||
156 | score = -opt["x1"] * opt["x1"] |
||
157 | return score |
||
158 | |||
159 | search_space = { |
||
160 | "x1": list(range(0, 100, 1)), |
||
161 | "class1": [class_f1, class_f2, class_f3], |
||
162 | } |
||
163 | |||
164 | hyper = Hyperactive() |
||
165 | hyper.add_search( |
||
166 | objective_function, |
||
167 | search_space, |
||
168 | n_iter=15, |
||
169 | ) |
||
170 | hyper.run() |
||
171 | |||
172 | assert isinstance(hyper.search_data(objective_function), pd.DataFrame) |
||
173 | assert hyper.best_para(objective_function)["class1"] in search_space["class1"] |
||
174 | |||
175 | |||
176 | def test_search_space_6(): |
||
177 | def objective_function(opt): |
||
178 | score = -opt["x1"] * opt["x1"] |
||
179 | return score |
||
180 | |||
181 | def list_f1(): |
||
182 | return [0, 1] |
||
183 | |||
184 | def list_f2(): |
||
185 | return [1, 0] |
||
186 | |||
187 | search_space = { |
||
188 | "x1": list(range(0, 100, 1)), |
||
189 | "list1": [list_f1, list_f2], |
||
190 | } |
||
191 | |||
192 | hyper = Hyperactive() |
||
193 | hyper.add_search( |
||
194 | objective_function, |
||
195 | search_space, |
||
196 | n_iter=15, |
||
197 | ) |
||
198 | hyper.run() |
||
199 | |||
200 | assert isinstance(hyper.search_data(objective_function), pd.DataFrame) |
||
201 | assert hyper.best_para(objective_function)["list1"] in search_space["list1"] |
||
202 |