def test_dijkstra_vs_dense_backbone(): """ Test Closure: Dijkstra vs Dense backbone return """ C_Dense_m = transitive_closure(D, kind='metric', algorithm='dense') B_Dense_m = backbone(D, C_Dense_m) C_Djisktra_m = transitive_closure(D, kind='metric', algorithm='dijkstra') B_Djisktra_m = backbone(D_sparse, C_Djisktra_m) # The Sparse matrix version does not put a -1 in the diagonal. B_Djisktra_m = B_Djisktra_m.A np.fill_diagonal( B_Djisktra_m, -1) assert (B_Dense_m == B_Djisktra_m).all()
File.close() return llista # First, the DEanalysis.r script needs to be run to get the individual x individual correlation matrices. # Convert to Distance corr_matrix = 'Data/Correlation_matrix.txt' corr_matrix_array = from_corr_matrix_to_array(corr_matrix) D = prox2dist(corr_matrix_array) # Calculate transitive closure using the metric and ultra-metric (also known maximum flow) measure Cm = transitive_closure(D, kind='metric') Cu = transitive_closure(D, kind='ultrametric') # Retrieve the backbone edges Bm = backbone(D, Cm) Bu = backbone(D, Cu) # Backbone edges on Bm and Bu can be accessed, where edges with a 1 are metric. # We used the backbone edges based on the ultra-metric transitive closure. rows, cols = np.where(Bu == 1) # We get a two columns file where only the nodes that are connected through a backbone edge are showed. t = "" for element in map_index_to_ID(corr_matrix): if t == "": t = element[0] + ',' + element[1] + '\n' else: t += element[0] + ',' + element[1] + '\n' fd = open('Data/Backbone_edges.txt', 'w')
def test_dense_backbone(): """ Test Closure: Dense Backbone return """ Cm = transitive_closure(D, kind='metric', algorithm='dense') Bm = backbone(D, Cm) assert np.isclose(Bm, Bm_true).all()