For your case there is more than one way to create bipartite sets
since the original graph isn't connected.
Either way is a correct bipartitioning. So I don't think it is a bug.
Aric
Cheers,
Chris
2012/2/13 Christian Guckelsberger <in...@abyi.com>:
> Thanks for your quick reply, Aric. I think I got your point. It's a pity
> anyway that networkx doesn't preserve the original sets used to initialize
> the bipartite graph..
There is no Bipartite Graph Class in NetworkX, so you have to keep
track of which set each node belongs to, and make sure that there is
no edge between nodes of the same set. However, many of the algorithms
targeted to bipartite networks in NetworkX (see
networkx.algorithms.bipartite) need, as a parameter, a container with
all the nodes that belong to one set. A useful convention is to add an
attribute called "bipartite" to each node with values 0 or 1 to
identify the sets. So you could do something like this:
In [1]: import networkx as nx
In [2]: from networkx.algorithms import bipartite
In [3]: G = nx.Graph()
In [4]: G.add_nodes_from([1,2,3,4], bipartite=0)
In [5]: G.add_nodes_from(['a','b','c'], bipartite=1)
In [6]: G.add_edges_from([(1,'a'),(1,'b'),(2,'b'),(3,'c')])
In [7]: top_nodes = [n for n,d in G.nodes(data=True) if d['bipartite']==0]
In [8]: bipartite.betweenness_centrality(G,top_nodes)
Out[8]:
{1: 0.16666666666666666,
2: 0.0,
3: 0.0,
4: 0.0,
'a': 0.0,
'b': 0.15384615384615385,
'c': 0.0}
Salut!
excellent hint, cheers!
Best wishes,
Chris