Code Duplication    Length = 59-62 lines in 3 locations

tests/test_api/test_early_stop.py 2 locations

@@ 224-285 (lines=62) @@
221
    assert n_performed_iter == (n_iter_no_change + 1)
222
223
224
def test_early_stop_6():
225
    class Experiment(BaseExperiment):
226
        def objective_function(self, para):
227
            return para["x0"]
228
229
    experiment = Experiment()
230
231
    search_config = SearchConfig(
232
        x0=list(np.arange(0, 100, 0.01)),
233
    )
234
235
    n_iter_no_change = 5
236
    early_stopping = {
237
        "n_iter_no_change": 5,
238
        "tol_abs": None,
239
        "tol_rel": 10,
240
    }
241
242
    start1 = {"x0": 1}
243
    start2 = {"x0": 1.1}
244
    start3 = {"x0": 1.22}
245
    start4 = {"x0": 1.35}
246
    start5 = {"x0": 1.48}
247
248
    warm_start_l = [
249
        start1,
250
        start1,
251
        start1,
252
        start1,
253
        start1,
254
        start2,
255
        start2,
256
        start2,
257
        start3,
258
        start3,
259
        start3,
260
        start4,
261
        start4,
262
        start4,
263
        start5,
264
        start5,
265
        start5,
266
    ]
267
    n_iter = len(warm_start_l)
268
269
    hyper = RandomSearchOptimizer()
270
    hyper.add_search(
271
        experiment,
272
        search_config,
273
        n_iter=n_iter,
274
        initialize={"warm_start": warm_start_l},
275
        early_stopping=early_stopping,
276
    )
277
    hyper.run()
278
279
    search_data = hyper.search_data(experiment)
280
    n_performed_iter = len(search_data)
281
282
    print("\n n_performed_iter \n", n_performed_iter)
283
    print("\n n_iter_no_change \n", n_iter_no_change)
284
285
    assert n_performed_iter == n_iter
286
287
288
def test_early_stop_7():
@@ 104-165 (lines=62) @@
101
    assert n_performed_iter == (n_iter_no_change + 1)
102
103
104
def test_early_stop_4():
105
    class Experiment(BaseExperiment):
106
        def objective_function(self, para):
107
            return para["x0"]
108
109
    experiment = Experiment()
110
111
    search_config = SearchConfig(
112
        x0=list(np.arange(0, 100, 0.01)),
113
    )
114
115
    n_iter_no_change = 5
116
    early_stopping = {
117
        "n_iter_no_change": 5,
118
        "tol_abs": 1,
119
        "tol_rel": None,
120
    }
121
122
    start1 = {"x0": 0}
123
    start2 = {"x0": 1}
124
    start3 = {"x0": 2}
125
    start4 = {"x0": 3}
126
    start5 = {"x0": 4}
127
128
    warm_start_l = [
129
        start1,
130
        start1,
131
        start1,
132
        start1,
133
        start1,
134
        start2,
135
        start2,
136
        start2,
137
        start3,
138
        start3,
139
        start3,
140
        start4,
141
        start4,
142
        start4,
143
        start5,
144
        start5,
145
        start5,
146
    ]
147
    n_iter = len(warm_start_l)
148
149
    hyper = RandomSearchOptimizer()
150
    hyper.add_search(
151
        experiment,
152
        search_config,
153
        n_iter=n_iter,
154
        initialize={"warm_start": warm_start_l},
155
        early_stopping=early_stopping,
156
    )
157
    hyper.run()
158
159
    search_data = hyper.search_data(experiment)
160
    n_performed_iter = len(search_data)
161
162
    print("\n n_performed_iter \n", n_performed_iter)
163
    print("\n n_iter_no_change \n", n_iter_no_change)
164
165
    assert n_performed_iter == n_iter
166
167
168
def test_early_stop_5():

tests_old/test_early_stop.py 1 location

@@ 112-170 (lines=59) @@
109
    assert n_performed_iter == (n_iter_no_change + 1)
110
111
112
def test_early_stop_4():
113
    def objective_function(para):
114
        return para["x1"]
115
116
    search_space = {
117
        "x1": list(np.arange(0, 100, 0.1)),
118
    }
119
120
    n_iter_no_change = 5
121
    early_stopping = {
122
        "n_iter_no_change": 5,
123
        "tol_abs": 0.1,
124
        "tol_rel": None,
125
    }
126
127
    start1 = {"x1": 0}
128
    start2 = {"x1": 0.1}
129
    start3 = {"x1": 0.2}
130
    start4 = {"x1": 0.3}
131
    start5 = {"x1": 0.4}
132
133
    warm_start_l = [
134
        start1,
135
        start1,
136
        start1,
137
        start1,
138
        start1,
139
        start2,
140
        start2,
141
        start2,
142
        start3,
143
        start3,
144
        start3,
145
        start4,
146
        start4,
147
        start4,
148
        start5,
149
        start5,
150
        start5,
151
    ]
152
    n_iter = len(warm_start_l)
153
154
    hyper = Hyperactive()
155
    hyper.add_search(
156
        objective_function,
157
        search_space,
158
        n_iter=n_iter,
159
        initialize={"warm_start": warm_start_l},
160
        early_stopping=early_stopping,
161
    )
162
    hyper.run()
163
164
    search_data = hyper.search_data(objective_function)
165
    n_performed_iter = len(search_data)
166
167
    print("\n n_performed_iter \n", n_performed_iter)
168
    print("\n n_iter_no_change \n", n_iter_no_change)
169
170
    assert n_performed_iter == n_iter
171
172
173
def test_early_stop_5():