def test_mtl(): rho_noise = 0.3 SNR = 1 n_epochs, n_channels, n_sources, n_times = 5, 20, 10, 30 pb_name = "MTL" tol = 1e-7 X, all_epochs, B_star, S_star = get_data_me( dictionary_type="Gaussian", noise_type="Gaussian_iid", n_epochs=n_epochs, n_channels=n_channels, n_times=n_times, n_sources=n_sources, n_active=3, rho_noise=rho_noise, SNR=SNR) Y = np.mean(all_epochs, axis=0) sigma_min = get_sigma_min(Y) alpha_max = get_alpha_max(X, Y, sigma_min, pb_name=pb_name) alpha_div = 5 alpha = alpha_max / alpha_div B_mtl, S_inv, E, gaps = solver( X, Y, alpha, alpha_max, sigma_min, B0=None, tol=tol, pb_name=pb_name, n_iter=10000) gap = gaps[-1] np.testing.assert_array_less(gap, tol) _, _, E, gaps = solver( X, Y, alpha, alpha_max, sigma_min, B0=B_mtl, tol=tol, pb_name=pb_name, n_iter=10000) np.testing.assert_equal(len(E), 2) gap = gaps[-1] np.testing.assert_array_less(gap, tol * E[0])
def test_mtl_me(): rho_noise = 0.3 SNR = 1 n_epochs, n_channels, n_sources, n_times = 5, 20, 10, 30 pb_name = "MTLME" tol = 1e-7 X, all_epochs, _, _ = get_data_me(dictionary_type="Gaussian", noise_type="Gaussian_iid", n_epochs=n_epochs, n_channels=n_channels, n_times=n_times, n_sources=n_sources, n_active=3, rho_noise=rho_noise, SNR=SNR) Y = np.mean(all_epochs, axis=0) sigma_min = get_sigma_min(Y) alpha_max = get_alpha_max(X, all_epochs, sigma_min, pb_name=pb_name) alpha_div = 1.1 alpha = alpha_max / alpha_div gap = solver(X, all_epochs, alpha, sigma_min, B0=None, tol=tol, pb_name=pb_name, n_iter=10000)[-1] np.testing.assert_array_less(gap, tol)
def tests_sgcl(dictionary_type="Gaussian", noise_type="Gaussian_iid", rho_noise=0.3, SNR=0.5, n_channels=20, n_times=30, n_sources=10, n_active=3, gap_freq=100, active_set_freq=1, S_freq=10, n_iter=10**6, p_alpha_max=0.9, tol=10**-4): X, all_epochs, _, _ = get_data_me(dictionary_type="Gaussian", noise_type=noise_type, n_channels=n_channels, n_times=n_times, n_sources=n_sources, n_active=n_active, rho_noise=rho_noise, SNR=SNR, n_epochs=50) Y = all_epochs.mean(axis=0) sigma_min = get_sigma_min(Y) alpha_max = get_alpha_max(X, Y, sigma_min, "SGCL") alpha = alpha_max * p_alpha_max print("alpha = %.2e" % alpha) print("sigma_min = %.2e" % sigma_min) all_epochs = np.zeros((1, *Y.shape)) all_epochs[0] = Y B_sgcl, S_inv_sgcl, E, (gaps, gaps_accel) = solver( X, Y, alpha, alpha_max, sigma_min, B0=None, n_iter=n_iter, gap_freq=gap_freq, active_set_freq=active_set_freq, S_freq=S_freq, pb_name="SGCL", use_accel=True, tol=tol, verbose=True) log_gap = np.log10(gaps[-1]) log_gap_accel = np.log10(gaps_accel[-1]) assert log_gap_accel < np.log10(tol) * E[0] or \ log_gap < np.log10(tol) * E[0]
def test_mrce(): rho_noise = 0.6 SNR = 1 n_epochs, n_channels, n_sources, n_times = 5, 20, 10, 30 pb_name = "mrce" tol = 1e-4 X, all_epochs = get_data_me(dictionary_type="Gaussian", noise_type="Gaussian_multivariate", n_epochs=n_epochs, n_channels=n_channels, n_times=n_times, n_sources=n_sources, n_active=3, rho_noise=rho_noise, SNR=SNR)[:2] alpha_Sigma_inv = 0.01 Y = np.mean(all_epochs, axis=0) sigma_min = get_sigma_min(Y) alpha_max = get_alpha_max(X, all_epochs, sigma_min, pb_name=pb_name, alpha_Sigma_inv=alpha_Sigma_inv) alpha = alpha_max * 0.9 solver(X, all_epochs, alpha, sigma_min, B0=None, tol=tol, pb_name=pb_name, n_iter=1000, alpha_Sigma_inv=alpha_Sigma_inv)
def test_clar(noise_type="Gaussian_iid", rho_noise=0.3, SNR=0.5, n_channels=20, n_times=30, n_sources=10, n_epochs=50, n_active=3, gap_freq=50, active_set_freq=1, S_freq=10, n_iter=10**4, alpha_under_alpha_max=0.2, tol=1e-7): X, all_epochs, _, _ = get_data_me(dictionary_type="Gaussian", noise_type=noise_type, n_epochs=n_epochs, n_channels=n_channels, n_times=n_times, n_sources=n_sources, n_active=n_active, rho_noise=rho_noise, SNR=SNR) Y = np.mean(all_epochs, axis=0) sigma_min = get_sigma_min(Y) alpha_max = get_alpha_max(X, all_epochs, sigma_min, pb_name="CLAR") alpha = alpha_max * \ alpha_under_alpha_max print("alpha = %.2e" % alpha) print("alpha = %.2e" % alpha) print("sigma_min = %.2e" % sigma_min) gaps_me = solver(X, all_epochs, alpha, sigma_min, B0=None, n_iter=n_iter, gap_freq=gap_freq, active_set_freq=active_set_freq, S_freq=S_freq, tol=tol, pb_name="CLAR")[-1] gap_me = gaps_me[-1] assert gap_me < tol
S_star = S_star[-1] Y = np.mean(all_epochs, axis=0) sigma_min = get_sigma_min(Y) alpha_max = get_alpha_max_me(X, all_epochs, sigma_min) alpha = alpha_max / 5 print("alpha = %.2e" % alpha) print("sigma_min = %.2e" % sigma_min) B_clar, S_inv, E, gaps_me = solver(X, all_epochs, alpha, alpha_max, sigma_min, B0=None, n_iter=n_iter, gap_freq=50, S_freq=update_S_freq, tol=tol, pb_name="CLAR") gap_me = gaps_me[-1] assert gap_me < tol try: matplotlib.rcParams["text.usetex"] = True except: print("Could not use tex for matplotlib rendering") fig, axarr = plt.subplots(1, 2) S = np.linalg.inv(S_inv)