From 8e1488b9fa0f4913a473ba80159daab90f830411 Mon Sep 17 00:00:00 2001 From: Robin Scheibler Date: Thu, 30 Apr 2020 23:52:35 +0900 Subject: [PATCH] Making min dist a little faster --- bss_scale/algorithms.py | 16 ++++++------ bss_scale/surrogate.py | 6 ++--- experiment2_config.json | 32 +++++++++++++++++++++++ experiment1_rpt.py => paper_simulation.py | 0 4 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 experiment2_config.json rename experiment1_rpt.py => paper_simulation.py (100%) diff --git a/bss_scale/algorithms.py b/bss_scale/algorithms.py index a00915c..6ad3ca1 100644 --- a/bss_scale/algorithms.py +++ b/bss_scale/algorithms.py @@ -85,7 +85,7 @@ def minimum_distortion_l2(Y, ref): def minimum_distortion( - Y, ref, p=None, q=None, rtol=1e-3, max_iter=100, + Y, ref, p=None, q=None, rtol=1e-2, max_iter=100, ): """ This function computes the frequency-domain filter that minimizes the sum @@ -135,7 +135,7 @@ def minimum_distortion( eps = 1e-15 - prev_res = None + prev_c = None epoch = 0 while epoch < max_iter: @@ -145,9 +145,9 @@ def minimum_distortion( # the current error error = ref[:, :, None] - c * Y if q is None or p == q: - res, weights = lp_norm(error, p=p) + weights = lp_norm(error, p=p) else: - res, weights = lpq_norm(error, p=p, q=q, axis=1) + weights = lpq_norm(error, p=p, q=q, axis=1) # minimize num = np.sum(ref[:, :, None] * np.conj(Y) * weights, axis=0) @@ -155,13 +155,13 @@ def minimum_distortion( c = num / np.maximum(eps, denom) # condition for termination - if prev_res is None: - prev_res = res + if prev_c is None: + prev_c = c continue # relative step length - delta = (prev_res - res) / prev_res - prev_res = res + delta = np.linalg.norm(c - prev_c) / np.linalg.norm(prev_c) + prev_c = c if delta < rtol: break diff --git a/bss_scale/surrogate.py b/bss_scale/surrogate.py index a1bf7a6..d362230 100644 --- a/bss_scale/surrogate.py +++ b/bss_scale/surrogate.py @@ -7,16 +7,14 @@ def lp_norm(E, p=1): assert p > 0 and p < 2 - cost = np.sum(np.abs(E) ** p) weights = p / np.maximum(eps, 2.0 * np.abs(E) ** (2 - p)) - return cost, weights + return weights def lpq_norm(E, p=1, q=2, axis=1): assert p > 0 and q >= p and q <= 2.0 - cost = np.sum(np.sum(np.abs(E) ** q, axis=axis, keepdims=True) ** (p / q)) rn = np.sum(np.abs(E) ** q, axis=axis, keepdims=True) ** (1 - p / q) qfn = np.abs(E) ** (2 - q) weights = p / np.maximum(eps, 2.0 * rn * qfn) - return cost, weights + return weights diff --git a/experiment2_config.json b/experiment2_config.json new file mode 100644 index 0000000..f0b2bdc --- /dev/null +++ b/experiment2_config.json @@ -0,0 +1,32 @@ +{ + "metadata_fn": "./bss_speech_dataset/data/metadata.json", + + "stft": { + "nfft": 512, + "hop": 256, + "window": "hamming" + }, + + "ref_mic": 0, + "si_metric": false, + "snr": 40, + + "minimum_distortion": { + "p_list": [0.1, 2.0, 20], + "kwargs": { + "rtol": 1e-5, + "max_iter": 100 + } + }, + + "bss_algorithms": { + "ilrma_t": { + "name": "ilrma_t", + "kwargs": { + "n_taps": 6, + "n_delays": 1 + }, + "n_iter_per_channel": 15 + } + } +} diff --git a/experiment1_rpt.py b/paper_simulation.py similarity index 100% rename from experiment1_rpt.py rename to paper_simulation.py