Visible to Intel only — GUID: GUID-F356EC66-0299-4E03-8629-81B5E57620C1
Visible to Intel only — GUID: GUID-F356EC66-0299-4E03-8629-81B5E57620C1
Principal Components Analysis (PCA)
Principal Component Analysis (PCA) is an algorithm for exploratory data analysis and dimensionality reduction. PCA transforms a set of feature vectors of possibly correlated features to a new set of uncorrelated features, called principal components. Principal components are the directions of the largest variance, that is, the directions where the data is mostly spread out.
Operation |
Computational methods |
Programming Interface |
|||
Mathematical formulation
Training
Given the training set of p-dimensional feature vectors and the number of principal components r, the problem is to compute r principal directions (p-dimensional eigenvectors [Lang87]) for the training set. The eigenvectors can be grouped into the matrix T that contains one eigenvector in each row.
Training method: Covariance
This method uses eigenvalue decomposition of the covariance matrix to compute the principal components of the datasets. The method relies on the following steps:
Computation of the covariance matrix
Computation of the eigenvectors and eigenvalues
Formation of the matrices storing the results
Covariance matrix computation is performed in the following way:
Compute the vector-column of sums .
Compute the cross-product .
Compute the covariance matrix .
To compute eigenvalues and eigenvectors , the implementer can choose an arbitrary method such as [Ping14].
The final step is to sort the set of pairs in the descending order by and form the resulting matrix . Additionally, the means and variances of the initial dataset are returned.
Training method: SVD
This method uses singular value decomposition of the dataset to compute its principal components. The method relies on the following steps:
Computation of the singular values and singular vectors
Formation of the matrices storing the results
To compute singular values and singular vectors and , the implementer can choose an arbitrary method such as [Demmel90].
The final step is to sort the set of pairs in the descending order by and form the resulting matrix . Additionally, the means and variances of the initial dataset are returned.
Sign-flip technique
Eigenvectors computed by some eigenvalue solvers are not uniquely defined due to sign ambiguity. To get the deterministic result, a sign-flip technique should be applied. One of the sign-flip techniques proposed in [Bro07] requires the following modification of matrix T:
where is i-th row, is the element in the i-th row and j-th column, is the signum function,
Inference
Given the inference set of p-dimensional feature vectors and the matrix T produced at the training stage, the problem is to transform to the set , where is an r-dimensional feature vector, .
The feature vector is computed through applying linear transformation [Lang87] defined by the matrix T to the feature vector ,
Inference methods: Covariance and SVD
Covariance and SVD inference methods compute according to (1).
Programming Interface
Distributed mode
The algorithm supports distributed execution in SMPD mode (only on GPU).
Usage example
Training
pca::model<> run_training(const table& data) { const auto pca_desc = pca::descriptor<float>{} .set_component_count(5) .set_deterministic(true); const auto result = train(pca_desc, data); print_table("means", result.get_means()); print_table("variances", result.get_variances()); print_table("eigenvalues", result.get_eigenvalues()); print_table("eigenvectors", result.get_eigenvectors()); return result.get_model(); }
Inference
table run_inference(const pca::model<>& model, const table& new_data) { const auto pca_desc = pca::descriptor<float>{} .set_component_count(model.get_component_count()); const auto result = infer(pca_desc, model, new_data); print_table("labels", result.get_transformed_data()); }
Examples
oneAPI DPC++
Batch Processing:
dpc_pca_cor_dense_batch.cpp
oneAPI C++
Batch Processing:
cpp_pca_dense_batch.cpp
Python* with DPC++ support
Batch Processing: