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