cpm_quality#
- graph_tool.inference.cpm_quality(g, b, gamma=1.0, weight=None, vweight=None)[git][source]#
Calculate the quality function of the constant Potts model for a network partition.
- Parameters:
- g
Graph Graph to be used (the edge directions are ignored).
- b
VertexPropertyMap Vertex property map with the community partition.
- gamma
float(optional, default:1.) Resolution parameter.
- weight
EdgePropertyMap(optional, default:None) Edge weights.
- vweight
VertexPropertyMap(optional, default:None) Vertex weights (sizes). If not given, every vertex has weight one.
- g
- Returns:
- H
float The quality of the partition.
- H
See also
modularityNewman’s modularity of a partition
partition_qualityCoverage and performance of a partition
ModularityStateModularity maximization
Notes
The constant Potts model (CPM) of Traag, Van Dooren, and Nesterov [traag-narrow-2011] has the quality function
\[H = \sum_r\left[e_r - \gamma\frac{n_r(n_r - 1)}{2}\right],\]where \(e_r\) is the number of edges inside group \(r\) (or their total weight), including self-loops, \(n_r\) its number of vertices (or their total weight), and \(\gamma\) is
gamma, so that the groups are subgraphs with densities above \(\gamma\). It is the quality maximized by the Leiden algorithm with the CPM objective. It is computed in time \(O(V + E)\).Note
As with the modularity, the maximization of this quality function does not distinguish structure from randomness, and the result depends on the arbitrary choice of \(\gamma\). Principled inference of the groups is offered by
minimize_blockmodel_dl().References
[traag-narrow-2011]V. A. Traag, P. Van Dooren and Y. Nesterov, “Narrow scope for resolution-limit-free community detection”, Phys. Rev. E 84, 016114 (2011), DOI: 10.1103/PhysRevE.84.016114 [sci-hub, @tor], arXiv: 1104.3083
Examples
>>> g = gt.collection.data["football"] >>> print(gt.cpm_quality(g, g.vp.value, gamma=0.1)) 341.69...