Why are tall arrays producing different results for Principal Component Analysis in underdetermined systems?

조회 수: 8 (최근 30일)
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];
>> pca(test)
ans =
0.5774
0.5774
0.5774
This is the output if my array is "tall":
>> gather(pca(tall(test)))
Evaluating tall expression using the Parallel Pool 'Processes':
- Pass 1 of 1: Completed in 0.32 sec
Evaluation completed in 0.53 sec
ans =
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?

채택된 답변

MathWorks Support Team
MathWorks Support Team 2023년 3월 17일
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:

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dimensionality Reduction and Feature Extraction에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by