[Top][All Lists]

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

Re: [igraph] Collapsing/Folding graph based on vertex attributes

From: S. M. Ali Abbas
Subject: Re: [igraph] Collapsing/Folding graph based on vertex attributes
Date: Tue, 11 Sep 2012 17:46:37 +0100
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120824 Thunderbird/15.0

Hi Gabor,

That's brilliant. It is working now. Thanks a bunch for the workaround and the explanation! You both are really helpful. I will now apply the sum function for the count and the weight attributes, as Tamas suggested earlier.

Thanks again!


On 11/09/2012 17:35, Gábor Csárdi wrote:
Hi Ali,

contract.vertices() just takes a vector that gives the group id for
each vertex. E.g. if you have nine vertices and three groups each,
then 'mapping' can be something like this: c(1,1,2,2,3,1,2,3,3). So if
you just want to contract the vertices according to ethnic groups,
then you'll need to code the ethnic group using integer numbers, and
supply that as 'mapping'. An easy way to do this is to convert it to a
factor. This should work:

contracted_g <- contract.vertices(g,
vertex.attr.comb=list(Ethnic.Group=toString, "ignore"))


On Tue, Sep 11, 2012 at 12:27 PM, S. M. Ali Abbas <address@hidden> wrote:
Hi Tamas,
Thanks a lot for your help. I highly appreciate it. This contract function,
it seems has been introduced in Igraph 0.6.
I am struggling to apply the same on my graph. Specifically, I couldn't
understand the mapping parameter in the function. The help page says that it
should correspond to the elements of vertices. In my case, for instance,
there are 57 unique ethnicities. That means the contracted graph, based on
ethnicity vertex attribute, should have just 57 vertices. Do I have to know
vertex ID within each ethnicity, and then supply it here? This is how I
(incorrectly) did it:

contracted_g <- contract.vertices(g, 1:length(unique(V(g)$Ethnic.Group)),
vertex.attr.comb=list(Ethnic.Group=toString, "ignore")) # just consider
Ethnic group attribute, and ignore the rest for now.

As expected, I am getting this error:

At structural_properties.c:6915 : Invalid mapping vector length, Invalid

Could you please shed more light how to do this mapping?



I unfortunately could not make it work for my graph. I am sorry but I am
struggling to use this on my graph. The mapping parameter is

On 11/09/2012 15:05, Tamás Nepusz wrote:

Use the contract.vertices() function first to contract the vertices, then
use simplify() to collapse multiple edges between the now-contracted
vertices into a single one. These functions let you specify what to do with
the attributes of the original vertices and edges. For instance, if you want
the new (contracted) vertices to have a "count" attribute that contains the
number of vertices they were contracted from, this can be achieved by adding
a "count" attribute to every vertex of the original graph with a value of 1
and then use vertex.attr.comb=list(count="sum") to specify that you want to
sum the "count" attributes while collapsing. Similarly, you can assign a
"weight" of 1 to every edge before calling simplify() and then sum the
weight of the collapsed edges.

igraph-help mailing list

reply via email to

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