| Total Complexity | 7 |
| Total Lines | 60 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import numpy as np |
||
| 2 | |||
| 3 | from gradient_free_optimizers import RandomSearchOptimizer |
||
| 4 | |||
| 5 | |||
| 6 | def objective_function(para): |
||
| 7 | score = -para["x1"] * para["x1"] |
||
| 8 | return score |
||
| 9 | |||
| 10 | |||
| 11 | search_space = { |
||
| 12 | "x1": np.arange(0, 100, 0.1), |
||
| 13 | } |
||
| 14 | |||
| 15 | |||
| 16 | def test_verbosity_0(): |
||
| 17 | opt = RandomSearchOptimizer(search_space) |
||
| 18 | opt.search(objective_function, n_iter=100, verbosity=False) |
||
| 19 | |||
| 20 | |||
| 21 | def test_verbosity_1(): |
||
| 22 | opt = RandomSearchOptimizer(search_space,) |
||
| 23 | opt.search( |
||
| 24 | objective_function, |
||
| 25 | n_iter=100, |
||
| 26 | verbosity=["progress_bar", "print_results", "print_times"], |
||
| 27 | ) |
||
| 28 | |||
| 29 | |||
| 30 | def test_verbosity_2(): |
||
| 31 | opt = RandomSearchOptimizer(search_space) |
||
| 32 | opt.search( |
||
| 33 | objective_function, |
||
| 34 | n_iter=100, |
||
| 35 | verbosity=["print_results", "print_times"], |
||
| 36 | ) |
||
| 37 | |||
| 38 | |||
| 39 | def test_verbosity_3(): |
||
| 40 | opt = RandomSearchOptimizer(search_space) |
||
| 41 | opt.search( |
||
| 42 | objective_function, |
||
| 43 | n_iter=100, |
||
| 44 | verbosity=["progress_bar", "print_times"], |
||
| 45 | ) |
||
| 46 | |||
| 47 | |||
| 48 | def test_verbosity_4(): |
||
| 49 | opt = RandomSearchOptimizer(search_space) |
||
| 50 | opt.search( |
||
| 51 | objective_function, |
||
| 52 | n_iter=100, |
||
| 53 | verbosity=["progress_bar", "print_results"], |
||
| 54 | ) |
||
| 55 | |||
| 56 | |||
| 57 | def test_verbosity_5(): |
||
| 58 | opt = RandomSearchOptimizer(search_space) |
||
| 59 | opt.search(objective_function, n_iter=100, verbosity=[]) |
||
| 60 | |||
| 61 |