Skip to content
Snippets Groups Projects
Commit b17cfe1d authored by ferrari's avatar ferrari
Browse files

Fix smart method search space

parent 7b3e656c
No related branches found
No related tags found
No related merge requests found
...@@ -107,6 +107,12 @@ def mask_val(mem, val): ...@@ -107,6 +107,12 @@ def mask_val(mem, val):
return mem[0][mask], mem[1][mask] return mem[0][mask], mem[1][mask]
def constrained_argmax(mem, tij_ind, t_max):
min_t, max_t = tij_ind.min(), tij_ind.max()
mask = ((max_t - t_max <= mem[1]) & (mem[1] <= min_t + t_max)).all(-1)
return mem[1][mask][np.argmax(mem[0][mask])]
def smart_gsrp(cc, n_ind, n_tot, t_max, tree, program, clean_list): def smart_gsrp(cc, n_ind, n_tot, t_max, tree, program, clean_list):
memory = dict() memory = dict()
val = 0 val = 0
...@@ -124,8 +130,9 @@ def smart_gsrp(cc, n_ind, n_tot, t_max, tree, program, clean_list): ...@@ -124,8 +130,9 @@ def smart_gsrp(cc, n_ind, n_tot, t_max, tree, program, clean_list):
memory[(i, j)] = mul(mask_val(memory[(i-1, op.left)], val), mask_val(memory[(0, op.right)], val), memory[(i, j)] = mul(mask_val(memory[(i-1, op.left)], val), mask_val(memory[(0, op.right)], val),
cc, t_max, tree[i - 1][op.left], tree[0][op.right][0], n_ind) cc, t_max, tree[i - 1][op.left], tree[0][op.right][0], n_ind)
# find potential maximum # find potential maximum
tij[:] = 0
for j in range(len(step)): for j in range(len(step)):
tij[tree[i][j]] = memory[(i, j)][1][np.argmax(memory[(i, j)][0])] tij[tree[i][j]] = constrained_argmax(memory[(i, j)], tij[:n_ind], t_max)
dep_tdoa(tij, n_ind, n_tot) dep_tdoa(tij, n_ind, n_tot)
val = cc[tij, np.arange(n_tot)].prod() val = cc[tij, np.arange(n_tot)].prod()
# print('tdoa:', tij, 'val:', val, 'mem size:', (lambda x: f'{x} ({100 * x / (2 * t_max + 1) ** i}%)')(sum(len(o[0]) for o in memory.values()))) # print('tdoa:', tij, 'val:', val, 'mem size:', (lambda x: f'{x} ({100 * x / (2 * t_max + 1) ** i}%)')(sum(len(o[0]) for o in memory.values())))
......
...@@ -120,11 +120,12 @@ def corr(data, pos, w_size, max_tdoa, decimate=1, mode='prepare', hyper=True): ...@@ -120,11 +120,12 @@ def corr(data, pos, w_size, max_tdoa, decimate=1, mode='prepare', hyper=True):
cc /= maxs cc /= maxs
val, tij = smart_gsrp(cc.T, num_channels - 1, num_channel_pairs, cc_size // 2, tree, program, clean_list) val, tij = smart_gsrp(cc.T, num_channels - 1, num_channel_pairs, cc_size // 2, tree, program, clean_list)
tdoas[i, 0], tdoas[i, 1:] = np.log10(val * maxs.prod()), tij[:(num_channels - 1)] tdoas[i, 0], tdoas[i, 1:] = np.log10(val * maxs.prod()), tij[:(num_channels - 1)]
cc *= maxs
else: else:
raise ValueError(f'Unknown mode {mode}') raise ValueError(f'Unknown mode {mode}')
if hyper: if hyper:
tdoas[i, 0], tdoas2[i, 1:] = _hyperres(tdoas[i, 1:], cc) tdoas2[i, 0], tdoas2[i, 1:] = _hyperres(tdoas[i, 1:], cc)
if hyper: if hyper:
return np.hstack((np.expand_dims(pos, -1), tdoas)), np.hstack((np.expand_dims(pos, -1), tdoas2)) return np.hstack((np.expand_dims(pos, -1), tdoas)), np.hstack((np.expand_dims(pos, -1), tdoas2))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment