I have a sparse, real, symmetric matrix which I'm trying decompose into its e.v. The odd thing is: if I calculate the top 20 eigen-vectors using eigs, I get different results than if I calculate the top 50 and then pick out the top 20.
opts.v0 = rand(size(K,1),1);
opts.p = 100;
n_ev = 20;
[V,D] = eigs(K, n_ev,'lm',opts);
Display(V,79,95,size(V,1)/(79*95),20)
n_ev = 50;
[V,D] = eigs(K, n_ev,'lm',opts);
Display(V,79,95,size(V,1)/(79*95),20)
n_ev = 70;
[V,D] = eigs(K, n_ev,'lm',opts);
Display(V,79,95,size(V,1)/(79*95),20)
Can this be explained by the fact that eigen-vectors are not unique? Any other insights would be highly appreciated.
Thanks
According to John in a mathworks post
This is because eigs uses a random start
Since eigs
is a ARPACK library it could be time consuming to read through its documentation. However we can assume that 1) it does not try to solve the inverse matrix and 2) random number is involved so output has random error.
An experiment is done:
clear;clc;close all
K = randn(100);
N = 20;
DD = zeros(N,10);
for ii = 1:10
[V,D] = eigs(K, N,'lm');
DS = diag(D);
[~,DI] = sort(abs(DS),'descend');
DS = DS(DI);
DD(:,ii) = DS;
end
DN1 = abs(DD);
N = 50;
DD = zeros(N,10);
for ii = 1:10
[V,D] = eigs(K, N,'lm');
DS = diag(D);
[~,DI] = sort(abs(DS),'descend');
DS = DS(DI);
DD(:,ii) = DS;
end
DN2 = abs(DD);
DN2 = DN2(1:20,:);
N = 20;
DD = zeros(N,10);
for ii = 1:10
[V,D] = eigs(K, N,'lm');
DS = diag(D);
[~,DI] = sort(abs(DS),'descend');
DS = DS(DI);
DD(:,ii) = DS;
end
DN3 = abs(DD);
which follows your procedure: first top 20, then top 50, and then top 20. In each step, same procedure is repeated 10 times.
I have saved the top 20 of each step and did a quick comparison:
Err = (sum((DN1-DN2).^2+(DN2-DN3).^2+(DN1-DN3).^2,1)).^.5;
>> Err
Err =
Columns 1 through 6
0.0000 0.0000 0.0000 0.0870 0.0000 0.0000
Columns 7 through 10
0.0000 0.0000 0.0870 0.0870
>> min(Err),max(Err)
ans =
3.1665e-13
ans =
0.0870
>>
For most of the times the error is comparable to eps(1)
but a few error is big. This suggests that in order to generate a reliable result, repeated calculation and averaging may be required.
However if your question is merely they are out of order (I think I got your point now), you could sort
the vector with respect to the magnitudes after the evaluation. My experiment should be able to prove that after the sort
the top 20 are always the same.
Edit: As @TroyHaskin has pointed out in comments you have defined opts
(and I blatantly removed it) to define the random seeds. Let's add those lines and see what happens with the error:
Err =
Columns 1 through 6
0.0016 0.0016 0.0016 0.0016 0.0016 0.0016
Columns 7 through 10
0.0016 0.0016 0.0016 0.0016
Possible (guessed) explanation: as the number of interested e.v. increases the error grows since "some" tolerance is loosened to guarantee the speed performance.