示例#1
0
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()
示例#2
0
        Index_r = rows[index]
        Index_c = cols[index]
        if [F[Index_c], F[Index_r]] not in llista:
            llista.append([F[Index_r], F[Index_c]])
    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'
示例#3
0
def test_dijkstra_vs_dense_transitive_closure_ultrametric():
	""" Test Closure: Dijkstra vs Dense ultra metric comparison """
	C_Dense_um = transitive_closure(D, kind='ultrametric', algorithm='dense')
	C_Djisktra_um = transitive_closure(D_sparse, kind='ultrametric', algorithm='dijkstra')	
	assert (C_Dense_um == C_Djisktra_um.A).all()
示例#4
0
def test_dijkstra_vs_dense_transitive_closure_ultrametric():
	""" Test Closure: Dijkstra vs Dense metric comparison """
	C_Dense_um = transitive_closure(D, kind='metric', algorithm='dense')
	C_Djisktra_um = transitive_closure(D, kind='metric', algorithm='dijkstra')	
	assert (C_Dense_um == dict2matrix(C_Djisktra_um)).all()
示例#5
0
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()
示例#6
0
def test_dense_transitive_closure_ultrametric():
	""" Test Closure: Dense Transitive Closure (Ultrametric) """
	Cu = transitive_closure(D, kind='ultrametric', algorithm='dense')
	assert np.isclose(Cu, Cu_true).all()
示例#7
0
def test_dense_transitive_closure_metric():
	""" Test Closure: Dense Transitive Closure (Metric) """
	Cm = transitive_closure(D, kind='metric', algorithm='dense', verbose=True)
	assert np.isclose(Cm , Cm_true).all()
示例#8
0
def test_dense_transitive_closure_faults_nonzerodiagonal():
	""" Test Closure: Dense for non-zero diagonal """
	Dtmp = D.copy()
	Dtmp[0][0] = 1
	transitive_closure(Dtmp, kind='metric', verbose=True)