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:
- g
Graph Bipartite graph to be used (the edge directions are ignored).
- b
VertexPropertyMap Scalar vertex property map with the groups of the vertices (of both kinds).
- kind
VertexPropertyMap(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.- weight
EdgePropertyMap(optional, default:None) Edge weights.
- g
- Returns:
- Q
float The bipartite modularity.
- Q
See also
graph_tool.inference.modularityNewman’s modularity
graph_tool.inference.ModularityStateModularity maximization
graph_tool.structure.is_bipartiteTest 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
kindequal 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 (seemodularity()), 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 aValueError. 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 optionpclabel.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...