Total Complexity | 2 |
Total Lines | 42 |
Duplicated Lines | 83.33 % |
Changes | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | import pytest |
||
2 | import numpy as np |
||
3 | |||
4 | from ._parametrize import optimizers_local |
||
5 | |||
6 | |||
7 | View Code Duplication | @pytest.mark.parametrize(*optimizers_local) |
|
|
|||
8 | def test_convex_convergence_singleOpt(Optimizer): |
||
9 | def objective_function(para): |
||
10 | score = -(para["x1"] * para["x1"]) |
||
11 | return score |
||
12 | |||
13 | search_space = { |
||
14 | "x1": np.arange(-1000, 1, 1), |
||
15 | } |
||
16 | |||
17 | init1 = { |
||
18 | "x1": -1000, |
||
19 | } |
||
20 | initialize = {"warm_start": [init1]} |
||
21 | |||
22 | n_opts = 33 |
||
23 | |||
24 | scores = [] |
||
25 | for rnd_st in range(n_opts): |
||
26 | opt = Optimizer(search_space, rand_rest_p=1) |
||
27 | opt.search( |
||
28 | objective_function, |
||
29 | n_iter=30, |
||
30 | random_state=rnd_st, |
||
31 | memory=False, |
||
32 | verbosity=False, |
||
33 | initialize=initialize, |
||
34 | ) |
||
35 | |||
36 | scores.append(opt.best_score) |
||
37 | score_mean = np.array(scores).mean() |
||
38 | |||
39 | print("score_mean", score_mean) |
||
40 | |||
41 | assert score_mean > -10000 |
||
42 | |||
43 |