src.spectral_clustering.spectral_clustering¶
- src.spectral_clustering.spectral_clustering(sim_matrix: torch.Tensor, cluster_num: int, init: Optional[torch.Tensor] = None, return_state: bool = False, normalized: bool = False)[source]¶
Perform spectral clustering based on given similarity matrix.
This function firstly computes the leading eigenvectors of the given similarity matrix, and then utilizes the eigenvectors as features and performs k-means clustering based on these features.
- Parameters
sim_matrix – \((n\times n)\) input similarity matrix. \(n\): number of instances
cluster_num – number of clusters
init – the initialization technique or initial features for k-means
return_state – whether return state features (can be further used for prediction)
normalized – whether to normalize the similarity matrix by its degree
- Returns
the belonging of each instance to clusters, state features (if
return_state==True
)