scipy.linalg.eig return complex eigenvalues for covariance matrix?

后端 未结 2 1493
说谎
说谎 2021-01-04 00:11

The eigenvalues of a covariance matrix should be real and non-negative because covariance matrices are symmetric and semi positive definite.

However, take a look at

2条回答
  •  误落风尘
    2021-01-04 00:19

    What you are experiencing is numerical instability due to limitations on floating point precision.

    Note that:

    (1) MATLAB also returned negative values, but the printing format is set to short and you don't see the full precision of the double stored in memory. Use format long g for printing more decimals

    (2) All imaginary parts returned by numpy's linalg.eig are close to the machine precision. Thus you should consider them zero.

提交回复
热议问题