API reference

andrey.metrics.latent_cluster_ari#

andrey.metrics.latent_cluster_ari(estimated, true)[source]#

Adjusted Rand index of the latent clustering of the observed variables.

Clusters each observed node by its latent parent, then scores the two partitions. The two graphs must describe the same observed variables (same indices and labels), though their latent counts may differ; a mismatch raises. Returns 1.0 when there are no observed nodes.

Return type:

float

Examples

>>> from andrey.core import GraphStructure, LATENT, OBSERVED
>>> import numpy as np
>>> # node 2 is a latent parent of observed 0 and 1
>>> m = np.array([[0, 0, 2], [0, 0, 2], [1, 1, 0]], dtype=np.int8)
>>> types = np.array([OBSERVED, OBSERVED, LATENT], dtype=np.int8)
>>> g = GraphStructure.from_numpy(m, kind="dag", node_types=types)
>>> latent_cluster_ari(g, g)
1.0