## Developer Guide and Reference

• 2021.3
• 06/28/2021
• Public Content
Contents

# 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:
1. Computation of the covariance matrix
2. Computation of the eigenvectors and eigenvalues
3. Formation of the matrices storing the results
Covariance matrix computation is performed in the following way:
1. Compute the vector-column of sums .
2. Compute the cross-product .
3. 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:
1. Computation of the singular values and singular vectors
2. 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).

## 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:
oneAPI C++
Batch Processing:
Python* with DPC++ support
Batch Processing:

#### Product and Performance Information

1

Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex.
{"ft_lang_label":"__label__en","ft_lang_prob":0.70706075,"math_prob":0.9383708,"size":3826,"snap":"2021-31-2021-39","text_gpt3_token_len":840,"char_repetition_ratio":0.13683935,"word_repetition_ratio":0.19622642,"special_character_ratio":0.20151594,"punctuation_ratio":0.13301282,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99600387,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62],"im_url_duplicate_count":[null,3,null,2,null,1,null,1,null,1,null,2,null,1,null,1,null,3,null,1,null,2,null,1,null,1,null,1,null,3,null,1,null,1,null,2,null,1,null,1,null,1,null,3,null,2,null,2,null,1,null,1,null,2,null,2,null,1,null,1,null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-09-28T07:58:23Z\",\"WARC-Record-ID\":\"<urn:uuid:6cdc323a-6bd8-4796-a20e-ce08bdd442be>\",\"Content-Length\":\"366415\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:107919fb-fe66-47fc-9cd3-91b4b826ce8c>\",\"WARC-Concurrent-To\":\"<urn:uuid:b4c4ad8b-4336-4b30-9cdb-080f507cf5c0>\",\"WARC-IP-Address\":\"104.121.101.238\",\"WARC-Target-URI\":\"https://software.intel.com/content/www/us/en/develop/documentation/onedal-developer-guide-and-reference/top/oneapi-interfaces/algorithms-2/decomposition-1/principal-components-analysis-pca-1.html\",\"WARC-Payload-Digest\":\"sha1:K6PESTRS7BMXL6Y5TJOJ7XAQV4KFCHNN\",\"WARC-Block-Digest\":\"sha1:QNV6EU7SKE53KOP3NA4C6YTMFJDXBMMH\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-39/CC-MAIN-2021-39_segments_1631780060538.11_warc_CC-MAIN-20210928062408-20210928092408-00151.warc.gz\"}"}