def run_one_exp(n, k, dim, ampl, type_matrix, scaled, n_avrg, type_lap=None, type_noise='gaussian'): """ Run n_avrg experiments for a given set of parameters, and return the mean kendall-tau score and the associated standard deviation (among the n_avrg instances). """ # Pre-defined settings for Laplacian_Fiedler : if circular, random_walk, # if linear, unnormalized; Laplacian_init : random_walk if not type_lap: type_lap = 'random_walk' if type_matrix[0] == 'L': circular = False elif type_matrix[0] == 'C': circular = True else: raise ValueError("type matrix must be in ['LinearBanded'," "'CircularBanded', 'LinearStrongDecrease'," "'CircularStrongDecrease']") # Create matrix generator data_gen = MatrixGenerator() # Create spectral solver reord_method = SpectralOrdering(dim=dim, k_nbrs=k, circular=circular, scaled=scaled, type_laplacian=type_lap, verb=1) # Initialize array of results scores = np.zeros(n_avrg) for i_exp in range(n_avrg): np.random.seed(i_exp) data_gen.gen_matrix(n, type_matrix=type_matrix, apply_perm=True, noise_ampl=ampl, law=type_noise) this_perm = reord_method.fit_transform(data_gen.sim_matrix) scores[i_exp] = evaluate_ordering(this_perm, data_gen.true_perm, circular=circular) print('.', end='') print('') return (scores.mean(), scores.std(), scores)
type_matrix=type_similarity, apply_perm=apply_perm, noise_ampl=ampl_noise, law=type_noise) # Call Spectral Ordering method reord_method = SpectralOrdering(n_components=n_components, k_nbrs=k_nbrs, circular=circular, scale_embedding=scaled, norm_laplacian='random_walk') my_perm = reord_method.fit_transform(data_gen.sim_matrix) reord_method.new_sim = reord_method.new_sim.toarray() # reord_method.fit(data_gen.sim_matrix) score = evaluate_ordering(my_perm, data_gen.true_perm, circular=circular) print("Kendall-Tau score = {}".format(score)) inv_perm = np.argsort(data_gen.true_perm) # Display some results fig, axes = plt.subplots(2, 2) axes[0, 0].tick_params( axis='x', # changes apply to the x-axis which='both', # both major and minor ticks are affected bottom=False, # ticks along the bottom edge are off top=False, # ticks along the top edge are off labelbottom=False) # labels along the bottom edge are off axes[0, 0].matshow(data_gen.sim_matrix[:, inv_perm][inv_perm, :]) axes[0, 0].set_title("raw matrix") axes[0, 1].tick_params( axis='x', # changes apply to the x-axis
for i_exp in range(10): np.random.seed(i_exp) n = 150 data_gen = SimilarityMatrix() data_gen.gen_matrix(n, type_matrix='CircularBanded', noise_prop=0.1, noise_ampl=5, apply_perm=False) X = data_gen.sim_matrix # plt.matshow(X) # plt.show() X = coo_matrix(X) pp = spectral_eta_trick(X, do_plot=True, n_iter=30, dh=20, circular=True) pp2 = spectral_eta_trick3(X, do_plot=True, n_iter=30, avg_dim=1) pp3 = spectral_eta_trick3(X, do_plot=True, dh=20, score_function='Huber', n_iter=100, avg_dim=5, avg_scaling=True) pp3 = spectral_eta_trick3(ord_mat, do_plot=True, dh=30, score_function='R2S', n_iter=100, avg_dim=8, avg_scaling=True, eigen_solver='amg') pp = spectral_eta_trick(X, do_plot=True, n_iter=50, dh=20, circular=True, eigen_solver='amg') kt1 = evaluate_ordering(pp, np.arange(n)) kt2 = evaluate_ordering(pp2, np.arange(n)) print("kt1: %2.2f" % (kt1)) print("kt2: %2.2f" % (kt2))
def run_one_exp(n, k, dim, ampl, type_matrix, n_avrg, type_noise='gaussian', norm_laplacian='unnormalized', norm_adjacency=False, scale_embedding='heuristic', embedding_method='spectral'): """ Run n_avrg experiments for a given set of parameters, and return the mean kendall-tau score and the associated standard deviation (among the n_avrg instances). """ if type_matrix[0] == 'L': circular = False elif type_matrix[0] == 'C': circular = True else: raise ValueError("type matrix must be in ['LinearBanded'," "'CircularBanded', 'LinearStrongDecrease'," "'CircularStrongDecrease']") # Create matrix generator data_gen = SimilarityMatrix() # Create spectral solver if embedding_method == 'TSNE': reord_method = SpectralOrdering(n_components=2, k_nbrs=k, norm_adjacency=norm_adjacency, norm_laplacian=norm_laplacian, scale_embedding=scale_embedding, circular=circular, merge_if_ccs=True, embedding_method=embedding_method) else: reord_method = SpectralOrdering(n_components=dim, k_nbrs=k, norm_adjacency=norm_adjacency, norm_laplacian=norm_laplacian, scale_embedding=scale_embedding, circular=circular, merge_if_ccs=True, embedding_method=embedding_method) # Initialize array of results scores = np.zeros(n_avrg) for i_exp in range(n_avrg): np.random.seed(i_exp) data_gen.gen_matrix(n, type_matrix=type_matrix, apply_perm=True, noise_ampl=ampl, law=type_noise) this_perm = reord_method.fit_transform(data_gen.sim_matrix) scores[i_exp] = evaluate_ordering(this_perm, data_gen.true_perm, circular=circular) return (scores.mean(), scores.std(), scores)