rigraph icon indicating copy to clipboard operation
rigraph copied to clipboard

Plotting a partition of a bipartite graph takes much more time than the entire graph

Open ghost opened this issue 6 years ago • 5 comments

In my code, plotting the entire bipartite graph takes much less time than plotting one of the projections alone (which, of course, have less nodes than the bipartite graph, since it is only a part of the bipartite graph). How can it be?

Here is the code:

rm(list=ls())
library(igraph)
library(tictoc)
nodes <- read.csv("./ma_nodes.csv", header=T, as.is=T)
links <- read.csv("./ma_edges.csv", header=T, as.is=T)
nodes$type <- as.logical(nodes$IsInvestor)
net <- graph_from_data_frame(d=links, vertices=nodes, directed=T)
net.bp <- bipartite_projection(net, multiplicity=F)
net.prj1 = net.bp$proj1
net.prj2 = net.bp$proj2

tic("Plotting bibpartite net")
plot(net)
toc()

tic("Plotting prj2")
plot(net.prj2)
toc()

tic("Plotting prj1")
plot(net.prj1)
toc()

Here is the result:

Plotting bibpartite net: 5.04 sec elapsed
Plotting prj2: 0.21 sec elapsed
Plotting prj1: 77.9 sec elapsed

Also note that using Sys.time() to measure time (and taking the difference end time - start time), this effect is not captured: the result would be that plotting prj1 takes less time than plotting net. But this is not true: plotting the last graph takes way more time than plotting the other twos. It is a problem of sys.time() which is not able to capture that (maybe it has to do with the problem?)

What is going on here?

I can send the files of the dataset if you want, I am just not sure how I can do that

ghost avatar Mar 03 '19 16:03 ghost

It is not the number of nodes that primarily matters when plotting a graph but the number of edges. A bipartite projection can easily have more edges than the initial graph; if you have a vertex of type A with d neighbors of type B in the bipartite graph, the corresponding subgraph in the type B bipartite projection will have d*(d-1)/2 edges. You only need a few vertices of high degree in the initial graph to see this effect.

ntamas avatar Mar 03 '19 19:03 ntamas

I see. Is there a way to speed up the plot? I tried to install the Intel MKL libraries but nothing

ghost avatar Mar 04 '19 06:03 ghost

The Intel MKL libraries would have no effect here.

Is there a way to speed up the plot?

There are two significant time-consuming parts of a plotting call: the layout calculation and the actual drawing itself. You can try using a different layout algorithm using the layout=... argument of the plot() function. layout="circle" can be calculated fast so if plotting is still slow with layout=..., then the drawing is the bottleneck -- otherwise you might be lucky with a different layout algorithm.

ntamas avatar Mar 04 '19 08:03 ntamas

Actually I am pre-calulating the layout in the real code, and then passing to the function the layout parameter

ghost avatar Mar 04 '19 09:03 ghost

The graphics device can be slow as well, e.g. with anti-aliasing, etc.

gaborcsardi avatar Mar 04 '19 09:03 gaborcsardi