bipartite_modularity

bipartite_modularity#

graph_tool.clustering.bipartite_modularity(g, b, kind=None, weight=None)[git][source]#

Compute Barber’s modularity of a partition of a bipartite graph.

Parameters:
gGraph

Bipartite graph to be used (the edge directions are ignored).

bVertexPropertyMap

Scalar vertex property map with the groups of the vertices (of both kinds).

kindVertexPropertyMap (optional, default: None)

Scalar vertex property map with the kinds of the vertices (zero for one kind, nonzero for the other). If not given, the partition found by is_bipartite() is used.

weightEdgePropertyMap (optional, default: None)

Edge weights.

Returns:
Qfloat

The bipartite modularity.

See also

graph_tool.inference.modularity

Newman’s modularity

graph_tool.inference.ModularityState

Modularity maximization

graph_tool.structure.is_bipartite

Test for bipartiteness

Notes

The bipartite modularity of Barber [barber-modularity-2007] is

\[Q_B = \frac{1}{m}\sum_{i\in R}\sum_{j\in B}\left(A_{ij} - \frac{k_id_j}{m}\right)\delta_{b_i,b_j},\]

where \(R\) and \(B\) are the vertices of the two kinds (with kind equal to zero and nonzero, respectively), \(A_{ij}\) is the number of edges between \(i\) and \(j\) (or their total weight), \(k_i\) and \(d_j\) are the (weighted) degrees of \(i\) and \(j\), \(m\) is the number of edges (or their total weight), and \(b_i\) is the group of vertex \(i\). Unlike the modularity of Newman (see modularity()), the null model allows edges only between vertices of different kinds. Its value is at most \(1 - 1/c\) for \(c\) groups. An edge between vertices of the same kind raises a ValueError. It is computed in time \(O(V + E)\).

Note

As with the modularity, maximizing this quality function to find communities is subject to overfitting and other problems. Principled inference of bipartite community structure is offered by minimize_blockmodel_dl(), with the option pclabel.

References

[barber-modularity-2007]

Michael J. Barber, “Modularity and community detection in bipartite networks”, Phys. Rev. E 76, 066102 (2007), DOI: 10.1103/PhysRevE.76.066102 [sci-hub, @tor]

Examples

>>> g = gt.collection.ns["davis_southern_women"]
>>> b = gt.spectral_clustering(g, 2)
>>> print(gt.bipartite_modularity(g, b, g.vp.is_woman))
0.31839414...