简体   繁体   English

最小生成树切割后的聚类

[英]Clustering after minimum spanning tree cut

What would be the optimal way of clustering nodes after cutting a MST with a maximum edge-length? 切割具有最大边缘长度的MST之后,群集节点的最佳方法是什么? My output from MST edge-length cut is a 2xN array where each element is an integer. 我从MST边长剪切的输出是2xN数组,其中每个元素都是整数。 The integers are the node identifiers that describe the edges. 整数是描述边缘的节点标识符。 An example of the output would is given below: 输出示例如下:

>>> print array[0:3]
[[  0   1]
 [  0   2]
 [  2  17]]

I'm typically dealing with 100 to 20,000 nodes. 我通常处理100到20,000个节点。 My MST code is sufficiently fast, but it's being bogged down by the clustering/grouping algorithm. 我的MST代码足够快,但是被聚类/分组算法所困扰。 It's a loop-heavy set of functions and that's what is slowing it down. 这是一组繁重的函数,这就是使它变慢的原因。 Check out the following code. 查看以下代码。 Any ideas on how to speed it up? 关于如何加快速度的任何想法? I'm aware that this is a brute force method, so a cleaner method would be best. 我知道这是一种蛮力方法,所以最好使用一种更清洁的方法。 Thanks in advance for your help! 在此先感谢您的帮助!

Cheers, 干杯,

Eli 以利

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

The problem has been solved. 问题已经解决。 Go to the NetworkX google group link to see the solution. 转到NetworkX谷歌论坛链接以查看解决方案。

http://groups.google.com/group/networkx-discuss/browse_thread/thread/4ac4250d460a1b75 http://groups.google.com/group/networkx-discuss/browse_thread/thread/4ac4250d460a1b75

Cheers, 干杯,

Eli 以利

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM