@@ 98-121 (lines=24) @@ | ||
95 | assert abs(np.sum(n_last_scores0) - np.sum(n_last_scores1)) > err |
|
96 | ||
97 | ||
98 | def test_random_state_direct(): |
|
99 | opt0 = DirectAlgorithm( |
|
100 | search_space, initialize={"random": n_random}, random_state=1 |
|
101 | ) |
|
102 | opt0.search( |
|
103 | ackkley_function, |
|
104 | n_iter=n_iter, |
|
105 | ) |
|
106 | ||
107 | opt1 = DirectAlgorithm( |
|
108 | search_space, initialize={"random": n_random}, random_state=10 |
|
109 | ) |
|
110 | opt1.search( |
|
111 | ackkley_function, |
|
112 | n_iter=n_iter, |
|
113 | ) |
|
114 | ||
115 | print("\n opt0.search_data \n", opt0.search_data) |
|
116 | print("\n opt1.search_data \n", opt1.search_data) |
|
117 | ||
118 | n_last_scores0 = list(opt0.search_data["score"].values)[-n_last:] |
|
119 | n_last_scores1 = list(opt1.search_data["score"].values)[-n_last:] |
|
120 | ||
121 | assert abs(np.sum(n_last_scores0) - np.sum(n_last_scores1)) < err |
|
122 | ||
123 | ||
124 | @pytest.mark.parametrize(*optimizers) |
|
@@ 75-95 (lines=21) @@ | ||
72 | assert abs(np.sum(n_last_scores0) - np.sum(n_last_scores1)) < err |
|
73 | ||
74 | ||
75 | @pytest.mark.parametrize(*optimizers) |
|
76 | def test_random_state_2(Optimizer): |
|
77 | opt0 = Optimizer(search_space, initialize={"random": n_random}, random_state=1) |
|
78 | opt0.search( |
|
79 | ackkley_function, |
|
80 | n_iter=n_iter, |
|
81 | ) |
|
82 | ||
83 | opt1 = Optimizer(search_space, initialize={"random": n_random}, random_state=10) |
|
84 | opt1.search( |
|
85 | ackkley_function, |
|
86 | n_iter=n_iter, |
|
87 | ) |
|
88 | ||
89 | print("\n opt0.search_data \n", opt0.search_data) |
|
90 | print("\n opt1.search_data \n", opt1.search_data) |
|
91 | ||
92 | n_last_scores0 = list(opt0.search_data["score"].values)[-n_last:] |
|
93 | n_last_scores1 = list(opt1.search_data["score"].values)[-n_last:] |
|
94 | ||
95 | assert abs(np.sum(n_last_scores0) - np.sum(n_last_scores1)) > err |
|
96 | ||
97 | ||
98 | def test_random_state_direct(): |
|
@@ 32-52 (lines=21) @@ | ||
29 | n_last = n_iter - n_random |
|
30 | ||
31 | ||
32 | @pytest.mark.parametrize(*optimizers) |
|
33 | def test_random_state_0(Optimizer): |
|
34 | opt0 = Optimizer(search_space, initialize={"random": n_random}, random_state=1) |
|
35 | opt0.search( |
|
36 | ackkley_function, |
|
37 | n_iter=n_iter, |
|
38 | ) |
|
39 | ||
40 | opt1 = Optimizer(search_space, initialize={"random": n_random}, random_state=1) |
|
41 | opt1.search( |
|
42 | ackkley_function, |
|
43 | n_iter=n_iter, |
|
44 | ) |
|
45 | ||
46 | print("\n opt0.search_data \n", opt0.search_data) |
|
47 | print("\n opt1.search_data \n", opt1.search_data) |
|
48 | ||
49 | n_last_scores0 = list(opt0.search_data["score"].values)[-n_last:] |
|
50 | n_last_scores1 = list(opt1.search_data["score"].values)[-n_last:] |
|
51 | ||
52 | assert abs(np.sum(n_last_scores0) - np.sum(n_last_scores1)) < err |
|
53 | ||
54 | ||
55 | @pytest.mark.parametrize(*optimizers) |