Question

I have a 8 x 8 matrix of floating point numbers and need to calculate eigenvector and eigenvalue from it. This is for feature reduction using PCA (Principal Component Analysis) and is one hell of a time consuming job if done by traditional methods. I tried to use power method as, Y = C*X where X is my 8 X 8 matrix.

                float[,] XMatrix = new float[8, 1];
                float[,] YMatrix = new float[8, 1];
                float max = 0;
                XMatrix[0, 0] = 1;



                for (int i = 0; i < 8; i++)
                {
                    for (int j = 0; j < 1; j++)
                    {

                        for (int k = 0; k < 8; k++)
                        {
                            YMatrix[i, j] += C[i, k] * XMatrix[k, j];
                            if (YMatrix[i, j] > max)
                                max = YMatrix[i, j];
                        }

                    }
                }

I know it is incorrect but cannot figure it out. I need help for using a power method or perhaps more effective way of calculating it.

Thanks in advance.

Was it helpful?

Solution

To retrieve the eigenvalues/eigenvectors in an efficent manner (i.e. fast!) for any size (dense) matrix, is not entirely trivial. I would suggest you use something like the QR algorithm (although this maybe overkill for a one-off calculation of a single 8x8 matrix).

The QR algorithm computes a Schur decomposition of a matrix. It is certainly one of the most important algorithm in eigenvalue computations. However, it is applied to dense matrices only (as stated above).

The QR algorithm consists of two separate stages. First, by means of a similarity transformation, the original matrix is transformed in a finite number of steps to Hessenberg form or – in the Hermitian/symmetric case – to real tridiagonal form. This first stage of the algorithm prepares its second stage, the actual QR iterations that are applied to the Hessenberg or tridiagonal matrix.

The overall complexity (number of floating points) of the algorithm is O(n3). For a good explanation of this algorithm see here. Or searches for eigenvalue algorithm in Google should provide you with many alternative ways of calculating your required eigenvalues/vectors.

Also, I have not looked into this in detail, but Math.NET a free library may help you here...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top