本文介绍了Matlab和Python采取的特征向量的符号差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能否解释一下为什么某些本征矢量(2-4)存在符号差异?这种差异是否会影响进一步计算中的进一步计算,例如降维?

Could you please explain why there is a sign difference in some of the eigenvectors (2-4)? Does this difference affect further calculation in further calculations, e.g dimensionality reduction?

Matlab:

N = 5000;
dataA = rand(N,5);
covA = cov(dataA);
%covA = dataA*dataA'/(length(dataA)-1);
covA = covA + eps.*eye(size(covA));
[~,pA] = chol(covA);
assert(pA==0,'A is not possitive definite')

dataB = rand(N,5);
covB = cov(dataB);
%covB = dataB*dataB'/(length(dataB)-1);
covB = covB + eps.*eye(size(covB));
[~,pB] = chol(covB);
assert(pB==0,'B is not possitive definite')

[V,D] = eig(covA, covB);

V =

   -0.4241   -1.0891    1.8175    2.4067   -1.3032
    1.4445   -1.8960   -1.4118   -0.6514   -2.0075
    0.1214   -2.5039    0.3332   -0.1705    2.3609
   -2.1235   -0.7007    1.1632   -2.1532   -1.0554
   -2.2599   -0.4405   -2.2236    1.2545    0.0760

Python:

from scipy.linalg import eigh
import scipy.io
import numpy as np

cov_mat = scipy.io.loadmat('cov.mat')
covA = cov_mat['covA']
covB = cov_mat['covB']
eigvals, eigvecs = eigh(covA, covB, eigvals_only=False)

np.savetxt('eigvals.txt', eigvals, fmt='%.4f')
np.savetxt('eigvecs.txt', eigvecs, fmt='%.4f')

eigvecs =

   0.4241 1.0891 -1.8175 -2.4067 -1.3032
  -1.4445 1.8960  1.4118  0.6514 -2.0075
  -0.1214 2.5039 -0.3332  0.1705  2.3609
   2.1235 0.7007 -1.1632  2.1532 -1.0554
   2.2599 0.4405  2.2236 -1.2545  0.0760

推荐答案

它们是相同的特征向量,因为翻转特征向量上的符号不会改变其表示形式-它们将具有相同的特征值.因此,它不会影响进一步的计算.

They are the same eigenvectors, as flipping the signs on eigenvectors does not change their formulation - they will have the same eigenvalue. It will not affect further calculations as a result.

为什么它们的计算方式不同?最有可能的原因是,运行的子例程会根据所操作的矩阵而有所不同,并且不关心它们返回的符号"是什么,因为特征值没有一个.

Why are they calculated differently? Most likely because the subroutines that are run vary based on the matrix that is being operated on, and don't care what 'sign' they return because eigenvalues don't have one.

简单的数学证明:

如果x是具有特征值q的矩阵A的特征向量,则根据定义,我们具有Ax = qx.

If x is an eigenvector of matrix A with eigenvalue q, then by definition we have that Ax = qx.

由此得出,A(-x) = -(Ax) = -(qx) = q(-x)使得-x是具有相同特征值的特征向量.

It follows that A(-x) = -(Ax) = -(qx) = q(-x) such that -x is an eigenvector with the same eigenvalue.

这篇关于Matlab和Python采取的特征向量的符号差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 17:18