| Total Complexity | 8 |
| Total Lines | 58 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # Author: Simon Blanke |
||
| 2 | # Email: [email protected] |
||
| 3 | # License: MIT License |
||
| 4 | |||
| 5 | |||
| 6 | import numpy as np |
||
| 7 | |||
| 8 | |||
| 9 | class SearchSpace: |
||
| 10 | def __init__(self, _config_): |
||
| 11 | self.search_config = _config_.search_config |
||
| 12 | self.warm_start = _config_.warm_start |
||
| 13 | self.scatter_init = _config_.scatter_init |
||
| 14 | |||
| 15 | self.memory = {} |
||
| 16 | |||
| 17 | def pos_space_limit(self): |
||
| 18 | dim = [] |
||
| 19 | |||
| 20 | for pos_key in self.para_space: |
||
| 21 | dim.append(len(self.para_space[pos_key]) - 1) |
||
| 22 | |||
| 23 | self.dim = np.array(dim) |
||
| 24 | |||
| 25 | def create_kerasSearchSpace(self): |
||
| 26 | """ |
||
| 27 | para_space = {} |
||
| 28 | |||
| 29 | for para_key in search_config_temp.keys(): |
||
| 30 | |||
| 31 | for param_str in search_config_temp[para_key].keys(): |
||
| 32 | new_param_str = para_key + "." + param_str |
||
| 33 | |||
| 34 | para_space[new_param_str] = search_config_temp[para_key][param_str] |
||
| 35 | |||
| 36 | """ |
||
| 37 | |||
| 38 | self.para_space = self.search_config[list(self.search_config)[0]] |
||
| 39 | |||
| 40 | self.pos_space_limit() |
||
| 41 | |||
| 42 | def get_random_pos(self): |
||
| 43 | pos_new = np.random.uniform(np.zeros(self.dim.shape), self.dim, self.dim.shape) |
||
| 44 | pos = np.rint(pos_new) |
||
| 45 | |||
| 46 | # n_zeros = [0] * len(self.dim) |
||
| 47 | # pos = np.clip(pos_new_int, n_zeros, self.dim) |
||
| 48 | return pos |
||
| 49 | |||
| 50 | def pos2para(self, pos): |
||
| 51 | if len(self.para_space.keys()) == pos.size: |
||
| 52 | values_dict = {} |
||
| 53 | for i, key in enumerate(self.para_space.keys()): |
||
| 54 | pos_ = int(pos[i]) |
||
| 55 | values_dict[key] = list(self.para_space[key])[pos_] |
||
| 56 | |||
| 57 | return values_dict |
||
| 58 |