本文介绍了igraph或其他库文库重叠社区检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在小型网络/图表中检测重叠社区。通过重叠,我的意思是一个节点可以包含在检测算法输出中的多个社区/集群中。



我已经看过各种社区检测算法,由 igraph 提供,但我认为它们都不会处理重叠的社区。

理想情况下,我希望能够以编程方式在Python中利用这些算法的一些实现。但是,其他语言的实现也可以。

我已经实现了算法Ahn等人之前使用igraph的Python接口;请参阅其源代码。



另外,将CFinder使用igraph的Python相当简单;这是我想出来的:

 #!/ usr / bin / env python $ b $ itertools导入组合

import igraph
import optparse

parser = optparse.OptionParser(usage =%prog [options] infile)
parser.add_option( - k,metavar =K,默认值= 3,type = int,
help =使用K的集团大小)

options,args = parser.parse_args()

如果不是args:
parser.error(必需的输入文件作为第一个参数)

k = options.k
g = igraph.load(args
cls = map(set,g.maximal_cliques(min = k))

edgelist = []
for [0],format =ncol,directed = False)如果len(cls [i] .intersection(cls [j])))> = k-1:
edgelist,则组合(范围(len(cls)),2):
。 append((i,j))

cg = igraph.Graph(edgelist,directed = False)
clusters = cg.clusters()
用于集群中的集群:
members = set()
for my cluster:
members.update(cls [i])
print \\t。加入(g.vs [成员] [ 名称])


I would like to detect overlapping communities in small networks/graphs. By overlapping, I mean that a node can be included within more than one communities/clusters in the output of the detection algorithm.

I have looked at various community detection algorithms curretly provided by igraph, but I think none of them handles overlapping communities.

Ideally, I would like to be able to programmatically utilize some implementation of such algorithm(s) in Python. However, implementation in other languages is OK too.

解决方案

I have implemented the hierarchical link clustering algorithm of Ahn et al a while ago using the Python interface of igraph; see its source code here.

Also, implementing CFinder in Python using igraph is fairly easy; this is what I came up with:

#!/usr/bin/env python
from itertools import combinations

import igraph
import optparse

parser = optparse.OptionParser(usage="%prog [options] infile")
parser.add_option("-k", metavar="K", default=3, type=int,
        help="use a clique size of K")

options, args = parser.parse_args()

if not args:
    parser.error("Required input file as first argument")

k = options.k
g = igraph.load(args[0], format="ncol", directed=False)
cls = map(set, g.maximal_cliques(min=k))

edgelist = []
for i, j in combinations(range(len(cls)), 2):
    if len(cls[i].intersection(cls[j])) >= k-1:
        edgelist.append((i, j))

cg = igraph.Graph(edgelist, directed=False)
clusters = cg.clusters()
for cluster in clusters:
    members = set()
    for i in cluster:
        members.update(cls[i])
    print "\t".join(g.vs[members]["name"])

这篇关于igraph或其他库文库重叠社区检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 10:40