| Total Complexity | 6 |
| Total Lines | 42 |
| Duplicated Lines | 35.71 % |
| 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 | # Author: Simon Blanke |
||
| 2 | # Email: [email protected] |
||
| 3 | # License: MIT License |
||
| 4 | |||
| 5 | import numpy as np |
||
| 6 | |||
| 7 | from gradient_free_optimizers import DecisionTreeOptimizer |
||
| 8 | from ._base_test import _base_test |
||
| 9 | |||
| 10 | n_iter = 33 |
||
| 11 | opt = DecisionTreeOptimizer |
||
| 12 | |||
| 13 | |||
| 14 | def get_score(para): |
||
| 15 | return -(para["x1"] * para["x1"]) |
||
| 16 | |||
| 17 | |||
| 18 | View Code Duplication | def test_warm_start_smbo(): |
|
|
|
|||
| 19 | gpr_X, gpr_y = [], [] |
||
| 20 | for _ in range(10): |
||
| 21 | pos_ = np.random.randint(0, high=9) |
||
| 22 | pos = np.array([pos_]) |
||
| 23 | |||
| 24 | para = { |
||
| 25 | "x1": pos_, |
||
| 26 | } |
||
| 27 | gpr_X.append(pos) |
||
| 28 | gpr_y.append(get_score(para)) |
||
| 29 | |||
| 30 | for warm_start_smbo in [None, (gpr_X, gpr_y)]: |
||
| 31 | opt_para = {"warm_start_smbo": warm_start_smbo} |
||
| 32 | _base_test(opt, n_iter, opt_para=opt_para) |
||
| 33 | |||
| 34 | |||
| 35 | def test_max_sample_size(): |
||
| 36 | for max_sample_size in [10, 100, 10000, 10000000000]: |
||
| 37 | opt_para = {"max_sample_size": max_sample_size} |
||
| 38 | _base_test(opt, n_iter, opt_para=opt_para) |
||
| 39 | |||
| 40 | |||
| 41 | """ |
||
| 42 | def test_gpr(): |
||
| 50 |