[SciPy-User] Incorrect eigenvectors/values from scipy.sparse.linalg.lobpcg

Charanpal Dhanjal dhanjal@telecom-paristech...
Wed Nov 9 12:55:10 CST 2011


Hi all,

I wanted to use scipy.sparse.linalg.lobpcg and found that it does not 
seem to work as described. Here is some code demonstrating the problem:

============================================
import numpy
import scipy.sparse.linalg

numpy.random.seed(21)

n = 20
A = numpy.random.rand(n, n)
A = A.T.dot(A)
s1, U1 = numpy.linalg.eig(A)
print(s1)

k = 5
X = numpy.random.rand(A.shape[0], k)
w, V = scipy.sparse.linalg.lobpcg(A, X, tol=1e-30, largest=True, 
maxiter=100)

print(w)
print(numpy.sum(V**2, 0))
print(numpy.linalg.norm(A.dot(V) - V.dot(numpy.diag(w))))
============================================

and the output on my machine is:

[ 106.1436    4.8357    4.6157    3.6735    2.9786    2.7774    2.4734  
  1.8922    1.8146    1.5884
     1.0942    0.985     0.7575    0.6286    0.4411    0.2275    0.0039  
  0.0501    0.0364    0.136 ]
[ 0.2275+0.j  0.0039+0.j  0.0501+0.j  0.0364+0.j  0.1360+0.j]
[  2.7735   4.7396   3.8368   4.5054  14.7127]
406.94471445

So, it looks like lobpcg is finding the smallest eigenvalues even 
though largest=True. When I change largest=False, then lobpcg returns 
the 2nd to 5th largest eigenvectors, i.e. it excludes the very largest 
for some reason. Furthermore, the norms of the eigenvectors are not 1 
and the last print statement shows the eigenvectors are just not 
correct. Any ideas about this? I tried playing around with tol and 
maxiter parameters to no avail.

I read that some bugs in this function had been fixed in version 0.9 
(the version I am using). Also, I am using python 2.7.2 and numpy 1.6.1 
on Ubuntu 11.10, if that helps.

Thanks in advance for any help,
Charanpal


More information about the SciPy-User mailing list