Why are tall arrays producing different results for Principal Component Analysis in underdetermined systems?
3 views (last 30 days)
Show older comments
Answered: MathWorks Support Team on 17 Mar 2023
I am using MATLAB R2022b and I am getting different results using the "pca" function on my data depending on whether or not I am casting my data to a tall array first.
This is the output if my array is not "tall":
>> test = [1 2 3; 2 3 4];
This is the output if my array is "tall":
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 0.32 sec
Evaluation completed in 0.53 sec
0.5774 0 0.8165
0.5774 -0.7071 -0.4082
0.5774 0.7071 -0.4082
The results, shown by 'ans', are different. What is causing this?
For tall arrays, "pca" cannot compute the principal components directly. Instead, it first creates the full covariance matrix, and then uses "pcacov" on the covariance matrix.
For overdetermined systems (i.e. "n x m" matrices where "n>=m", representing n observations of m variables) the two methods produce the same result.
For underdetermined systems, on the other hand, where m>n, the covariance matrix and therefore the result of "pcacov" is an m x m matrix. However, the result of "pca" for ordinary (i.e. not tall) "n x m" arrays is an "m x n - 1" matrix.
To reproduce the behaviour of the tall arrays on an ordinary array, you can use "pcacov(cov(test))" instead of "pca(test)".
To reproduce the behaviour of the ordinary arrays in the tall arrays, you can use the following code:
>> pcaTall = gather(pca(tall(test)));
>> pcaNotTall = pcaTall(1:size(test, 1), 1:size(test, 2));
For more information on "pcacov" and "cov", please find the following documentation pages:
More Answers (0)
Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!