Total Complexity | 3 |
Total Lines | 39 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import time |
||
2 | import pytest |
||
3 | import numpy as np |
||
4 | from sklearn.datasets import load_breast_cancer |
||
5 | from sklearn.model_selection import cross_val_score |
||
6 | from sklearn.tree import DecisionTreeClassifier |
||
7 | |||
8 | from ._parametrize import optimizers |
||
9 | |||
10 | |||
11 | def objective_function(para): |
||
12 | score = -para["x1"] * para["x1"] |
||
13 | return score |
||
14 | |||
15 | |||
16 | search_space = { |
||
17 | "x1": np.arange(0, 100, 1), # small search space because of smbo |
||
18 | } |
||
19 | |||
20 | |||
21 | @pytest.mark.parametrize(*optimizers) |
||
22 | def test_max_time_0(Optimizer): |
||
23 | c_time1 = time.time() |
||
24 | opt = Optimizer(search_space) |
||
25 | opt.search(objective_function, n_iter=1000000, max_time=0.1) |
||
26 | diff_time1 = time.time() - c_time1 |
||
27 | |||
28 | assert diff_time1 < 1 |
||
29 | |||
30 | |||
31 | @pytest.mark.parametrize(*optimizers) |
||
32 | def test_max_time_1(Optimizer): |
||
33 | c_time1 = time.time() |
||
34 | opt = Optimizer(search_space) |
||
35 | opt.search(objective_function, n_iter=1000000, max_time=1) |
||
36 | diff_time1 = time.time() - c_time1 |
||
37 | |||
38 | assert 0.3 < diff_time1 < 2 |
||
39 |