xgi.communities.spectral#

Community detection via clustering of Laplacian eigenvectors.

Functions

spectral_clustering(H, k=2, max_iter=1000, seed=None)[source]#

Computes a spectral clustering in \(k\) partitions of the input hypergraph according to the heuristic presented in [1].

This is done by computing the normalized Laplacian of the input hypergraph and then applying \(k\)-means clustering on the hypergraph vertices represented in the \(k\)-dimensional Euclidian space generated by the eigenvectors corresponding to the \(k\) smallest eigenvalues of the normalized Laplacian.

Parameters:
  • H (Hypergraph) – Hypergraph

  • k (int, optional) – Number of clusters to find, default 2.

  • max_iter (int, optional.) – Maximum number of cluster updates to compute, default 1,000.

  • seed (int, optional) – Seed used to initialize clusters, optional.

Returns:

A dictionary mapping node ids to their clusters. Clusters begin at 0.

Return type:

dict

Raises:

XGIError – If more groups are specified than nodes in the hypergraph.

References