align_nested_partition_labels

align_nested_partition_labels#

graph_tool.inference.align_nested_partition_labels(x, y)[source]#

Returns a copy of nested partition x, with the group labels aligned as to maximize the overlap with y.

Parameters:
xiterable of iterables of int values or iterable of PropertyMap

Nested partition.

yiterable of iterables of int values or iterable of PropertyMap

Reference nested partition.

Returns:
zlist of numpy.ndarray or list of PropertyMap

Nested partition x with labels aligned to y.

Notes

This algorithm runs in time \(O[\sum_l N_l + (B_x^l+B_y^l)E_m^l]\) where \(B_x^l\) and \(B_y^l\) are the number of labels in partitions \(\bar{\boldsymbol x}\) and \(\bar{\boldsymbol y}\) at level \(l\), respectively, and \(E_m^l \le B_x^lB_y^l\) is the number of nonzero entries in the contingency table between both partitions.

Examples

>>> x = [[0, 2, 2, 1, 1, 1, 2, 3, 2], [1, 0, 1, 0], [0,0]]
>>> y = gt.shuffle_nested_partition_labels(x)
>>> print(y)
[array([3, 1, 1, 2, 2, 2, 1, 0, 1], dtype=int32), array([0, 1, 0, 1], dtype=int32), array([0, 0], dtype=int32)]
>>> gt.align_nested_partition_labels(y, x)
[array([0, 2, 2, 1, 1, 1, 2, 3, 2], dtype=int32), array([1, 0, 1, 0], dtype=int32), array([0, 0], dtype=int32)]