An eigen decomposition problem in programming

Click For Summary
SUMMARY

The discussion focuses on the eigen decomposition of a covariance matrix using various methods, including LaEigSolve from the lapack++ library, svdcmp from Numerical Recipes, MATLAB's eig(), and R's pcacov(). The results from these methods differ, with pcacov() yielding results that the user believes to be the most accurate. The user is developing a Principal Component Analysis (PCA) program in C++ and seeks clarification on the reliability of these methods and the discrepancies in their outputs.

PREREQUISITES
  • Understanding of covariance matrices and their properties
  • Familiarity with eigen decomposition techniques
  • Experience with C++ programming for implementing PCA
  • Knowledge of numerical libraries such as LAPACK and Numerical Recipes
NEXT STEPS
  • Research the implementation details of LAPACK's LaEigSolve for eigen decomposition
  • Explore the svdcmp routine in Numerical Recipes for its application in PCA
  • Learn about MATLAB's eig() function and its underlying algorithms
  • Investigate the workings of R's pcacov() function and its accuracy in PCA
USEFUL FOR

Data scientists, statisticians, and software developers working on Principal Component Analysis, particularly those implementing PCA in C++ or comparing different numerical methods for eigen decomposition.

Asuralm
Messages
35
Reaction score
0
Hi all:

I have a covariance matrix which is like:

0.00166713 -0.00060678 4.60534e-05
-0.00060678 0.00178576 -0.000244526
4.60534e-05 -0.000244526 0.000772057

And then I want to eigen decompose the matrix to obtain the eigenvector matrix. I tried several methods, one is to use the LaEigSolve in the lapack++ library. This gives me the result:

0.655504 -0.742432 0.138237
-0.743371 -0.60208 0.291375
0.133097 0.293759 0.946568

Then I tried to use svdcmp routine of the Numerical recipe which gives me:

-0.655504 0.742432 0.138237
0.743371 0.60208 0.291375
-0.133097 -0.293759 0.946568

I also tried to use eig() in MATLAB which gives me:

-0.6555 0.7424 0.1383
0.7434 0.6021 0.2914
-0.1331 -0.2938 0.9465

By using pcacov(), the result is:

-0.6555 -0.7424 0.1383
0.7434 -0.6021 0.2914
-0.1331 0.2938 0.9465

Actually, I am writing a program of Pinciple Component Analysis in C++. But I don't really know which one is reliable and correct. The pcacov() seems to give me the correct result but I really don't understand why it's different from the others.

Can anyone help me with it please?

Thanks
 
Physics news on Phys.org
reconstruct the original matrix let say Ahat by using your decomposed matrices, and compute the norm of |A-Ahat|. Then decide for yourself. Do this in a for loop for a couple of hundred matrices of course...
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K