|
From: | S. M. Ali Abbas |
Subject: | Re: [igraph] Collapsing/Folding graph based on vertex attributes |
Date: | Tue, 11 Sep 2012 17:27:47 +0100 |
User-agent: | Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20120824 Thunderbird/15.0 |
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 value
Could you please shed more light how to do this mapping? Thanks! Cheers, AliI 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:
Hi, 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.
[Prev in Thread] | Current Thread | [Next in Thread] |