NetworkX

Table Of Contents

Previous topic

attribute_mixing_dict

Next topic

is_bipartite

Bipartite

This module provides functions and operations for bipartite graphs. Bipartite graphs G(X,Y,E) have two node sets X,Y and edges in E that only connect nodes from opposite sets.

NetworkX does not have a custom bipartite graph class but the Graph() or DiGraph() classes can be used to represent bipartite graphs.

For example:

>>> import networkx as nx
>>> top_nodes=[1,1,2,3,3]
>>> bottom_nodes=['a','b','b','b','c']
>>> edges=zip(top_nodes,bottom_nodes) # create 2-tuples of edges
>>> B=nx.Graph(edges) 

The bipartite algorithms are not imported into the networkx namespace at the top level so the easiest way to use them is with:

>>> from networkx.algorithms import bipartite

Some of the functions such as bipartite_density and projected_graph take a node set as an argument in addition to the graph B.

>>> print(bipartite.density(B,top_nodes))
1.0
>>> G=bipartite.projected_graph(B,bottom_nodes)
>>> G.edges()
[('a', 'b'), ('c', 'b')]

You can find the bipartite node sets using

>>> X,Y=bipartite.sets(B)
>>> print(list(X))
['a', 'c', 'b']
>>> print(list(Y))
[1, 2, 3]

Basic functions

is_bipartite(G) Returns True if graph G is bipartite, False if not.
is_bipartite_node_set(G, nodes) Returns True if nodes and G/nodes are a bipartition of G.
sets(G) Returns bipartite node sets of graph G.
color(G) Returns a two-coloring of the graph.
density(B, nodes) Return density of bipartite graph B.
degrees(B, nodes[, weight]) Return the degrees of the two node sets in the bipartite graph B.

Projections

Create one-mode (unipartite) projections from bipartite graphs.

projected_graph(B, nodes[, multigraph]) Return the graph that is the projection of the bipartite graph B
weighted_projected_graph(B, nodes[, ratio]) Return a weighted unipartite projection of B onto the nodes of
collaboration_weighted_projected_graph(B, nodes) Weighted unipartite projection of B onto the nodes of
overlap_weighted_projected_graph(B, nodes[, ...]) Return the overlap weighted projection of B onto the nodes of
generic_weighted_projected_graph(B, nodes[, ...]) Return the weighted unipartite projection of B onto the nodes of

Spectral

Spectral bipartivity measure.

spectral_bipartivity(G[, nodes, weight]) Returns the spectral bipartivity.

Clustering

clustering(G[, nodes, mode]) Compute a bipartite clustering coefficient for nodes.
average_clustering(G[, nodes, mode]) Compute the average bipartite clustering coefficient.

Redundancy

Node redundancy for bipartite graphs.

node_redundancy(G[, nodes]) Compute bipartite node redundancy coefficient.

Centrality

closeness_centrality(G, nodes[, normalized]) Compute the closeness centrality for nodes in a bipartite network.
degree_centrality(G, nodes) Compute the degree centrality for nodes in a bipartite network.
betweenness_centrality(G, nodes) Compute betweenness centrality for nodes in a bipartite network.