PCA

View as Markdown

Source header: cuvs/preprocessing/pca.h

C API for PCA (Principal Component Analysis)

cuvsPcaSolver

Solver algorithm for PCA eigen decomposition.

1enum cuvsPcaSolver { ... };

Values

NameValue
CUVS_PCA_COV_EIG_DQ0
CUVS_PCA_COV_EIG_JACOBI1

cuvsPcaParams

Parameters for PCA decomposition.

1struct cuvsPcaParams { ... };

Fields

NameTypeDescription
n_componentsintNumber of principal components to keep.
copyboolIf false, data passed to fit are overwritten and running fit(X).transform(X) will not yield the expected results; use fit_transform(X) instead.
whitenboolWhen true the component 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.
algorithmenum cuvsPcaSolverSolver algorithm to use.
tolfloatTolerance for singular values (used by Jacobi solver).
n_iterationsintNumber of iterations for the power method (Jacobi solver).

cuvsPcaParamsCreate

Allocate PCA params and populate with default values.

1CUVS_EXPORT cuvsError_t cuvsPcaParamsCreate(cuvsPcaParams_t* params);

Parameters

NameDirectionTypeDescription
paramsoutcuvsPcaParams_t*cuvsPcaParams_t to allocate

Returns

CUVS_EXPORT cuvsError_t

cuvsPcaParamsDestroy

De-allocate PCA params.

1CUVS_EXPORT cuvsError_t cuvsPcaParamsDestroy(cuvsPcaParams_t params);

Parameters

NameDirectionTypeDescription
paramsincuvsPcaParams_tcuvsPcaParams_t to de-allocate

Returns

CUVS_EXPORT cuvsError_t

cuvsPcaFit

Perform PCA fit operation.

1CUVS_EXPORT cuvsError_t cuvsPcaFit(cuvsResources_t res,
2cuvsPcaParams_t params,
3DLManagedTensor* input,
4DLManagedTensor* components,
5DLManagedTensor* explained_var,
6DLManagedTensor* explained_var_ratio,
7DLManagedTensor* singular_vals,
8DLManagedTensor* mu,
9DLManagedTensor* noise_vars,
10bool flip_signs_based_on_U);

Computes the principal components, explained variances, singular values, and column means from the input data.

Parameters

NameDirectionTypeDescription
resincuvsResources_tcuvsResources_t opaque C handle
paramsincuvsPcaParams_tPCA parameters
inputinoutDLManagedTensor*input data [n_rows x n_cols] (col-major, float32, device)
componentsoutDLManagedTensor*principal components [n_components x n_cols] (col-major, float32, device)
explained_varoutDLManagedTensor*explained variances [n_components] (float32, device)
explained_var_ratiooutDLManagedTensor*explained variance ratios [n_components] (float32, device)
singular_valsoutDLManagedTensor*singular values [n_components] (float32, device)
muoutDLManagedTensor*column means [n_cols] (float32, device)
noise_varsoutDLManagedTensor*noise variance [1] (float32, device)
flip_signs_based_on_Uinboolwhether to determine signs by U (true) or V.T (false)

Returns

CUVS_EXPORT cuvsError_t

cuvsPcaFitTransform

Perform PCA fit and transform in a single operation.

1CUVS_EXPORT cuvsError_t cuvsPcaFitTransform(cuvsResources_t res,
2cuvsPcaParams_t params,
3DLManagedTensor* input,
4DLManagedTensor* trans_input,
5DLManagedTensor* components,
6DLManagedTensor* explained_var,
7DLManagedTensor* explained_var_ratio,
8DLManagedTensor* singular_vals,
9DLManagedTensor* mu,
10DLManagedTensor* noise_vars,
11bool flip_signs_based_on_U);

Computes the principal components and transforms the input data into the eigenspace.

Parameters

NameDirectionTypeDescription
resincuvsResources_tcuvsResources_t opaque C handle
paramsincuvsPcaParams_tPCA parameters
inputinoutDLManagedTensor*input data [n_rows x n_cols] (col-major, float32, device)
trans_inputoutDLManagedTensor*transformed data [n_rows x n_components] (col-major, float32, device)
componentsoutDLManagedTensor*principal components [n_components x n_cols] (col-major, float32, device)
explained_varoutDLManagedTensor*explained variances [n_components] (float32, device)
explained_var_ratiooutDLManagedTensor*explained variance ratios [n_components] (float32, device)
singular_valsoutDLManagedTensor*singular values [n_components] (float32, device)
muoutDLManagedTensor*column means [n_cols] (float32, device)
noise_varsoutDLManagedTensor*noise variance [1] (float32, device)
flip_signs_based_on_Uinboolwhether to determine signs by U (true) or V.T (false)

Returns

CUVS_EXPORT cuvsError_t

cuvsPcaTransform

Perform PCA transform operation.

1CUVS_EXPORT cuvsError_t cuvsPcaTransform(cuvsResources_t res,
2cuvsPcaParams_t params,
3DLManagedTensor* input,
4DLManagedTensor* components,
5DLManagedTensor* singular_vals,
6DLManagedTensor* mu,
7DLManagedTensor* trans_input);

Transforms the input data into the eigenspace using previously computed principal components.

Parameters

NameDirectionTypeDescription
resincuvsResources_tcuvsResources_t opaque C handle
paramsincuvsPcaParams_tPCA parameters
inputinoutDLManagedTensor*data to transform [n_rows x n_cols] (col-major, float32, device)
componentsinDLManagedTensor*principal components [n_components x n_cols] (col-major, float32, device)
singular_valsinDLManagedTensor*singular values [n_components] (float32, device)
muinDLManagedTensor*column means [n_cols] (float32, device)
trans_inputoutDLManagedTensor*transformed data [n_rows x n_components] (col-major, float32, device)

Returns

CUVS_EXPORT cuvsError_t

cuvsPcaInverseTransform

Perform PCA inverse transform operation.

1CUVS_EXPORT cuvsError_t cuvsPcaInverseTransform(cuvsResources_t res,
2cuvsPcaParams_t params,
3DLManagedTensor* trans_input,
4DLManagedTensor* components,
5DLManagedTensor* singular_vals,
6DLManagedTensor* mu,
7DLManagedTensor* output);

Transforms data from the eigenspace back to the original space.

Parameters

NameDirectionTypeDescription
resincuvsResources_tcuvsResources_t opaque C handle
paramsincuvsPcaParams_tPCA parameters
trans_inputinDLManagedTensor*transformed data [n_rows x n_components] (col-major, float32, device)
componentsinDLManagedTensor*principal components [n_components x n_cols] (col-major, float32, device)
singular_valsinDLManagedTensor*singular values [n_components] (float32, device)
muinDLManagedTensor*column means [n_cols] (float32, device)
outputoutDLManagedTensor*reconstructed data [n_rows x n_cols] (col-major, float32, device)

Returns

CUVS_EXPORT cuvsError_t