partition_quality#
- graph_tool.inference.partition_quality(g, b, weight=None)[git][source]#
Calculate the coverage and the performance of a network partition.
- Parameters:
- g
Graph Graph to be used.
- b
VertexPropertyMap Vertex property map with the community partition.
- weight
EdgePropertyMap(optional, default:None) Edge weights, used only for the coverage.
- g
- Returns:
- coverage
float Fraction of the edges inside the groups.
- performance
float Fraction of the correctly classified pairs of vertices.
- coverage
See also
modularityNewman’s modularity of a partition
cpm_qualityQuality function of the constant Potts model
ModularityStateModularity maximization
Notes
The coverage of a partition \(\boldsymbol b\) [fortunato-community-2010] is the fraction of the edges (or of their total weight) that connect vertices of the same group,
\[c(\boldsymbol b) = \frac{\sum_{(i,j)\in E}w_{ij}\delta_{b_i,b_j}} {\sum_{(i,j)\in E}w_{ij}},\]and its performance is the fraction of the pairs of distinct vertices that are either adjacent and in the same group, or nonadjacent and in different groups,
\[P(\boldsymbol b) = \frac{m_{\text{in}} + \left[\frac{1}{2}\left(V^2 - \sum_rn_r^2\right) - m_{\text{out}}\right]}{\binom{V}{2}},\]where \(n_r\) is the number of vertices in group \(r\), and \(m_{\text{in}}\) and \(m_{\text{out}}\) are the numbers of adjacent pairs of distinct vertices in the same group and in different groups, respectively. For directed graphs, ordered pairs are counted instead, i.e. the denominator is \(V(V - 1)\), the factor \(1/2\) is omitted, and \((i, j)\) is adjacent if there is an edge from \(i\) to \(j\). Parallel edges and self-loops count for the coverage but not for the performance, which considers only whether two vertices are adjacent. Both are computed in time \(O(V + E)\).
Note
These quantities are descriptive, and their maximization does not yield meaningful partitions (e.g. the coverage is maximal for a single group). Principled inference of the groups is offered by
minimize_blockmodel_dl().References
[fortunato-community-2010]Santo Fortunato, “Community detection in graphs”, Physics Reports 486, 75-174 (2010), DOI: 10.1016/j.physrep.2009.11.002 [sci-hub, @tor], arXiv: 0906.0612
Examples
>>> g = gt.collection.data["football"] >>> print(gt.partition_quality(g, g.vp.value)) (0.64274..., 0.94691...)