| Total Complexity | 7 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | """ |
||
| 2 | Hyperactive is very versatile, because of it can handle not just numerical or |
||
| 3 | string variables in the search space, but also functions. This enables many |
||
| 4 | possibilities for more complex optimization applications. Neural architecture search, |
||
| 5 | feature engineering, ensemble optimization and many other applications are |
||
| 6 | only possible or much easier, if you can put functions in the search space. |
||
| 7 | """ |
||
| 8 | |||
| 9 | from hyperactive import Hyperactive |
||
| 10 | |||
| 11 | |||
| 12 | def function_0(): |
||
| 13 | pass |
||
| 14 | |||
| 15 | |||
| 16 | def function_1(): |
||
| 17 | pass |
||
| 18 | |||
| 19 | |||
| 20 | def function_2(): |
||
| 21 | pass |
||
| 22 | |||
| 23 | |||
| 24 | def list1(): |
||
| 25 | return [1, 0, 0] |
||
| 26 | |||
| 27 | |||
| 28 | def list2(): |
||
| 29 | return [0, 1, 0] |
||
| 30 | |||
| 31 | |||
| 32 | def list3(): |
||
| 33 | return [0, 0, 1] |
||
| 34 | |||
| 35 | |||
| 36 | # Hyperactive can handle python objects in the search space |
||
| 37 | search_space = { |
||
| 38 | "int": list(range(1, 10)), |
||
| 39 | "float": [0.1, 0.01, 0.001], |
||
| 40 | "string": ["string1", "string2"], |
||
| 41 | "function": [function_0, function_1, function_2], |
||
| 42 | "list": [list1, list2, list3], |
||
| 43 | } |
||
| 44 | |||
| 45 | |||
| 46 | def objective_function(para): |
||
| 47 | # score must be a single number |
||
| 48 | score = 1 |
||
| 49 | return score |
||
| 50 | |||
| 51 | |||
| 52 | hyper = Hyperactive() |
||
| 53 | hyper.add_search(objective_function, search_space, n_iter=20) |
||
| 54 | hyper.run() |
||
| 55 | |||
| 56 | search_data = hyper.results(objective_function) |
||
| 57 | |||
| 58 | print("\n Search Data: \n", search_data) |
||
| 59 |