特征值不正确SciPy稀疏linalg.eigs,eigsh(非对角M矩阵) [英] Incorrect eigenvalues SciPy sparse linalg.eigs, eigsh for non-diagonal M matrix

查看:585
本文介绍了特征值不正确SciPy稀疏linalg.eigs,eigsh(非对角M矩阵)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在求解广义特征值问题A * x = lambda * M * x时,如果M不是对角线,为什么下面使用的scipy.sparse.linalg中的eigheigsh给出错误的结果?

Why do eigh and eigsh from scipy.sparse.linalg as used below give incorrect results when solving the generalized eigenvalue problem A * x = lambda * M * x , if M is non-diagonal?

import mkl
import numpy as np
from scipy import linalg as LA
from scipy.sparse import linalg as LAsp
from scipy.sparse import csr_matrix

A = np.diag(np.arange(1.0,7.0))
M = np.array([[ 25.1,   0. ,   0. ,  17.3,   0. ,   0. ],
       [  0. ,  33.6,  16.8,   8.4,   4.2,   2.1],
       [  0. ,  16.8,   3.6,   0. ,  11. ,   0. ],
       [ 17.3,   8.4,   0. ,   4.2,   0. ,   9.5],
       [  0. ,   4.2,  11. ,   0. ,   2.7,   8.3],
       [  0. ,   2.1,   0. ,   9.5,   8.3,   4.4]])

Asp = csr_matrix(np.matrix(A,dtype=float))
Msp = csr_matrix(np.matrix(M,dtype=float))

D, V = LA.eig(A, b=M)

eigno  = 4
Dsp0, Vsp0 = LAsp.eigs(csr_matrix(np.matrix(np.dot(np.linalg.inv(M),A))),
                         k=eigno,which='LM',return_eigenvectors=True)
Dsp1, Vsp1 = LAsp.eigs(Asp,k=eigno,M=Msp,which='LM',return_eigenvectors=True)
Dsp2, Vsp2 = LAsp.eigsh(Asp,k=eigno,M=Msp,which='LA',return_eigenvectors=True,
                          maxiter=1000)

从LA.eig并使用MatLab进行检查,该带有测试矩阵A和M的广义广义特征值问题的特征值应为:

From LA.eig and checking with MatLab the eigenvalues for this small generalized eigenvalue problem with test matrices A and M should be:

D = [ 0.7208+0.j,  0.3979+0.j, -0.3011+0.j, -0.3251+0.j,  0.0357+0.j,  0.0502+0.j]

我想使用稀疏矩阵,因为涉及的实际A和M矩阵约为30,000 x 30,000. A始终是正方形,实数和对角线,M始终是正方形,实数和对称.当M是对角线时,我得到正确的结果.但是,当求解非对角M矩阵的广义特征值问题时,eigseigsh都给出错误的结果.

I want to use sparse matrices because the actual A and M matrices involved are around 30,000 x 30,000. A is always square, real and diagonal, M is always square, real and symmetric. When M is diagonal I get the correct results. However, both eigs and eigsh give incorrect results when solving the generalized eigenvalue problem for a non-diagonal M matrix.

Dsp1 = [-1.6526+2.3357j, -1.6526-2.3357j, -0.6243+2.7334j, -0.6243-2.7334j]

Dsp2 = [ 2.01019097,  3.09248265,  4.06799498,  7.01216316]

当我将问题转换为标准特征值形式M ^ -1 * A * x = lambda * x时,eigs给出正确的结果(Dsp0).对于大型矩阵,这不是一种选择,因为计算M的逆值会花费太长时间.

When I convert the problem to the standard eigenvalue form M^-1 * A * x = lambda * x, eigs gives the correct result (Dsp0). For large matrices this is not an option because it takes too long to compute the inverse of M.

我注意到,使用mkl或不使用mkl也会产生不同的Dsp1和Dsp2特征值.这个特征值问题可能是由我的Python安装问题引起的吗?我在Mac OS 10.10.2上运行带有SciPy 0.15.1的Python 2.7.8 anaconda-np19py27_p0 [mkl].

I noticed that using mkl or not yields different Dsp1 and Dsp2 eigenvalues as well. Could this eigenvalue problem be caused by an issue with my Python installation? I am running Python 2.7.8 anaconda with SciPy 0.15.1 - np19py27_p0 [mkl] on Mac OS 10.10.2.

推荐答案

两者 eigsh 要求M正定 (有关更多详细信息,请参见文档字符串中的M描述.)

Both eigs and eigsh require that M be positive definite (see the descriptions of M in the docstrings for more details).

您的矩阵M不是正定的.注意负特征值:

Your matrix M is not positive definite. Note the negative eigenvalues:

In [212]: M
Out[212]: 
array([[ 25.1,   0. ,   0. ,  17.3,   0. ,   0. ],
       [  0. ,  33.6,  16.8,   8.4,   4.2,   2.1],
       [  0. ,  16.8,   3.6,   0. ,  11. ,   0. ],
       [ 17.3,   8.4,   0. ,   4.2,   0. ,   9.5],
       [  0. ,   4.2,  11. ,   0. ,   2.7,   8.3],
       [  0. ,   2.1,   0. ,   9.5,   8.3,   4.4]])

In [213]: np.linalg.eigvals(M)
Out[213]: 
array([ 45.92443169,  33.92113421, -13.12639751, -10.6991868 ,
         5.34183619,  12.23818222])

这篇关于特征值不正确SciPy稀疏linalg.eigs,eigsh(非对角M矩阵)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆