igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] calculating modularity


From: Gábor Csárdi
Subject: Re: [igraph] calculating modularity
Date: Thu, 9 Dec 2010 20:08:48 +0100

Hi Khanh,

On Wed, Dec 8, 2010 at 7:39 PM, Khanh Nguyen <address@hidden> wrote:
> Hi all,
>
> I create a graph as follow
>
> src <- c('a','b','c','e','f')
> dst <- c('b','c','d','f','g')
> ee  <- cbind(src,dst)
> g1  <- graph.edgelist(as.matrix(ee), directed=FALSE)
>
> and two vector describing the community structure of the graph
>
> c1 <- c("1", "a", "b" , "c" , "d")
> c2 <- c("2", "e","f","g")

If you have your vectors in 'memblist', e.g. in your case:

memblist <- list(c1[-1], c2[-1])

then you can get a membership vector like this:

memb <- rep(seq_along(memblist), sapply(memblist, length))[
match(V(g1)$name, unlist(memblist))]

This works for any number of communities. I haven't tested it much, so
please double check it.

Best,
Gabor

> I'd like to use modularity() to compute the modularity but I am
> struggling to generate the "membership" parameter correctly. How can I
> map the community assignment in this form to the node's id? Thanks.
>
> Regards,
>
> -k
>
> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help
>



-- 
Gabor Csardi <address@hidden>     UNIL DGM



reply via email to

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