igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] how to "collapse" a network


From: Tamás Nepusz
Subject: Re: [igraph] how to "collapse" a network
Date: Tue, 6 Mar 2012 10:36:54 +0100

Hello Peter,

It happens frequently that the same companies engage in multiple deals
together, but each deal is represented by a line in my data. As a
result, you see that 'COMP 1' -- 'COMP 2' occurs twice.
I would like to be able to collapse this to a weighted edge list where
'COMP 1' -- 'COMP 2' occurs only once but with value 2, 'COMP 1' --
'COMP 3' occurs only once having value 3, et cetera.
There must be a very simple way of doing this, but how?
I assume that you are using igraph from R. The "simplify" function in igraph 0.6 will sum up numeric edge attributes when it eliminates multiple edges, so I guess the easiest for you is to upgrade to the development version of igraph (that is, 0.6). Since it has not been released officially yet, you can download it from the page of our nightly builds:

http://code.google.com/p/igraph/downloads/list

Download the latest "GNU R source package", and install it in R. If you happen to use Windows and need a pre-compiled package, let us know - Gabor can probably prepare one for you.

Unfortunately if you cannot upgrade to igraph 0.6 for any reason, then the only option is to use count.multiple to find the "multiplicity" of each edge, and then construct a new graph manually; e.g., like this (not sure if there is a simpler solution):

mul <- count.multiple(g)
df <- as.data.frame(get.edgelist(g))
df$weight <- cm
g <- graph.data.frame(unique(df))

Second, each company has several attributes, including industry. One of
the things I would like to do is to collapse the entire
company*company network into a weigted industry*industry network. This
would reduce the network from approx. 2000*2000 to 40*40.
How can I construct such a weighted network in igraph?
igraph 0.6 will also have a function called contract.vertices which lets you contract many vertices into a single one, so you could proceed by first contracting the vertices by industry using contract.vertices, followed by simplify.

-- 
T.

reply via email to

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