Code Duplication    Length = 59-59 lines in 2 locations

tests/test_early_stop.py 2 locations

@@ 229-287 (lines=59) @@
226
    assert n_performed_iter == (n_iter_no_change + 1)
227
228
229
def test_early_stop_6():
230
    """Test early stopping with relative tolerance where no early stop occurs."""
231
232
    def objective_function(para):
233
        return para["x1"]
234
235
    search_space = {
236
        "x1": list(np.arange(0, 100, 0.01)),
237
    }
238
239
    n_iter_no_change = 5
240
    early_stopping = {
241
        "n_iter_no_change": 5,
242
        "tol_abs": None,
243
        "tol_rel": 10,
244
    }
245
246
    start1 = {"x1": 1}
247
    start2 = {"x1": 1.1}
248
    start3 = {"x1": 1.22}
249
    start4 = {"x1": 1.35}
250
    start5 = {"x1": 1.48}
251
252
    warm_start_l = [
253
        start1,
254
        start1,
255
        start1,
256
        start1,
257
        start1,
258
        start2,
259
        start2,
260
        start2,
261
        start3,
262
        start3,
263
        start3,
264
        start4,
265
        start4,
266
        start4,
267
        start5,
268
        start5,
269
        start5,
270
    ]
271
    n_iter = len(warm_start_l)
272
273
    hyper = Hyperactive()
274
    hyper.add_search(
275
        objective_function,
276
        search_space,
277
        n_iter=n_iter,
278
        initialize={"warm_start": warm_start_l},
279
        early_stopping=early_stopping,
280
    )
281
    hyper.run()
282
283
    search_data = hyper.search_data(objective_function)
284
    n_performed_iter = len(search_data)
285
286
    print("\n n_performed_iter \n", n_performed_iter)
287
    print("\n n_iter_no_change \n", n_iter_no_change)
288
289
    assert n_performed_iter == n_iter
290
@@ 111-169 (lines=59) @@
108
    assert n_performed_iter == (n_iter_no_change + 1)
109
110
111
def test_early_stop_4():
112
    """Test early stopping with absolute tolerance where no early stop occurs."""
113
114
    def objective_function(para):
115
        return para["x1"]
116
117
    search_space = {
118
        "x1": list(np.arange(0, 100, 0.1)),
119
    }
120
121
    n_iter_no_change = 5
122
    early_stopping = {
123
        "n_iter_no_change": 5,
124
        "tol_abs": 0.1,
125
        "tol_rel": None,
126
    }
127
128
    start1 = {"x1": 0}
129
    start2 = {"x1": 0.1}
130
    start3 = {"x1": 0.2}
131
    start4 = {"x1": 0.3}
132
    start5 = {"x1": 0.4}
133
134
    warm_start_l = [
135
        start1,
136
        start1,
137
        start1,
138
        start1,
139
        start1,
140
        start2,
141
        start2,
142
        start2,
143
        start3,
144
        start3,
145
        start3,
146
        start4,
147
        start4,
148
        start4,
149
        start5,
150
        start5,
151
        start5,
152
    ]
153
    n_iter = len(warm_start_l)
154
155
    hyper = Hyperactive()
156
    hyper.add_search(
157
        objective_function,
158
        search_space,
159
        n_iter=n_iter,
160
        initialize={"warm_start": warm_start_l},
161
        early_stopping=early_stopping,
162
    )
163
    hyper.run()
164
165
    search_data = hyper.search_data(objective_function)
166
    n_performed_iter = len(search_data)
167
168
    print("\n n_performed_iter \n", n_performed_iter)
169
    print("\n n_iter_no_change \n", n_iter_no_change)
170
171
    assert n_performed_iter == n_iter
172