def test_norm_epsilon(): """Test computation of espilon norm on TF coefficients.""" n_steps = 5 n_freqs = 4 Y = np.zeros(n_steps * n_freqs) l1_ratio = 0.5 assert_allclose(norm_epsilon(Y, l1_ratio, n_steps), 0.) Y[0] = 2. assert_allclose(norm_epsilon(Y, l1_ratio, n_steps), np.max(Y)) l1_ratio = 1. assert_allclose(norm_epsilon(Y, l1_ratio, n_steps), np.max(Y)) # dummy value without random: Y = np.arange(n_steps * n_freqs).reshape(-1, ) l1_ratio = 0. assert_allclose( norm_epsilon(Y, l1_ratio, n_steps)**2, stft_norm2(Y.reshape(-1, n_freqs, n_steps)))
def test_norm_epsilon(): """Test computation of espilon norm on TF coefficients.""" tstep = np.array([2]) wsize = np.array([4]) n_times = 10 n_steps = np.ceil(n_times / tstep.astype(float)).astype(int) n_freqs = wsize // 2 + 1 n_coefs = n_steps * n_freqs phi = _Phi(wsize, tstep, n_coefs) Y = np.zeros(n_steps * n_freqs) l1_ratio = 0.5 assert_allclose(norm_epsilon(Y, l1_ratio, phi), 0.) Y[0] = 2. assert_allclose(norm_epsilon(Y, l1_ratio, phi), np.max(Y)) l1_ratio = 1. assert_allclose(norm_epsilon(Y, l1_ratio, phi), np.max(Y)) # dummy value without random: Y = np.arange(n_steps * n_freqs).reshape(-1, ) l1_ratio = 0. assert_allclose(norm_epsilon(Y, l1_ratio, phi) ** 2, stft_norm2(Y.reshape(-1, n_freqs[0], n_steps[0])))
def test_norm_epsilon(): """Test computation of espilon norm on TF coefficients.""" tstep = np.array([2]) wsize = np.array([4]) n_times = 10 n_steps = np.ceil(n_times / tstep.astype(float)).astype(int) n_freqs = wsize // 2 + 1 n_coefs = n_steps * n_freqs phi = _Phi(wsize, tstep, n_coefs) Y = np.zeros(n_steps * n_freqs) l1_ratio = 0.5 assert_allclose(norm_epsilon(Y, l1_ratio, phi), 0.) Y[0] = 2. assert_allclose(norm_epsilon(Y, l1_ratio, phi), np.max(Y)) l1_ratio = 1. assert_allclose(norm_epsilon(Y, l1_ratio, phi), np.max(Y)) # dummy value without random: Y = np.arange(n_steps * n_freqs).reshape(-1, ) l1_ratio = 0. assert_allclose(norm_epsilon(Y, l1_ratio, phi) ** 2, stft_norm2(Y.reshape(-1, n_freqs[0], n_steps[0])))
def test_norm_epsilon(): """Test computation of espilon norm on TF coefficients.""" tstep = np.array([2]) wsize = np.array([4]) n_times = 10 n_steps = np.ceil(n_times / tstep.astype(float)).astype(int) n_freqs = wsize // 2 + 1 n_coefs = n_steps * n_freqs phi = _Phi(wsize, tstep, n_coefs, n_times) Y = np.zeros(n_steps * n_freqs) l1_ratio = 0.03 assert_allclose(norm_epsilon(Y, l1_ratio, phi), 0.) Y[0] = 2. assert_allclose(norm_epsilon(Y, l1_ratio, phi), np.max(Y)) l1_ratio = 1. assert_allclose(norm_epsilon(Y, l1_ratio, phi), np.max(Y)) # dummy value without random: Y = np.arange(n_steps * n_freqs).reshape(-1, ) l1_ratio = 0.0 assert_allclose( norm_epsilon(Y, l1_ratio, phi)**2, stft_norm2(Y.reshape(-1, n_freqs[0], n_steps[0]))) l1_ratio = 0.03 # test that vanilla epsilon norm = weights equal to 1 w_time = np.ones(n_coefs[0]) Y = np.abs(np.random.randn(n_coefs[0])) assert_allclose(norm_epsilon(Y, l1_ratio, phi), norm_epsilon(Y, l1_ratio, phi, w_time=w_time)) # scaling w_time and w_space by the same amount should divide # epsilon norm by the same amount Y = np.arange(n_coefs) + 1 mult = 2. assert_allclose( norm_epsilon(Y, l1_ratio, phi, w_space=1, w_time=np.ones(n_coefs)) / mult, norm_epsilon(Y, l1_ratio, phi, w_space=mult, w_time=mult * np.ones(n_coefs)))