igraph-help
[Top][All Lists]

## [igraph] Re: your spinglass.community function in the R igraph library

 From: Gábor Csárdi Subject: [igraph] Re: your spinglass.community function in the R igraph library Date: Sun, 7 Feb 2010 20:11:34 +0100

```Dear Avril,

here are a bunch of examples on how get membership vectors for the
various community finding algorithms. The partitioning with the
maximal modularity score is chosen for the methods that return a full
merge tree.

memberships <- list()

pause()

### edge.betweenness.community
ebc <- edge.betweenness.community(G)
mods <- sapply(0:ecount(G), function(i) {
g2 <- delete.edges(G, ebc\$removed.edges[seq(length=i)])
cl <- clusters(G)\$membership
modularity(G, cl)
})

g2 <- delete.edges(G, ebc\$removed.edges[1:(which.max(mods)-1)])
memberships\$`Edge betweenness` <- clusters(g2)\$membership

pause()

### fastgreedy.community
fc <- fastgreedy.community(G)
memb <- community.to.membership(G, fc\$merges,
steps=which.max(fc\$modularity)-1)
memberships\$`Fast greedy` <- memb\$membership

pause()

pause()

### spinglass.community
sc <- spinglass.community(G, spins=10)
memberships\$`Spinglass` <- sc\$membership

pause()

### walktrap.community
wt <- walktrap.community(G, modularity=TRUE)
wmemb <- community.to.membership(G, wt\$merges,
steps=which.max(wt\$modularity)-1)
memberships\$`Walktrap` <- wmemb\$membership

pause()

### label.propagation.community
memberships\$`Label propagation` <- label.propagation.community(G)

Best,
Gabor

On Sat, Feb 6, 2010 at 7:39 PM, Coghlan, Avril <address@hidden> wrote:
> Dear Gabor, and igraph developers,
>
> makes a lot of sense that it gives different results each time because it is
> starting from different random start-points each time.
>
> By the way, I found spinglass.community() very nice because it returns a
> vector "membership" that tells you which community each vertex belongs to.
> I looked at other igraph functions for finding communities (eg.
> fastgreedy.community(), walktrap.community()) and found that they don't seem
> to return any information on which community each vertex is a member of - or
> at least, I couldn't figure out how to infer that information from their
> output - is there a way to do that? (sorry if I am being very slow)
>
> One last thing, I wrote a function that makes a plot of a graph (using
> Rgraphviz) and plots the communities found by spinglass.community() on the
> graph, by colouring in the vertices belonging to each particular community in
> a different colour (eg. one community in red, a second community in green
> etc.)
> Do you think that this function would be useful enough that it would be worth
> including in igraph (or in Rgraphviz)? If so, I would be happy to send you
> the code for my function.
>
> Kind regards,
> Avril
> Avril Coghlan
> University College Cork, Ireland
>
> -----Original Message-----
> Sent: 19 January 2010 19:41
> To: Coghlan, Avril
> Subject: Re: your spinglass.community function in the R igraph library
>
> Dear Avril,
>
> I think you got Jörg's email address wrong, you are supposed to
> replace the 'lastname' part with his last name.
>
> On Tue, Jan 19, 2010 at 1:11 PM, Coghlan, Avril <address@hidden> wrote:
>> Dear Jorg and Gabor,
>>
>>
>>
>> I have been using your spinglass.community() function in the R "igraph"
>> library for identifying communities in a network, and am finding it very
>> useful.
>>
>> I noticed that sometimes when I run this function repeatedly on the same
>> graph, it gives slightly different answers for the communities.
>>
>> I am wondering if this is expected?
>
> It is. It is a randomized algorithm, or at least it starts from a
> random configuration of spins.
>
>> I imagine that you might be using a random number generator in this
>> function, and this is the reason why when you run it again and again on the
>> same input graph, it gives slightly different answers each time - is this
>> right?
>
> It is perfectly right. The version in the igraph package uses R's
> RNG's so if you set the R RNG seed with 'set.seed()', then you should
> always get the same results. This is useful if you want to reproduce
> things.
>
> Btw. it is better to write to the igraph-help mailing list, than to me
> directly, see http://igraph.sf.net for details. Thanks.
>
> Best,
> Gabor
>
>>
>>
>> Regards,
>>
>> Avril Coghlan
>>
>> University College Cork, Ireland
>>
>>
>
>
>
> --
> Gabor Csardi <address@hidden>     UNIL DGM
>

--