align_partition_labels

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 with y.

Parameters:
xiterable of int values or PropertyMap

Partition.

yiterables of int values or PropertyMap

Reference partition.

Returns:
znumpy.ndarray or PropertyMap

Partition x with labels aligned to 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)
[3 1 1 2 2 2 1 0 1]
>>> gt.align_partition_labels(y, x)
array([0, 2, 2, 1, 1, 1, 2, 3, 2], dtype=int32)