2017-06-14 153 views
0

有没有在Python办法“排序”的邻接矩阵,以更好地看到连接节点的不同集群?如何排序的邻接矩阵

我有一些矩阵还,但图案看起来像随机分布的就可以了。在现实世界中,我知道例如我有N个独立的群集(中间没有连接)。

所以我想邻接矩阵看起来像有N个不同的模式。

这是可以实现的吗?

更新: 昨天我没有时间,但这里是现在的一些细节:

import networkx as nx 
import numpy as np 
import matplotlib.pyplot as plt 
G = nx.Graph() 
S = {'7064', '7065', '7066', '7067', '7068', '7069', '7070', '7071', '7072', '7073', '7074', '7075', '7076', '7077', '7078', '7079', '7080'} 
E = [('7064', '7065'), 
('7067', '7068'), 
('7067', '7076'), 
('7067', '7077'), 
('7067', '7078'), 
('7067', '7079'), 
('7067', '7080'), 
('7067', '7081'), 
('7068', '7076'), 
('7068', '7077'), 
('7068', '7078'), 
('7068', '7080'), 
('7068', '7081'), 
('7069', '7075'), 
('7070', '7072'), 
('7070', '7074'), 
('7071', '7074'), 
('7076', '7077'), 
('7076', '7078'), 
('7076', '7079'), 
('7076', '7080'), 
('7076', '7081'), 
('7077', '7078'), 
('7077', '7079'), 
('7077', '7080'), 
('7077', '7081'), 
('7078', '7079'), 
('7078', '7080'), 
('7078', '7081'), 
('7079', '7080'), 
('7079', '7081'), 
('7080', '7081')] 
G.add_nodes_from(S) 
G.add_edges_from(E) 
adj_matrix = nx.adjacency_matrix(G).toarray() 

plt.imshow(adj_matrix) 

adjacency matrix

在事实,我只关心上三角,因为它是一个对称矩阵(样品与他们自己)。

sub_graphs = list(nx.connected_components(G)) 
nb_clusters = len(sub_graphs) # total number of sub graphs, including isolated points, there is here 2 isolated points. All other are at least linked with min 1 other point. 

我想邻接矩阵看起来像有6“斑点”(其中两个将是两个孤立点单个像素)。目前,它在其上部三角形中显示了12个视觉上分离的区域(它们仅被视觉分离,实际上矩阵是确定的,但我想重新排列它以更适合子图的实际数量)

+3

如何邻接矩阵代码中的代表?你能展示一些你正在使用的代码吗? – mkrieger1

+0

主文编辑。 –

回答