gpt4 book ai didi

numpy - scipy.linalg.eig 是否给出了正确的左特征向量?

转载 作者:行者123 更新时间:2023-12-01 01:11:00 24 4
gpt4 key购买 nike

我有一个关于 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 (根据特征值重新排序后)可以很快发现前者是后者的共轭,因此 left_evscipy.linalg.eig 获得与 left=True不是有效的左特征向量。
另一个对特征向量有效性的检查可以基于这样一个事实:对于任意实方矩阵,左右特征向量是双正交的,即: left_v.T.dot(right_v)应该给出一个对角矩阵,但它没有,
直到我将其更改为: left_v.T.conj().dot(right_v) ,
尽管: left_v_2.T.dot(right_v_2)给出一个预期的对角矩阵。
有没有人遇到过类似的问题?我说的对吗? sciPy 手册在描述 eig 时是否有点不精确?你能给点建议吗?
非常感谢!

最佳答案

关于 vl , eig docstring 说:

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

或者,取两边的共轭转置(即厄米转置)(这就是 .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 docstring 在返回值的描述中还说:
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 列的共轭转置这实际上是左特征向量。

关于numpy - scipy.linalg.eig 是否给出了正确的左特征向量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15560905/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com