Pergunta

Im working in Matlab to compute the PCA. I already compute the Eigen Value and the Eigen Vector.

I used this matlab function :

     [Eigen Vector, Eigen Value]=eigs(Matrix,k);

With this eigs function, we will get ordered Eigen Value (from big to small).

In this case, Im going to determine the k (which is the number of Eigen Value I want to keep).

And I need to compute k with this formula :

   Σ(from 1 to p) of eigen value
   ------------------------------------------------------- * 100 = our persentage
   Σ(from 1 to col of eigen value matrix) of eigen value

where k=p

And to reduce the dimension of input matrix, I just have to :

     (Eigen Vector*Eigen Value*Eigen Vector')

Someone know if there is matlab function to get the k number based on the persentage we want ??

Foi útil?

Solução

You can use cumsum.

You probably want to take the absolute value of the eigenvalues before summming:

P = 90; %// desired percentage
eigenValues = eigs(Matrix);
summation = cumsum(abs(eigenValues));
summation = summation/summation(end)*100; %// normalize to get percentage
k = find(summation>=P,1); %// first index for whith P is exceeded
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top