【问题标题】:Is scipy.linalg.eig giving the correct left eigenvectors?scipy.linalg.eig 是否给出了正确的左特征向量?
【发布时间】:2013-03-22 00:54:46
【问题描述】:

我有一个关于 scipy.linalg.eig 如何计算左右特征向量的问题。也许我误解了一切,但事情似乎不适合我......

从一开始。为了获得特征值和两个特征向量,我使用了以下内容:

ev, left_v, right_v = scipy.linalg.eig(A, left=True)

根据manual,在调用函数时设置left=True 后,我应该期望将左特征向量作为left_v 的列,其中第i 列指的是第i 个特征值。但是,结果不是我预期的,所以我做了一个简单的检查。

我计算了两次调用该函数的左右特征向量(详情请查看here):

right_ev, right_v_2 = scipy.linalg.eig(A)
left_ev, left_v_2 = scipy.linalg.eig(A.T)

其中left_v_2 的列是与left_ev 中的对应值相关联的特征向量。 值得强调的是,right_ev_2left_ev_2 给出了相同的特征值,但是它们的顺序不同,需要加以说明。

比较left_evleft_ev_2(在对特征值重新排序之后)可以很快发现前者是后者的共轭,因此从scipy.linalg.eig 获得的left_evleft=True 是无效的左特征向量。

基于任意实方矩阵左右特征向量是双正交的,可以对特征向量的有效性进行另一项检查,即:

left_v.T.dot(right_v) 应该给出一个对角矩阵,但它没有, 直到我把它改成:left_v.T.conj().dot(right_v),

同时:

left_v_2.T.dot(right_v_2) 给出一个预期的对角矩阵。

以前有没有人遇到过类似的问题?我说的对吗? sciPy 手册在描述eig 时是否有点不精确?能给点建议吗?

非常感谢!

【问题讨论】:

    标签: numpy scipy eigenvector


    【解决方案1】:

    关于vleig 文档字符串说:

    a.H vl[:,i] = w[i].conj() b.H vl[:,i]
    

    或者,取两边的共轭转置(即Hermitian转置)(这是.H的意思),并假设b是恒等式,

    vl[:,i].H a = w[i] vl[:,i].H
    

    所以vl 的共轭转置的行是a 的实际左特征向量。

    Numpy 数组实际上没有 .H 属性,因此必须使用 .conj().T。

    这是一个验证计算的脚本:

    import numpy as np
    from scipy.linalg import eig
    
    # This only affects the printed output.
    np.set_printoptions(precision=4)
    
    a = np.array([[6, 2],
                  [-1, 4]])
    
    w, vl, vr = eig(a, left=True)
    
    print "eigenvalues:", w
    print
    
    # check the left eigenvectors one-by-one:
    for k in range(a.shape[0]):
        val = w[k]
        # Use a slice to maintain shape; vec is a 2x1 array.
        # That allows a meaningful transpose using .T.
        vec = vl[:, k:k+1]
        # rowvec is 1x2; it is the conjugate transpose of vec.
        # This should be the left eigenvector.
        rowvec = vec.conj().T
        # Verify that rowvec is a left eigenvector
        lhs = rowvec.dot(a)
        rhs = val * rowvec
        print "Compare", lhs, "to", rhs
        print rowvec, "is",
        if not np.allclose(lhs, rhs):
            print "*NOT*",
        print "a left eigenvector for eigenvalue", val
    
    print
    print "Matrix version:"
    print "This"
    print vl.conj().T.dot(a)
    print "should equal this"
    print np.diag(w).dot(vl.conj().T)
    

    输出:

    eigenvalues: [ 5.+1.j  5.-1.j]
    
    Compare [[ 1.6330+2.4495j  4.0825+0.8165j]] to [[ 1.6330+2.4495j  4.0825+0.8165j]]
    [[ 0.4082+0.4082j  0.8165-0.j    ]] is a left eigenvector for eigenvalue (5+1j)
    Compare [[ 1.6330-2.4495j  4.0825-0.8165j]] to [[ 1.6330-2.4495j  4.0825-0.8165j]]
    [[ 0.4082-0.4082j  0.8165+0.j    ]] is a left eigenvector for eigenvalue (5-1j)
    
    Matrix version:
    This
    [[ 1.6330+2.4495j  4.0825+0.8165j]
     [ 1.6330-2.4495j  4.0825-0.8165j]]
    should equal this
    [[ 1.6330+2.4495j  4.0825+0.8165j]
     [ 1.6330-2.4495j  4.0825-0.8165j]]
    

    现在,eig 文档字符串也在返回值的描述中说:

    vl : double or complex ndarray
        The normalized left eigenvector corresponding to the eigenvalue
        ``w[i]`` is the column v[:,i]. Only returned if ``left=True``.
        Of shape ``(M, M)``.
    

    这可能会产生误导,因为左特征向量(例如 http://mathworld.wolfram.com/LeftEigenvector.htmlhttp://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors#Left_and_right_eigenvectors)的传统定义是一个行向量,所以它是 vl 列的共轭转置,实际上是左特征向量。

    【讨论】:

    • 谢谢,沃伦。我了解到您确认vl 的共轭转置是根据常用约定的左特征向量。现在的问题是为什么eigdoscstring 提供了这种模棱两可的信息?
    • Fwiw,A = np.array([ [0., -1], [1, 0] ]); w, L, R = eig(A, left=True, right=True); print "L* . R: \n", L.conj().T.dot(R) 给了- I——如果你期待I,那就麻烦了。一般来说,它可能是np.diag( 1 -1 -1 1 ),所以没有快速修复? (版本:numpy 1.14.1 scipy 1.0.0 python 2.7.14 mac 10.10.5)
    • 一般情况下,L.conj().T.dot(R) 必须是diagonal,但不一定是标识。存在左右特征向量,使得乘积为恒等,但eig 不能保证计算出这样的特征向量。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-08
    • 1970-01-01
    • 2013-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多