Source header: cuvs/preprocessing/pca.hpp
Parameters for PCA decomposition. Ref: http://scikit-learn.org/stable/modules/generated/sklearn.decomposition.PCA.html
| 1 | struct params { |
| 2 | int n_components; |
| 3 | bool copy; |
| 4 | bool whiten; |
| 5 | solver algorithm; |
| 6 | float tol; |
| 7 | int n_iterations; |
| 8 | }; |
Fields
| n_components | int | Number of components to keep. |
| copy | bool | If false, data passed to fit are overwritten and running fit(X).transform(X) will not yield the expected results, use fit_transform(X) instead. |
| whiten | bool | When true (false by default) the components vectors are multiplied by the square root of n_samples and then divided by the singular values to ensure uncorrelated outputs with unit component-wise variances. |
| algorithm | solver | The solver algorithm to use. |
| tol | float | Tolerance for singular values computed by svd_solver == ‘arpack’ or the Jacobi solver. |
| n_iterations | int | Number of iterations for the power method computed by the Jacobi solver. |
Perform PCA fit operation.
| 1 | void fit(raft::resources const& handle, |
| 2 | const params& config, |
| 3 | raft::device_matrix_view<float, int64_t, raft::col_major> input, |
| 4 | raft::device_matrix_view<float, int64_t, raft::col_major> components, |
| 5 | raft::device_vector_view<float, int64_t> explained_var, |
| 6 | raft::device_vector_view<float, int64_t> explained_var_ratio, |
| 7 | raft::device_vector_view<float, int64_t> singular_vals, |
| 8 | raft::device_vector_view<float, int64_t> mu, |
| 9 | raft::device_scalar_view<float, int64_t> noise_vars, |
| 10 | bool flip_signs_based_on_U = false); |
Computes the principal components, explained variances, singular values, and column means from the input data.
Parameters
| handle | in | raft::resources const& | raft resource handle |
| config | in | const params& | PCA parameters |
| input | inout | raft::device_matrix_view<float, int64_t, raft::col_major> | input data [n_rows x n_cols] (col-major). Modified temporarily. |
| components | out | raft::device_matrix_view<float, int64_t, raft::col_major> | principal components [n_components x n_cols] (col-major) |
| explained_var | out | raft::device_vector_view<float, int64_t> | explained variances [n_components] |
| explained_var_ratio | out | raft::device_vector_view<float, int64_t> | explained variance ratios [n_components] |
| singular_vals | out | raft::device_vector_view<float, int64_t> | singular values [n_components] |
| mu | out | raft::device_vector_view<float, int64_t> | column means [n_cols] |
| noise_vars | out | raft::device_scalar_view<float, int64_t> | noise variance (scalar) |
| flip_signs_based_on_U | in | bool | whether to determine signs by U (true) or V.T (false) Default: false. |
Returns
void
Perform PCA fit and transform operations.
| 1 | void fit_transform(raft::resources const& handle, |
| 2 | const params& config, |
| 3 | raft::device_matrix_view<float, int64_t, raft::col_major> input, |
| 4 | raft::device_matrix_view<float, int64_t, raft::col_major> trans_input, |
| 5 | raft::device_matrix_view<float, int64_t, raft::col_major> components, |
| 6 | raft::device_vector_view<float, int64_t> explained_var, |
| 7 | raft::device_vector_view<float, int64_t> explained_var_ratio, |
| 8 | raft::device_vector_view<float, int64_t> singular_vals, |
| 9 | raft::device_vector_view<float, int64_t> mu, |
| 10 | raft::device_scalar_view<float, int64_t> noise_vars, |
| 11 | bool flip_signs_based_on_U = false); |
Computes the principal components and transforms the input data into the eigenspace in a single operation.
Parameters
| handle | in | raft::resources const& | raft resource handle |
| config | in | const params& | PCA parameters |
| input | inout | raft::device_matrix_view<float, int64_t, raft::col_major> | input data [n_rows x n_cols] (col-major). Modified temporarily. |
| trans_input | out | raft::device_matrix_view<float, int64_t, raft::col_major> | transformed data [n_rows x n_components] (col-major) |
| components | out | raft::device_matrix_view<float, int64_t, raft::col_major> | principal components [n_components x n_cols] (col-major) |
| explained_var | out | raft::device_vector_view<float, int64_t> | explained variances [n_components] |
| explained_var_ratio | out | raft::device_vector_view<float, int64_t> | explained variance ratios [n_components] |
| singular_vals | out | raft::device_vector_view<float, int64_t> | singular values [n_components] |
| mu | out | raft::device_vector_view<float, int64_t> | column means [n_cols] |
| noise_vars | out | raft::device_scalar_view<float, int64_t> | noise variance (scalar) |
| flip_signs_based_on_U | in | bool | whether to determine signs by U (true) or V.T (false) Default: false. |
Returns
void
Perform PCA transform operation.
| 1 | void transform(raft::resources const& handle, |
| 2 | const params& config, |
| 3 | raft::device_matrix_view<float, int64_t, raft::col_major> input, |
| 4 | raft::device_matrix_view<float, int64_t, raft::col_major> components, |
| 5 | raft::device_vector_view<float, int64_t> singular_vals, |
| 6 | raft::device_vector_view<float, int64_t> mu, |
| 7 | raft::device_matrix_view<float, int64_t, raft::col_major> trans_input); |
Transforms the input data into the eigenspace using previously computed principal components.
Parameters
| handle | in | raft::resources const& | raft resource handle |
| config | in | const params& | PCA parameters |
| input | inout | raft::device_matrix_view<float, int64_t, raft::col_major> | data to transform [n_rows x n_cols] (col-major). Modified temporarily (mean-centered then restored). |
| components | in | raft::device_matrix_view<float, int64_t, raft::col_major> | principal components [n_components x n_cols] (col-major) |
| singular_vals | in | raft::device_vector_view<float, int64_t> | singular values [n_components] |
| mu | in | raft::device_vector_view<float, int64_t> | column means [n_cols] |
| trans_input | out | raft::device_matrix_view<float, int64_t, raft::col_major> | transformed data [n_rows x n_components] (col-major) |
Returns
void
Perform PCA inverse transform operation.
| 1 | void inverse_transform(raft::resources const& handle, |
| 2 | const params& config, |
| 3 | raft::device_matrix_view<float, int64_t, raft::col_major> trans_input, |
| 4 | raft::device_matrix_view<float, int64_t, raft::col_major> components, |
| 5 | raft::device_vector_view<float, int64_t> singular_vals, |
| 6 | raft::device_vector_view<float, int64_t> mu, |
| 7 | raft::device_matrix_view<float, int64_t, raft::col_major> output); |
Transforms data from the eigenspace back to the original space.
Parameters
| handle | in | raft::resources const& | raft resource handle |
| config | in | const params& | PCA parameters |
| trans_input | in | raft::device_matrix_view<float, int64_t, raft::col_major> | transformed data [n_rows x n_components] (col-major) |
| components | in | raft::device_matrix_view<float, int64_t, raft::col_major> | principal components [n_components x n_cols] (col-major) |
| singular_vals | in | raft::device_vector_view<float, int64_t> | singular values [n_components] |
| mu | in | raft::device_vector_view<float, int64_t> | column means [n_cols] |
| output | out | raft::device_matrix_view<float, int64_t, raft::col_major> | reconstructed data [n_rows x n_cols] (col-major) |
Returns
void
Copyright © 2026, NVIDIA Corporation.