0
votes

I'm trying to figure out Eigenvalues/Eigenvectors for large datasets in order to compute the PCA. I can calculate the Eigenvalues and Eigenvectors for 2x2, 3x3 etc..

The problem is, I have a dataset containing 451x128 I compute the covariance matrix which gives me 128x128 values from this. This, therefore looks like the following:

A = [ [1, 2, 3, 
       2, 3, 1, 
       ..........,
       = 128]
       [5, 4, 1,
        3, 2, 1,
        2, 1, 2,
        ..........
        = 128]
      ......., 
      128]

Computing the Eigenvalues and vectors for a 128x128 vector seems really difficult and would take a lot of computing power. However, if I allow for each of the blocks in A to be a 2-dimensional (3xN) I can then compute the covariance matrix which will give me a 3x3 matrix.

My question is this: Would this be a good or reasonable assumption for solving the eigenvalues and vectors? Something like this:

A is a 2-dimensional vector containing 128x451, foreach of the blocks compute the eigenvalues and eigenvectors of the covariance vector, like so:

Eig1 = eig(cov(A[0])) Eig2 = eig(cov(A[1]))

This would then give me 128 Eigenvalues (for each of the blocks inside the 128x128 vector)..

If this is not correct, how does MATLAB handle such large dimensional data?

3
What do you mean by "If this is not correct"? And MATLAB can find eigenvectors and eigenvalues of large square matrices in a fraction of a second..Adarsh Chavakula
@AdarshChavakula Hey, I'm trying to create an algorithm (in C++) that can calculate the eigenvalues and eigenvectors without the use of third party software.. I can, calculate a 2x2, 3x3 but I'm getting confused on how to calculate it for large square matrices. I don't get quite how matlab does it - Does this make sense?Phorce

3 Answers

0
votes

Have you tried svd()

Do the singular value decomposition

[U,S,V] = svd(X)

U and V are orthogonal matrices and S contains the eigen values. Sort U and V in descending order based on S.

0
votes

As kkuilla mentions, you can use the SVD of the original matrix, as the SVD of a matrix is related to the Eigenvalues and Eigenvectors of the covariance matrix as I demonstrate in the following example:

A = [1 2 3; 6 5 4]; % A rectangular matrix
X = A*A';              % The covariance matrix of A

[V, D] = eig(X);       % Get the eigenvectors and eigenvalues of the covariance matrix
[U,S,W] = svd(A);      % Get the singular values of the original matrix

V is a matrix containing the eigenvectors, and D contains the eigenvalues. Now, the relationship:

SST ~ D

U ~ V

As to your own assumption, I may be misreading it, but I think it is false. I can't see why the Eigenvalues of the blocks would relate to the Eigenvalues of the matrix as a whole; they wouldn't correspond to the same Eigenvectors, as the dimensionality of the Eigenvectors wouldn't match. I think your covariances would be different too, but then I'm not completely clear on how you are creating these blocks.

As to how Matlab does it, it does use some tricks. Perhaps the link below might be informative (though it might be a little old). I believe they use (or used) LAPACK and a QZ factorisation to obtain intermediate values.

https://au.mathworks.com/company/newsletters/articles/matlab-incorporates-lapack.html

-3
votes

Use the word

[Eigenvectors, Eigenvalues] = eig(Matrix)