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

Add verbose option

parent 975f019c
No related branches found
No related tags found
No related merge requests found
import numpy as np import numpy as np
from tqdm import tqdm
from math import ceil from math import ceil
...@@ -135,7 +136,11 @@ def constrained_argmax(mem, cc, tij_ind, curr_tij, used_tij, t_max, n_ind): ...@@ -135,7 +136,11 @@ def constrained_argmax(mem, cc, tij_ind, curr_tij, used_tij, t_max, n_ind):
return mem_tij[:, np.argmax(mem_val)] return mem_tij[:, np.argmax(mem_val)]
def smart_gsrp(cc, n_ind, n_tot, t_max, tree, program, clean_list): def _get_mem_size(memory):
return sum(len(o[0].T) for o in memory.values())
def smart_gsrp(cc, n_ind, n_tot, t_max, tree, program, clean_list, verbose=False):
memory = dict() memory = dict()
val = cc[:, 0].prod() val = cc[:, 0].prod()
tij = np.zeros(n_tot, int) tij = np.zeros(n_tot, int)
...@@ -166,7 +171,10 @@ def smart_gsrp(cc, n_ind, n_tot, t_max, tree, program, clean_list): ...@@ -166,7 +171,10 @@ def smart_gsrp(cc, n_ind, n_tot, t_max, tree, program, clean_list):
for k in range(j): for k in range(j):
memory[(i, k)] = mask_lim(memory[(i, k)], tij_min, tij_max, t_max) memory[(i, k)] = mask_lim(memory[(i, k)], tij_min, tij_max, t_max)
# print('tdoa:', tij, 'val:', val, 'mem size:', (lambda x: f'{x} ({100 * x / (n_ind//(i+1)) / (2 * t_max + 1) ** (i+1)}%)')(sum(len(o[0].T) for o in memory.values()))) if verbose:
mem_size = _get_mem_size(memory)
tqdm.write(f'TDOA: {tij}, val: {val}, mem size: {mem_size} items,'
f' {100 * mem_size / (n_ind // (i + 1)) / (2 * t_max + 1) ** (i + 1)}%')
# Mem clean up # Mem clean up
for p in clean_list[i]: for p in clean_list[i]:
......
...@@ -44,7 +44,7 @@ def slicer(down, up, ndim, n): ...@@ -44,7 +44,7 @@ def slicer(down, up, ndim, n):
return slices[index].reshape(ndim, -1).T return slices[index].reshape(ndim, -1).T
def corr(data, pos, w_size, max_tdoa, decimate=1, mode='prepare', hyper=True): def corr(data, pos, w_size, max_tdoa, decimate=1, mode='prepare', hyper=True, verbose=False):
num_channels = data.shape[1] num_channels = data.shape[1]
num_channel_pairs = num_channels * (num_channels - 1) // 2 num_channel_pairs = num_channels * (num_channels - 1) // 2
...@@ -119,7 +119,7 @@ def corr(data, pos, w_size, max_tdoa, decimate=1, mode='prepare', hyper=True): ...@@ -119,7 +119,7 @@ def corr(data, pos, w_size, max_tdoa, decimate=1, mode='prepare', hyper=True):
tdoas[i, :2], tdoas[i, 2:] = c_corr.c_corr_all(cc, cc_size//2, num_channels - 1) tdoas[i, :2], tdoas[i, 2:] = c_corr.c_corr_all(cc, cc_size//2, num_channels - 1)
elif mode == 'smart': elif mode == 'smart':
tdoas[i, :2], tdoas[i, 2:] = smart_gsrp(cc, num_channels - 1, num_channel_pairs, cc_size // 2, tdoas[i, :2], tdoas[i, 2:] = smart_gsrp(cc, num_channels - 1, num_channel_pairs, cc_size // 2,
tree, program, clean_list) tree, program, clean_list, verbose=verbose)
else: else:
raise ValueError(f'Unknown mode {mode}') raise ValueError(f'Unknown mode {mode}')
tdoas[i, 1] += maxs tdoas[i, 1] += maxs
...@@ -184,7 +184,8 @@ def main(args): ...@@ -184,7 +184,8 @@ def main(args):
print("Computing TDOAs...") print("Computing TDOAs...")
results = corr(sound, pos, int(sr * args.frame_size), max_tdoa=int(np.ceil(sr * args.max_tdoa)), results = corr(sound, pos, int(sr * args.frame_size), max_tdoa=int(np.ceil(sr * args.max_tdoa)),
decimate=args.decimate if not args.temporal else 1, mode=args.mode, hyper=not args.no_hyperres) decimate=args.decimate if not args.temporal else 1, mode=args.mode, hyper=not args.no_hyperres,
verbose=args.verbose)
if args.no_hyperres: if args.no_hyperres:
result1 = results result1 = results
else: else:
...@@ -273,6 +274,7 @@ if __name__ == "__main__": ...@@ -273,6 +274,7 @@ if __name__ == "__main__":
f'{BColors.BOLD}smart{BColors.ENDC} gradually increase the search space dimension, ' f'{BColors.BOLD}smart{BColors.ENDC} gradually increase the search space dimension, '
f'reducing the number of tdoa to evaluate.\n' f'reducing the number of tdoa to evaluate.\n'
f'{BColors.BOLD}auto{BColors.ENDC} automatically try to pick the right method.') f'{BColors.BOLD}auto{BColors.ENDC} automatically try to pick the right method.')
group4.add_argument('-v', '--verbose', action='store_true', help='Activate verbose for smart mode')
args = parser.parse_args() args = parser.parse_args()
try: try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment