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