graph_tool.inference.align_partition_labels#
- graph_tool.inference.align_partition_labels(x, y)[source]#
Returns a copy of partition
x
, with the group labels aligned as to maximize the overlap withy
.- Parameters:
- xiterable of
int
values Partition.
- xiterable of
- Returns:
- y
numpy.ndarray
Partition with aligned labels.
- y
Notes
This algorithm runs in time \(O[N + (B_x+B_y)E_m]\) where \(N\) is the length of \(\boldsymbol x\) and \(\boldsymbol y\), \(B_x\) and \(B_y\) are the number of labels in partitions \(\boldsymbol x\) and \(\boldsymbol y\), respectively, and \(E_m \le B_xB_y\) is the number of nonzero entries in the contingency table between both partitions.
References
[peixoto-revealing-2021]Tiago P. Peixoto, “Revealing consensus and dissensus between network partitions”, Phys. Rev. X 11 021003 (2021) DOI: 10.1103/PhysRevX.11.021003 [sci-hub, @tor], arXiv: 2005.13977
Examples
>>> x = [0, 2, 2, 1, 1, 1, 2, 3, 2] >>> y = gt.shuffle_partition_labels(x) >>> print(y) [0 3 3 2 2 2 3 1 3] >>> gt.align_partition_labels(y, x) array([0, 2, 2, 1, 1, 1, 2, 3, 2], dtype=int32)