Conditions | 1 |
Total Lines | 32 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | # Author: Simon Blanke |
||
21 | def test_p_accept(): |
||
22 | p_accept_low = 0.5 |
||
23 | p_accept_high = 1 |
||
24 | |||
25 | epsilon = 1 / np.inf |
||
26 | |||
27 | opt = StochasticHillClimbingOptimizer( |
||
28 | search_space, |
||
29 | p_accept=p_accept_low, |
||
30 | epsilon=epsilon, |
||
31 | initialize={"random": 1}, |
||
32 | ) |
||
33 | opt.search(objective_function, n_iter=n_iter) |
||
34 | n_transitions_low = opt.n_transitions |
||
35 | |||
36 | opt = StochasticHillClimbingOptimizer( |
||
37 | search_space, |
||
38 | p_accept=p_accept_high, |
||
39 | epsilon=epsilon, |
||
40 | initialize={"random": 1}, |
||
41 | ) |
||
42 | opt.search(objective_function, n_iter=n_iter) |
||
43 | n_transitions_high = opt.n_transitions |
||
44 | |||
45 | print("\n n_transitions_low", n_transitions_low) |
||
46 | print("\n n_transitions_high", n_transitions_high) |
||
47 | |||
48 | lower_bound = int(n_iter * p_accept_low) |
||
49 | lower_bound -= lower_bound * 0.1 |
||
50 | higher_bound = n_iter |
||
51 | |||
52 | assert lower_bound < n_transitions_low < n_transitions_high < higher_bound |
||
53 |