spectral_embedding#

cuml.manifold.spectral_embedding(A, *, int n_components=8, affinity='nearest_neighbors', random_state=None, n_neighbors=None, norm_laplacian=True, drop_first=True)[source]#

Project the sample on the first eigenvectors of the graph Laplacian.

The adjacency matrix is used to compute a normalized graph Laplacian whose spectrum (especially the eigenvectors associated to the smallest eigenvalues) has an interpretation in terms of minimal number of cuts necessary to split the graph into comparably sized components.

Note : Laplacian Eigenmaps is the actual algorithm implemented here.

Parameters:
Aarray-like or sparse matrix of shape (n_samples, n_features) or (n_samples, n_samples)

If affinity is ‘nearest_neighbors’, this is the input data and a k-NN graph will be constructed. If affinity is ‘precomputed’, this is the affinity matrix. Supported formats for precomputed affinity: scipy sparse (CSR, CSC, COO), cupy sparse (CSR, CSC, COO), dense numpy arrays, or dense cupy arrays.

n_componentsint, default=8

The dimension of the projection subspace.

affinity{‘nearest_neighbors’, ‘precomputed’}, default=’nearest_neighbors’
How to construct the affinity matrix.
  • ‘nearest_neighbors’ : construct the affinity matrix by computing a graph of nearest neighbors.

  • ‘precomputed’ : interpret A as a precomputed affinity matrix.

random_stateint, RandomState instance or None, default=None

A pseudo random number generator used for the initialization. Use an int to make the results deterministic across calls.

n_neighborsint or None, default=None

Number of nearest neighbors for nearest_neighbors graph building. If None, n_neighbors will be set to max(n_samples/10, 1). Only used when A has shape (n_samples, n_features).

norm_laplacianbool, default=True

If True, then compute symmetric normalized Laplacian.

drop_firstbool, default=True

Whether to drop the first eigenvector. For spectral embedding, this should be True as the first eigenvector should be constant vector for connected graph, but for spectral clustering, this should be kept as False to retain the first eigenvector.

Returns:
embeddingcupy.ndarray of shape (n_samples, n_components)

The reduced samples.

Notes

Spectral Embedding (Laplacian Eigenmaps) is most useful when the graph has one connected component. If there graph has many components, the first few eigenvectors will simply uncover the connected components of the graph.

Examples

>>> import cupy as cp
>>> from cuml.manifold import spectral_embedding
>>> X = cp.random.rand(100, 20, dtype=cp.float32)
>>> embedding = spectral_embedding(X, n_components=2, random_state=42)
>>> embedding.shape
(100, 2)