Hi, I'm having this weird problem when computing eigenvalues/vectors with Numpy. I have the following symmetric matrix, B: -0.3462 0.6538 0.5385 -0.4615 0.6538 -0.3462 -0.3462 -0.3462 0.6538 -0.3462 0.5385 -0.4615 0.6538 -0.3462 -0.3462 -0.3462 0.5385 0.5385 -0.6154 0.3846 0.5385 -0.4615 -0.4615 -0.4615 -0.4615 -0.4615 0.3846 -0.6154 -0.4615 0.5385 0.5385 0.5385 0.6538 0.6538 0.5385 -0.4615 -0.3462 -0.3462 -0.3462 -0.3462 -0.3462 -0.3462 -0.4615 0.5385 -0.3462 -0.3462 0.6538 0.6538 -0.3462 -0.3462 -0.4615 0.5385 -0.3462 0.6538 -0.3462 0.6538 -0.3462 -0.3462 -0.4615 0.5385 -0.3462 0.6538 0.6538 -0.3462 I compute the eigenvalues and eigenvectors of B using numpy.linalg.eig(B). I get the following eigenvalues: [ 2.79128785e+00 -1.79128785e+00 1.64060486e-16 -3.07692308e-01 -1.00000000e+00 -1.00000000e+00 -1.00000000e+00 -1.00000000e+00] I do the same thing in Matlab and get the SAME eigenvalues. However, my eigenVECTORS in Matlab versus numpy are different. It makes no sense to me. In general, the following relationship should hold: Bx = Lx, where B is my matrix, x is an eigenvector, and L is the corresponding eigenvalue. For the eigenvectors that Matlab returns, I have confirmed that the relationship does hold. But for the Numpy eigenvectors, it doesn't! Any idea why this might be happening? I did some computations myself and it looks like the Matlab output is correct. Just seems like the eigenvectors that Numpy is returning are wrong... Thanks for any suggestions. Saket
On Sun, Jun 29, 2008 at 6:47 PM, Saket
Hi,
I'm having this weird problem when computing eigenvalues/vectors with Numpy. I have the following symmetric matrix, B:
-0.3462 0.6538 0.5385 -0.4615 0.6538 -0.3462 -0.3462 -0.3462 0.6538 -0.3462 0.5385 -0.4615 0.6538 -0.3462 -0.3462 -0.3462 0.5385 0.5385 -0.6154 0.3846 0.5385 -0.4615 -0.4615 -0.4615 -0.4615 -0.4615 0.3846 -0.6154 -0.4615 0.5385 0.5385 0.5385 0.6538 0.6538 0.5385 -0.4615 -0.3462 -0.3462 -0.3462 -0.3462 -0.3462 -0.3462 -0.4615 0.5385 -0.3462 -0.3462 0.6538 0.6538 -0.3462 -0.3462 -0.4615 0.5385 -0.3462 0.6538 -0.3462 0.6538 -0.3462 -0.3462 -0.4615 0.5385 -0.3462 0.6538 0.6538 -0.3462
I compute the eigenvalues and eigenvectors of B using numpy.linalg.eig(B). I get the following eigenvalues:
[ 2.79128785e+00 -1.79128785e+00 1.64060486e-16 -3.07692308e-01 -1.00000000e+00 -1.00000000e+00 -1.00000000e+00 -1.00000000e+00]
I do the same thing in Matlab and get the SAME eigenvalues. However, my eigenVECTORS in Matlab versus numpy are different. It makes no sense to me. In general, the following relationship should hold: Bx = Lx, where B is my matrix, x is an eigenvector, and L is the corresponding eigenvalue. For the eigenvectors that Matlab returns, I have confirmed that the relationship does hold. But for the Numpy eigenvectors, it doesn't!
Any idea why this might be happening? I did some computations myself and it looks like the Matlab output is correct. Just seems like the eigenvectors that Numpy is returning are wrong...
Thanks for any suggestions.
Works for me: In [16]: d,v = linalg.eig(A) In [17]: abs(dot(A,v) - dot(v,diag(d))).max() Out[17]: 1.1102230246251565e-15 Perhaps you are not applying the results correctly. You should also use eigh for symmetric matrices. Note that Matlab, IIRC, returns the eigenvalues as a diagonal matrix when you ask for the eigenvectors, while numpy returns a 1D array that needs to be made into a diagonal array or simply multiplied pointwise from the right, i.e., In [21]: abs(dot(A,v) - v*d).max() Out[21]: 1.1102230246251565e-15 This is with arrays, matrices will be slightly different. If your problem persists, please attach your configuration info. In [28]: numpy.__config__.show() atlas_threads_info: libraries = ['lapack', 'ptf77blas', 'ptcblas', 'atlas'] library_dirs = ['/usr/local/atlas/lib'] language = f77 include_dirs = ['/usr/local/atlas/include'] blas_opt_info: libraries = ['ptf77blas', 'ptcblas', 'atlas'] library_dirs = ['/usr/local/atlas/lib'] define_macros = [('ATLAS_INFO', '"\\"3.7.35\\""')] language = c include_dirs = ['/usr/local/atlas/include'] atlas_blas_threads_info: libraries = ['ptf77blas', 'ptcblas', 'atlas'] library_dirs = ['/usr/local/atlas/lib'] language = c include_dirs = ['/usr/local/atlas/include'] lapack_opt_info: libraries = ['lapack', 'ptf77blas', 'ptcblas', 'atlas'] library_dirs = ['/usr/local/atlas/lib'] define_macros = [('ATLAS_INFO', '"\\"3.7.35\\""')] language = f77 include_dirs = ['/usr/local/atlas/include'] lapack_mkl_info: NOT AVAILABLE blas_mkl_info: NOT AVAILABLE mkl_info: NOT AVAILABLE Chuck
On Sun, Jun 29, 2008 at 6:47 PM, Saket
Hi,
I'm having this weird problem when computing eigenvalues/vectors with Numpy. I have the following symmetric matrix, B:
-0.3462 0.6538 0.5385 -0.4615 0.6538 -0.3462 -0.3462 -0.3462 0.6538 -0.3462 0.5385 -0.4615 0.6538 -0.3462 -0.3462 -0.3462 0.5385 0.5385 -0.6154 0.3846 0.5385 -0.4615 -0.4615 -0.4615 -0.4615 -0.4615 0.3846 -0.6154 -0.4615 0.5385 0.5385 0.5385 0.6538 0.6538 0.5385 -0.4615 -0.3462 -0.3462 -0.3462 -0.3462 -0.3462 -0.3462 -0.4615 0.5385 -0.3462 -0.3462 0.6538 0.6538 -0.3462 -0.3462 -0.4615 0.5385 -0.3462 0.6538 -0.3462 0.6538 -0.3462 -0.3462 -0.4615 0.5385 -0.3462 0.6538 0.6538 -0.3462
I compute the eigenvalues and eigenvectors of B using numpy.linalg.eig(B). I get the following eigenvalues:
[ 2.79128785e+00 -1.79128785e+00 1.64060486e-16 -3.07692308e-01 -1.00000000e+00 -1.00000000e+00 -1.00000000e+00 -1.00000000e+00]
I do the same thing in Matlab and get the SAME eigenvalues. However, my eigenVECTORS in Matlab versus numpy are different. It makes no sense to me. In general, the following relationship should hold: Bx = Lx, where B is my matrix, x is an eigenvector, and L is the corresponding eigenvalue. For the eigenvectors that Matlab returns, I have confirmed that the relationship does hold. But for the Numpy eigenvectors, it doesn't!
Any idea why this might be happening? I did some computations myself and it looks like the Matlab output is correct. Just seems like the eigenvectors that Numpy is returning are wrong...
Thanks for any suggestions.
Also note that the -1 eigenvalue has multiplicity 4. This means that any set of orthogonal vectors spanning the same eigenspace will do for eigenvectors, i.e., they aren't unique and roundoff error is likely to have a large effect on what you end up with. Chuck
Hmm... so the relationship Ax = Lx should hold for every eigenvalue
and corresponding eigenvector of A, right? But, consider the first
eigenvalue,eigenvector pair:
for i,eval in enumerate(d):
print abs(numpy.dot(A,v[i]) - numpy.dot(eval,v[i])).max()
return
Outputs: 1.928
I thought maybe the ith eigenvector corresponds to a different (not
the ith) eigenvalue, but there doesn't seem to be any eigenvalue which
corresponds to the ith eigenvector such that the relationship holds...
Thanks again.
Saket
atlas_threads_info:
NOT AVAILABLE
blas_opt_info:
libraries = ['f77blas', 'cblas', 'atlas']
library_dirs = ['C:\\local\\lib\\yop\\sse2']
define_macros = [('ATLAS_INFO', '"\\"?.?.?\\""')]
language = c
atlas_blas_threads_info:
NOT AVAILABLE
lapack_opt_info:
libraries = ['lapack', 'f77blas', 'cblas', 'atlas']
library_dirs = ['C:\\local\\lib\\yop\\sse2']
define_macros = [('ATLAS_INFO', '"\\"?.?.?\\""')]
language = f77
atlas_info:
libraries = ['lapack', 'f77blas', 'cblas', 'atlas']
library_dirs = ['C:\\local\\lib\\yop\\sse2']
language = f77
lapack_mkl_info:
NOT AVAILABLE
blas_mkl_info:
NOT AVAILABLE
atlas_blas_info:
libraries = ['f77blas', 'cblas', 'atlas']
library_dirs = ['C:\\local\\lib\\yop\\sse2']
language = c
mkl_info:
NOT AVAILABLE
On Sun, Jun 29, 2008 at 9:15 PM, Charles R Harris
On Sun, Jun 29, 2008 at 6:47 PM, Saket
wrote: Hi,
I'm having this weird problem when computing eigenvalues/vectors with Numpy. I have the following symmetric matrix, B:
-0.3462 0.6538 0.5385 -0.4615 0.6538 -0.3462 -0.3462 -0.3462 0.6538 -0.3462 0.5385 -0.4615 0.6538 -0.3462 -0.3462 -0.3462 0.5385 0.5385 -0.6154 0.3846 0.5385 -0.4615 -0.4615 -0.4615 -0.4615 -0.4615 0.3846 -0.6154 -0.4615 0.5385 0.5385 0.5385 0.6538 0.6538 0.5385 -0.4615 -0.3462 -0.3462 -0.3462 -0.3462 -0.3462 -0.3462 -0.4615 0.5385 -0.3462 -0.3462 0.6538 0.6538 -0.3462 -0.3462 -0.4615 0.5385 -0.3462 0.6538 -0.3462 0.6538 -0.3462 -0.3462 -0.4615 0.5385 -0.3462 0.6538 0.6538 -0.3462
I compute the eigenvalues and eigenvectors of B using numpy.linalg.eig(B). I get the following eigenvalues:
[ 2.79128785e+00 -1.79128785e+00 1.64060486e-16 -3.07692308e-01 -1.00000000e+00 -1.00000000e+00 -1.00000000e+00 -1.00000000e+00]
I do the same thing in Matlab and get the SAME eigenvalues. However, my eigenVECTORS in Matlab versus numpy are different. It makes no sense to me. In general, the following relationship should hold: Bx = Lx, where B is my matrix, x is an eigenvector, and L is the corresponding eigenvalue. For the eigenvectors that Matlab returns, I have confirmed that the relationship does hold. But for the Numpy eigenvectors, it doesn't!
Any idea why this might be happening? I did some computations myself and it looks like the Matlab output is correct. Just seems like the eigenvectors that Numpy is returning are wrong...
Thanks for any suggestions.
Also note that the -1 eigenvalue has multiplicity 4. This means that any set of orthogonal vectors spanning the same eigenspace will do for eigenvectors, i.e., they aren't unique and roundoff error is likely to have a large effect on what you end up with.
Chuck
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Also, I'm getting different numbers when I do the above using eig(A)
and eigh(A). I thought eigh would be faster, but would still give the
same results...
On Sun, Jun 29, 2008 at 10:00 PM, Saket
Hmm... so the relationship Ax = Lx should hold for every eigenvalue and corresponding eigenvector of A, right? But, consider the first eigenvalue,eigenvector pair:
for i,eval in enumerate(d): print abs(numpy.dot(A,v[i]) - numpy.dot(eval,v[i])).max() return
Outputs: 1.928
I thought maybe the ith eigenvector corresponds to a different (not the ith) eigenvalue, but there doesn't seem to be any eigenvalue which corresponds to the ith eigenvector such that the relationship holds...
Thanks again.
Saket
atlas_threads_info: NOT AVAILABLE
blas_opt_info: libraries = ['f77blas', 'cblas', 'atlas'] library_dirs = ['C:\\local\\lib\\yop\\sse2'] define_macros = [('ATLAS_INFO', '"\\"?.?.?\\""')] language = c
atlas_blas_threads_info: NOT AVAILABLE
lapack_opt_info: libraries = ['lapack', 'f77blas', 'cblas', 'atlas'] library_dirs = ['C:\\local\\lib\\yop\\sse2'] define_macros = [('ATLAS_INFO', '"\\"?.?.?\\""')] language = f77
atlas_info: libraries = ['lapack', 'f77blas', 'cblas', 'atlas'] library_dirs = ['C:\\local\\lib\\yop\\sse2'] language = f77
lapack_mkl_info: NOT AVAILABLE
blas_mkl_info: NOT AVAILABLE
atlas_blas_info: libraries = ['f77blas', 'cblas', 'atlas'] library_dirs = ['C:\\local\\lib\\yop\\sse2'] language = c
mkl_info: NOT AVAILABLE
On Sun, Jun 29, 2008 at 9:15 PM, Charles R Harris
wrote: On Sun, Jun 29, 2008 at 6:47 PM, Saket
wrote: Hi,
I'm having this weird problem when computing eigenvalues/vectors with Numpy. I have the following symmetric matrix, B:
-0.3462 0.6538 0.5385 -0.4615 0.6538 -0.3462 -0.3462 -0.3462 0.6538 -0.3462 0.5385 -0.4615 0.6538 -0.3462 -0.3462 -0.3462 0.5385 0.5385 -0.6154 0.3846 0.5385 -0.4615 -0.4615 -0.4615 -0.4615 -0.4615 0.3846 -0.6154 -0.4615 0.5385 0.5385 0.5385 0.6538 0.6538 0.5385 -0.4615 -0.3462 -0.3462 -0.3462 -0.3462 -0.3462 -0.3462 -0.4615 0.5385 -0.3462 -0.3462 0.6538 0.6538 -0.3462 -0.3462 -0.4615 0.5385 -0.3462 0.6538 -0.3462 0.6538 -0.3462 -0.3462 -0.4615 0.5385 -0.3462 0.6538 0.6538 -0.3462
I compute the eigenvalues and eigenvectors of B using numpy.linalg.eig(B). I get the following eigenvalues:
[ 2.79128785e+00 -1.79128785e+00 1.64060486e-16 -3.07692308e-01 -1.00000000e+00 -1.00000000e+00 -1.00000000e+00 -1.00000000e+00]
I do the same thing in Matlab and get the SAME eigenvalues. However, my eigenVECTORS in Matlab versus numpy are different. It makes no sense to me. In general, the following relationship should hold: Bx = Lx, where B is my matrix, x is an eigenvector, and L is the corresponding eigenvalue. For the eigenvectors that Matlab returns, I have confirmed that the relationship does hold. But for the Numpy eigenvectors, it doesn't!
Any idea why this might be happening? I did some computations myself and it looks like the Matlab output is correct. Just seems like the eigenvectors that Numpy is returning are wrong...
Thanks for any suggestions.
Also note that the -1 eigenvalue has multiplicity 4. This means that any set of orthogonal vectors spanning the same eigenspace will do for eigenvectors, i.e., they aren't unique and roundoff error is likely to have a large effect on what you end up with.
Chuck
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
On Sun, Jun 29, 2008 at 21:14, Saket
Also, I'm getting different numbers when I do the above using eig(A) and eigh(A). I thought eigh would be faster, but would still give the same results...
What different numbers? Remember, as Chuck pointed out, you have a multiplicity of -1 eigenvalues, so the actual eigenvectors corresponding to those eigenvalues are not uniquely determined. The details of the algorithm will determine exactly which ones you get. eigh() has a different algorithm than eig(); that's the reason that it is faster. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
Everything's working now. I just messed up the rows and columns.
Thanks a lot, guys.
On Sun, Jun 29, 2008 at 10:35 PM, Robert Kern
On Sun, Jun 29, 2008 at 21:14, Saket
wrote: Also, I'm getting different numbers when I do the above using eig(A) and eigh(A). I thought eigh would be faster, but would still give the same results...
What different numbers? Remember, as Chuck pointed out, you have a multiplicity of -1 eigenvalues, so the actual eigenvectors corresponding to those eigenvalues are not uniquely determined. The details of the algorithm will determine exactly which ones you get. eigh() has a different algorithm than eig(); that's the reason that it is faster.
-- Robert Kern
"I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
On Sun, Jun 29, 2008 at 21:00, Saket
Hmm... so the relationship Ax = Lx should hold for every eigenvalue and corresponding eigenvector of A, right? But, consider the first eigenvalue,eigenvector pair:
for i,eval in enumerate(d): print abs(numpy.dot(A,v[i]) - numpy.dot(eval,v[i])).max() return
Outputs: 1.928
I thought maybe the ith eigenvector corresponds to a different (not the ith) eigenvalue, but there doesn't seem to be any eigenvalue which corresponds to the ith eigenvector such that the relationship holds...
The eigenvectors are the columns, not the rows. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
participants (3)
-
Charles R Harris
-
Robert Kern
-
Saket