简体   繁体   English

XX^T 矩阵不是正定的,虽然它应该是

[英]X X^T Matrix is not positive definite, although it should be

I have a matrix M where M.shape = (679, 512) .我有一个矩阵M其中M.shape = (679, 512)

I would like to find the eigenvectors and eigenvalues of MM^T , it's covatiance matrix, which should be positive definite in maths.我想找到MM^T的特征向量和特征值,它是协方差矩阵,在数学中应该是正定的。 I find them using:我发现他们使用:

import numpy as np
v, w = np.linalg.eig(np.matmul(M, M.T))

However, for some reason I see my eigenvalues/eigenvectors as:但是,出于某种原因,我将我的特征值/特征向量视为:

>>> v
array([ 1.17577206e+10+0.0000000e+00j,  1.05090161e+10+0.0000000e+00j,
        7.01098189e+09+0.0000000e+00j,  5.19451802e+09+0.0000000e+00j, 
    ...
    1.03985971e-12+0.0000000e+00j, -3.04194468e-13+6.9097571e-13j,
   -3.04194468e-13-6.9097571e-13j,  1.77363116e-13+0.0000000e+00j,
   -1.20885913e-13+0.0000000e+00j, -4.95627438e-14+0.0000000e+00j,
   -1.56456859e-16+0.0000000e+00j], dtype=complex64)

How is this possible?这怎么可能? Shouldn't MM^T be positive semi definite, giving positive and real eigenvalues only? MM^T不应该是半正定的,只给出正特征值和实特征值吗? How is it possible to get non real eigenvalues?如何获得非实数特征值?

def is_positive_def(x):
    return np.all(np.linalg.eigvals(x) > 0)

"Shouldn't MM^T be positive semi definite, giving positive and real eigenvalues only?" “MM^T 不应该是半正定的,只给出正和实特征值吗?” If you change "positive" to "nonnegative", then yes, that is true mathematically.如果您将“正”更改为“非负”,那么是的,这在数学上是正确的。 In fact, instead of numpy.linalg.eig , you can use numpy.linalg.eigh , which will return real eigenvalues and eigenvectors.事实上,而不是numpy.linalg.eig ,您可以使用numpy.linalg.eigh ,这将返回真正的特征向量。

Note that in a few places, you misstated that claim, and said that MM^T is positive definite.请注意,在一些地方,您错误地陈述了该声明,并说 MM^T 是正定的。 That is not correct.那是不正确的。 If M has shape (679, 512), then 679 - 512 = 167 of the eigenvalues will be 0;如果 M 的形状为 (679, 512),则 679 - 512 = 167 个特征值将为 0; MM^T is semi-definite, not positive definite . MM^T 是半定的,不是正定的

In the numerical computation of the eigenvalues, all those theoretical values of 0 will not be computed exactly by eig or eigh .在特征值的数值计算中,所有为 0 的理论值将不会由eigeigh精确计算。 The first 167 eigenvalues will be close to zero, and numerical error can result in some of those values being negative.前 167 个特征值将接近于零,数值误差可能导致其中一些值为负。 When I did the calculation on a random M (specifically, M = np.random.gamma(8, size=(679, 512)) , the largest eigenvalue of MM^T was about 2.227e7, the smallest was -5.822e-10, and the smallest magnitude was 3.881e-13. Note that 5.822e-10/2.227e7 (ie np.abs(v.min()) / v.max() ) is about 2.61e-17, so all those small eigenvalues are effectively 0 relative to the largest eigenvalue .当我对随机 M 进行计算时(特别是M = np.random.gamma(8, size=(679, 512)) ,MM^T 的最大特征值约为 2.227e7,最小的是 -5.822e- 10,最小的震级是 3.881e-13。注意 5.822e-10/2.227e7(即np.abs(v.min()) / v.max() )大约是 2.61e-17,所以所有那些相对于最大的特征值,小的特征值实际上是 0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM