Why Matlab function eigs has different results for the same input data?

27 visualizaciones (últimos 30 días)
Dear Matlab friends,
I use Matlab (2014b 64-bit) function eigs to find eigen values (some smallest ones) and vectors of sparse matrix, in LLE (locally linear embedding) algorithm. I find eigs has different results for the same input data. That means, for the same input data, current running results of eigs are different form the next running results of eigs. Another Matlab function eig has similar phenomenon. The last (also smallest) eigen value of the results of eigs is always zero. Why? How can I get the stable output? I'd like to hear from you!
Honggui
  3 comentarios
the cyclist
the cyclist el 19 de Dic. de 2015
Can you load an example of input data and code that exhibits the problem?
Honggui Li
Honggui Li el 20 de Dic. de 2015
Please see the wonderful answer from John D'Errico.

Iniciar sesión para comentar.

Respuesta aceptada

John D'Errico
John D'Errico el 19 de Dic. de 2015
Editada: John D'Errico el 19 de Dic. de 2015
This is because eigs uses a random start. So it need not generate exactly the same result every time it is called.
Worse, since eigenvectors are not unique(!), they may vary in the sign of those vectors generated. That is, you can multiply all elements of an eigenvector by -1 (actually, any constant will suffice) and still have an equally valid eigenvector for that eigenvalue.
That the last eigenvalue as returned by eigs is always zero merely means that your matrix is singular.
For example, if I generate a clearly singular matrix, then one eigenvalue (well, at least one eigenvalue) will be singular, or effectively so.
A = rand(4,3);A = A(:,[1 2 3 3]);
rank(A)
ans =
3
eigs(A)
ans =
-2.99458227515929e-17
0.0967955674503601
-0.547784486644781
1.98850968095585
So next, I have a non-singular matrix. No surprise that here no eigenvalues are zero.
A = rand(4);
rank(A)
ans =
4
eigs(A)
ans =
-0.126408754855564 + 0i
-0.133302928038295 + 0.236757870917361i
-0.133302928038295 - 0.236757870917361i
1.93779172327825 + 0i
Finally, if an eigenvalue is repeated, then there will be infinitely many choices of eigenvectors that span the subspace for that repeated eigenvalue.
As far as getting a stable answer, you can set the seed for the random generator that eigs will use to some fixed value. That will cause eigs to start from the same point every time, so the result will be stable (by some arbitrary definition of stability.) Alternatively, you can pass in an options structure to eigs, with a starting vector already supplied. Thus opts.v0 must be an Nx1 vector.
For example:
A = sprand(100,100,.01);
rank(full(A))
ans =
54
[V,D] = eigs(A);
[V1,D1] = eigs(A);
sum(V == V1)
ans =
0 0 0 0 0 0
Nothing was the same here. Now do this:
opts.v0 = rand(100,1);
[V,D] = eigs(A,5,'LM',opts);
[V1,D1] = eigs(A,5,'LM',opts);
sum(V == V1)
ans =
100 100 100 100 100
As you see, the two results are now identical.
So the things that you are seeing are not any surprise at all. Just mathematical fact, and nothing really beyond a basic linear algebra 101 class. Had you read the help for eigs, you would also have seen the fact that eigs uses a random start vector.
OPTS.v0: starting vector [N-by-1 vector | {randomly generated}]
  6 comentarios
Steven Lord
Steven Lord el 10 de Abr. de 2017
Can you send a MAT-file containing the matrix to Technical Support (using the Contact Us link at the top of this page) along with the syntax you use to call eigs so that we can investigate?
Dharshan
Dharshan el 10 de Nov. de 2022
Does this still apply? Or has matlab updated

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Linear Algebra en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by