2323
2424namespace cuvs ::preprocessing::spectral_embedding {
2525
26+ /* *
27+ * @defgroup spectral_embedding Spectral Embedding
28+ * @{
29+ */
30+
2631/* *
2732 * @brief Parameters for spectral embedding algorithm
33+ *
34+ * Spectral embedding is a dimensionality reduction technique that uses the
35+ * eigenvectors of the graph Laplacian to embed data points into a lower-dimensional
36+ * space. This technique is particularly useful for non-linear dimensionality
37+ * reduction and clustering tasks.
2838 */
2939struct params {
3040 /* * @brief The number of components to reduce the data to. */
@@ -33,24 +43,135 @@ struct params {
3343 /* * @brief The number of neighbors to use for the nearest neighbors graph. */
3444 int n_neighbors;
3545
36- /* * @brief Whether to normalize the Laplacian matrix. */
46+ /* *
47+ * @brief Whether to normalize the Laplacian matrix.
48+ *
49+ * If true, uses the normalized graph Laplacian (D^(-1/2) L D^(-1/2)).
50+ * If false, uses the unnormalized graph Laplacian (L = D - W).
51+ * Normalized Laplacian often leads to better results for clustering tasks.
52+ */
3753 bool norm_laplacian;
3854
39- /* * @brief Whether to drop the first eigenvector. */
55+ /* *
56+ * @brief Whether to drop the first eigenvector.
57+ *
58+ * The first eigenvector of the normalized Laplacian is constant and
59+ * uninformative. Setting this to true drops it from the embedding.
60+ * This is typically set to true when norm_laplacian is true.
61+ */
4062 bool drop_first;
4163
42- /* * @brief Random seed for reproducibility */
64+ /* *
65+ * @brief Random seed for reproducibility.
66+ *
67+ * Controls the random number generation for k-NN graph construction
68+ * and eigenvalue solver initialization. Use the same seed value to
69+ * ensure reproducible results across runs.
70+ */
4371 uint64_t seed;
4472};
4573
74+ /* *
75+ * @brief Perform spectral embedding on input dataset
76+ *
77+ * This function computes the spectral embedding of the input dataset by:
78+ * 1. Constructing a k-nearest neighbors graph from the input data
79+ * 2. Computing the graph Laplacian (normalized or unnormalized)
80+ * 3. Finding the eigenvectors corresponding to the smallest eigenvalues
81+ * 4. Using these eigenvectors as the embedding coordinates
82+ *
83+ * @code{.cpp}
84+ * #include <raft/core/resources.hpp>
85+ * #include <cuvs/preprocessing/spectral_embedding.hpp>
86+ *
87+ * raft::resources handle;
88+ *
89+ * // Set up parameters
90+ * cuvs::preprocessing::spectral_embedding::params params;
91+ * params.n_components = 2;
92+ * params.n_neighbors = 15;
93+ * params.norm_laplacian = true;
94+ * params.drop_first = true;
95+ * params.seed = 42;
96+ *
97+ * // Create input dataset (n_samples x n_features)
98+ * auto dataset = raft::make_device_matrix<float, int>(handle, n_samples, n_features);
99+ * // ... fill dataset ...
100+ *
101+ * // Create output embedding matrix (n_samples x n_components)
102+ * auto embedding = raft::make_device_matrix<float, int, raft::col_major>(
103+ * handle, n_samples, params.n_components);
104+ *
105+ * // Perform spectral embedding
106+ * cuvs::preprocessing::spectral_embedding::transform(
107+ * handle, params, dataset.view(), embedding.view());
108+ * @endcode
109+ *
110+ * @param[in] handle RAFT resource handle for managing CUDA resources
111+ * @param[in] config Parameters controlling the spectral embedding algorithm
112+ * @param[in] dataset Input dataset in row-major format [n_samples x n_features]
113+ * @param[out] embedding Output embedding in column-major format [n_samples x n_components]
114+ *
115+ */
46116void transform (raft::resources const & handle,
47117 params config,
48118 raft::device_matrix_view<float , int , raft::row_major> dataset,
49119 raft::device_matrix_view<float , int , raft::col_major> embedding);
50120
121+ /* *
122+ * @brief Perform spectral embedding using a precomputed connectivity graph
123+ *
124+ * This function computes the spectral embedding from a precomputed sparse
125+ * connectivity graph (e.g., from a k-NN search or custom similarity matrix).
126+ * This is useful when you want to use a custom graph construction method
127+ * or when you have a precomputed similarity/affinity matrix.
128+ *
129+ * The function:
130+ * 1. Converts the COO matrix to the graph Laplacian
131+ * 2. Computes eigenvectors of the Laplacian
132+ * 3. Returns the eigenvectors as the embedding
133+ *
134+ * @code{.cpp}
135+ * #include <raft/core/resources.hpp>
136+ * #include <cuvs/preprocessing/spectral_embedding.hpp>
137+ *
138+ * raft::resources handle;
139+ *
140+ * // Set up parameters
141+ * cuvs::preprocessing::spectral_embedding::params params;
142+ * params.n_components = 2;
143+ * params.norm_laplacian = true;
144+ * params.drop_first = true;
145+ * params.seed = 42;
146+ *
147+ * // Assume we have a precomputed connectivity graph as COO matrix
148+ * // connectivity_graph represents weighted edges between samples
149+ * raft::device_coo_matrix<float, int, int, int> connectivity_graph(...);
150+ *
151+ * // Create output embedding matrix (n_samples x n_components)
152+ * auto embedding = raft::make_device_matrix<float, int, raft::col_major>(
153+ * handle, n_samples, params.n_components);
154+ *
155+ * // Perform spectral embedding
156+ * cuvs::preprocessing::spectral_embedding::transform(
157+ * handle, params, connectivity_graph.view(), embedding.view());
158+ * @endcode
159+ *
160+ * @param[in] handle RAFT resource handle for managing CUDA resources
161+ * @param[in] config Parameters controlling the spectral embedding algorithm
162+ * (n_neighbors parameter is ignored when using precomputed graph)
163+ * @param[in] connectivity_graph Precomputed sparse connectivity/affinity graph in COO format
164+ * representing weighted connections between samples
165+ * @param[out] embedding Output embedding in column-major format [n_samples x n_components]
166+ *
167+ */
51168void transform (raft::resources const & handle,
52169 params config,
53170 raft::device_coo_matrix_view<float , int , int , int > connectivity_graph,
54171 raft::device_matrix_view<float , int , raft::col_major> embedding);
55172
173+ /* *
174+ * @}
175+ */
176+
56177} // namespace cuvs::preprocessing::spectral_embedding
0 commit comments