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