0

I'm trying to project a bipartite graph into two single mode graphs.

I'm want to analyze a bipartite graph using the dual projection approach. I have been using NetworkX, but I wanted to try graph-tool since it claims to be more efficient. There is a chance that my graph will get very big very quickly, so I want to use the most efficient method/package. The package graph-tool claims to be more efficient, and I would like to try it out, but I cannot find a way to project a bipartite graph using it. Does anybody know if this is possible using graph-tool? The only information I found was the creator asking somebody who asked a similar question to create a ticket so that he/they can start working on it, but it's from 2014.

Jean
  • 11
  • 1
  • 4

1 Answers1

1

I had the same problem and got a solution working. I have got it working on graphs up to 5 million nodes.

It follows three main steps:

  1. use the is_bipartite function to generate a boolean array of which set each vertex belongs to.
  2. loop over the set to be removed adding edges between all combinations of neighbours.
  3. use the GraphView to generate a new graph by only keep the nodes of the set of interest.
g = gt.lattice([5,5])
is_biparitite, part = gt.is_bipartite(g, partition=True)
gt.graph_draw(g, vertex_fill_color=part)  # to view the full graph coloured by set

from itertools import combinations

g_temp = g.copy()  # this is a deepcopy

for v, bipartite_label in enumerate(part):
    if bipartite_label == 0:
        neighbours = list(g.vertex(v).all_neighbours())

        for s, t in combinations(neighbours, 2):
            g_temp.add_edge(s, t)

g_projected = gt.Graph(gt.GraphView(g_temp, vfilt=part.a==1), prune=True)

gt.graph_draw(g_projected)
wem
  • 11
  • 1