Spectral Clustering#
Spectral clustering is a graph-based clustering technique that uses the eigenvalues of similarity matrices to identify clusters with complex, non-convex shapes.
#include <cuvs/cluster/spectral.hpp>
namespace cuvs::cluster::spectral
Parameters#
-
struct params#
- #include <spectral.hpp>
Parameters for spectral clustering.
Public Members
-
int n_clusters#
Number of clusters to find
-
int n_components#
Number of eigenvectors to use for the spectral embedding (typically equal to n_clusters)
-
int n_init#
Number of k-means runs with different centroid seeds
-
int n_neighbors#
Number of nearest neighbors for constructing the connectivity graph
-
float tolerance#
Tolerance for the eigenvalue solver
-
raft::random::RngState rng_state = {0}#
Random number generator state for reproducibility
-
int n_clusters#
Spectral Clustering#
- void fit_predict(
- raft::resources const &handle,
- params config,
- raft::device_coo_matrix_view<float, int, int, int> connectivity_graph,
- raft::device_vector_view<int, int> labels
Perform spectral clustering on a connectivity graph.
#include <cuvs/cluster/spectral.hpp> #include <cuvs/preprocessing/spectral_embedding.hpp> raft::resources handle; // Create connectivity graph from data auto graph = raft::make_device_coo_matrix<float>(handle, n_samples, n_samples); cuvs::preprocessing::spectral_embedding::params embed_params; embed_params.n_neighbors = 15; cuvs::preprocessing::spectral_embedding::helpers::create_connectivity_graph( handle, embed_params, X.view(), graph); // Configure and run spectral clustering cuvs::cluster::spectral::params params; params.n_clusters = 5; params.n_components = 5; params.n_neighbors = 15; params.n_init = 10; auto labels = raft::make_device_vector<int>(handle, n_samples); cuvs::cluster::spectral::fit_predict(handle, params, graph.view(), labels.view());
- Parameters:
handle – [in] RAFT resource handle
config – [in] Spectral clustering parameters
connectivity_graph – [in] Sparse COO matrix representing connectivity between data points
labels – [out] Device vector of size n_samples to store cluster assignments (0 to n_clusters-1)
- void fit_predict(
- raft::resources const &handle,
- params config,
- raft::device_coo_matrix_view<double, int, int, int> connectivity_graph,
- raft::device_vector_view<int, int> labels
Perform spectral clustering on a connectivity graph.
#include <cuvs/cluster/spectral.hpp> #include <cuvs/preprocessing/spectral_embedding.hpp> raft::resources handle; // Create connectivity graph from data auto graph = raft::make_device_coo_matrix<double>(handle, n_samples, n_samples); cuvs::preprocessing::spectral_embedding::params embed_params; embed_params.n_neighbors = 15; cuvs::preprocessing::spectral_embedding::helpers::create_connectivity_graph( handle, embed_params, X_double.view(), graph); // Configure and run spectral clustering cuvs::cluster::spectral::params params; params.n_clusters = 5; params.n_components = 5; params.n_neighbors = 15; params.n_init = 10; auto labels = raft::make_device_vector<int>(handle, n_samples); cuvs::cluster::spectral::fit_predict(handle, params, graph.view(), labels.view());
- Parameters:
handle – [in] RAFT resource handle
config – [in] Spectral clustering parameters
connectivity_graph – [in] Sparse COO matrix representing connectivity between data points
labels – [out] Device vector of size n_samples to store cluster assignments (0 to n_clusters-1)