pyagc.metrics.structure_metrics
- structure_metrics(edge_index: Tensor, clusters: Tensor, metrics: Union[str, Tuple[str, ...]] = ('Mod', 'Cond'), vectorized: bool = True) Dict[str, float][source]
Computes structural clustering metrics on a graph.
Supports modularity and conductance measures for evaluating the structural quality of clustering on graphs.
- Parameters:
edge_index (torch.Tensor) – Undirected edge index tensor of shape
(2, num_edges).clusters (torch.Tensor) – Cluster assignments of shape
(num_nodes,).metrics (str or tuple of str, optional) – Structural metrics to compute. Valid options are:
'Mod','Cond'. (default:('Mod', 'Cond'))vectorized (bool, optional) – Whether to use vectorized computation for better performance. (default:
True)
- Returns:
Dict[str,float] – Dictionary mapping metric names to their computed values.
Example
>>> # Fast vectorized version (default) >>> result = structure_metrics(edge_index, clusters, metrics=('Mod', 'Cond')) >>> print(result) {'Mod': 0.45, 'Cond': 0.32}
>>> # Loop-based version >>> result = structure_metrics(edge_index, clusters, vectorized=False)