Conditions | 3 |
Total Lines | 22 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | # Author: Simon Blanke |
||
8 | def init_grid_search(space_dim, n_pos): |
||
9 | positions = [] |
||
10 | |||
11 | n_dim = len(space_dim) |
||
12 | p_per_dim = int(np.power(n_pos, 1 / n_dim)) |
||
13 | |||
14 | for dim in space_dim: |
||
15 | dim_dist = int(dim / (p_per_dim + 1)) |
||
16 | n_points = [n * dim_dist for n in range(1, p_per_dim + 1)] |
||
17 | |||
18 | positions.append(n_points) |
||
19 | |||
20 | pos_mesh = np.array(np.meshgrid(*positions)) |
||
21 | positions = list(pos_mesh.T.reshape(-1, n_dim)) |
||
22 | |||
23 | diff_pos = n_pos - len(positions) |
||
24 | if diff_pos > 0: |
||
25 | pos_rnd = init_random_search(space_dim, n_pos=diff_pos) |
||
26 | |||
27 | return positions + pos_rnd |
||
28 | |||
29 | return positions |
||
30 | |||
39 |