igraph-help
[Top][All Lists]

## Re: [igraph] beginner's question

 From: Gábor Csárdi Subject: Re: [igraph] beginner's question Date: Sun, 20 Dec 2009 16:23:51 +0100

```Dear Prof Freeman,

On Sun, Dec 20, 2009 at 3:21 PM, Lin Freeman <address@hidden> wrote:
> Hi,
>
> I have a beginner's question.  I'm running various community-finders an a
> data set.  I've had success
> with spinglass and walktrap, but I can't get fastgreedy to run.  See below:
>
>
>> B <-D[,1:2]-1
>> library(igraph)
>> g <- graph(t(as.matrix(B)), directed=FALSE
> + )
>> E(g)\$weight <- D[,3]
>> fastgreedy.community(g, merges=TRUE, modular=TRUE, weights=E(g)\$weight)
> Error in fastgreedy.community(g, merges = TRUE, modular = TRUE, weights =
> E(g)\$weight) :
>   At fast_community.c:536 : fast-greedy community finding works only on
> simple graphs, Invalid value

the problem is not only self-loops, but multiple edges. If you create
your graph like this, and you have an edge A-B both in the form of A B
and in the form of B A in the file, then igraph creates two edges and
you end up with a multigraph. This is easy to check:

is.simple(g)
[1] FALSE
sum(is.multiple(g))
[1] 139

The solution is to call simplify() on the graph:

library(igraph)
g <- simplify(g)
fastgreedy.community(g)

Best Regards,
Gabor

--