igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Community finding in graphs


From: MATSUDA, Noriyuki
Subject: Re: [igraph] Community finding in graphs
Date: Wed, 12 Dec 2007 11:27:57 +0900

Hello:

   Thanks a lot.

At 6:12 PM +0100 07.12.11, Tamas Nepusz wrote:
Hi,

   I just found an intriguing community detection algorithm that tries to
reflect overlaps
A quick implementation in Python (and I assume it's similar in R):

# g is an undirected graph. If not, keep only the mutual edge pairs before doing this
from igraph import *

# search for all cliques
cliques = [set(clique) for clique in g.cliques(min=3)]

# sort the cliques by length
cliques_by_length = {}
for clique in cliques:
  k = len(clique)
  if not cliques_by_length.has_key(k): cliques_by_length[k] = []
  cliques_by_length[k].append(clique)

for k in cliques_by_length.keys():
  # create clique adjacency graph for all k
  adjacencies = []
  cs = cliques_by_length[k]
  for idx1, c1 in enumerate(cs):
    for idx2, c2 in enumerate(cs):
      if len(c1.union(c2)) == k+1:
        adjacencies.append((idx1, idx2))
  clique_graph = Graph(len(cs), adjacencies)
  # determine the connected components
  components = clique_graph.components()

  print "k=%d:" % k
  for component in components:
    community = set()
    for clique_idx in component: community.update(cs[clique_idx])
    print "  %s" % str(community)

This should work for small and medium sized sparse graphs. Note that the clique detection routine in igraph uses substantially less memory in the dev tree than in the last stable version, so you might consider installing the development version.

--
T.


_______________________________________________
igraph-help mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/igraph-help


--
MATSUDA, Noriyuki <in Kanji> 松 田 紀 之




reply via email to

[Prev in Thread] Current Thread [Next in Thread]