[英]Clustering after minimum spanning tree cut
切割具有最大邊緣長度的MST之后,群集節點的最佳方法是什么? 我從MST邊長剪切的輸出是2xN數組,其中每個元素都是整數。 整數是描述邊緣的節點標識符。 輸出示例如下:
>>> print array[0:3]
[[ 0 1]
[ 0 2]
[ 2 17]]
我通常處理100到20,000個節點。 我的MST代碼足夠快,但是被聚類/分組算法所困擾。 這是一組繁重的函數,這就是使它變慢的原因。 查看以下代碼。 關於如何加快速度的任何想法? 我知道這是一種蠻力方法,所以最好使用一種更清潔的方法。 在此先感謝您的幫助!
干杯,
以利
def _super_intersection(edges):
group = set(edges[0])
index = np.array([0])
k = 0
while k < 100:
k += 1
i = 0
for edge in edges[1:]:
i += 1
edge = set(edge)
if group & edge:
group = group | edge
index = np.append(index, i)
index = np.unique(np.array(index))
return group, index
def cluster(self, gmin = 5):
# A 2xN array of node IDs
edges = self.edges
group_nodes = {}
for no, edge in enumerate(edges):
try:
group, indice = _super_intersection(edges)
id_no = no
edges = np.delete(edges,indice,0)
if len(group) >= gmin:
group_nodes[id_no] = list(group)
except:
self.group_nodes = group_nodes
問題已經解決。 轉到NetworkX谷歌論壇鏈接以查看解決方案。
http://groups.google.com/group/networkx-discuss/browse_thread/thread/4ac4250d460a1b75
干杯,
以利
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.