【问题标题】:EigenVectors issue using apache common math3 library使用 apache 通用 math3 库的 EigenVectors 问题
【发布时间】:2015-08-27 09:24:12
【问题描述】:

我正在使用apache commons math3 library 计算协方差矩阵、特征向量和特征值。所以我的主要功能是(给定一个双矩阵):

private void coVariance(double[][] matrix) {
        RealMatrix mx = MatrixUtils.createRealMatrix(matrix);
        RealMatrix cov = new Covariance(mx).getCovarianceMatrix();
        System.out.println("***************************************");
        System.out.println("Covariance Matrix");
        for (int i = 0; i < cov.getRowDimension(); i++) {
            for (int j = 0; j < cov.getColumnDimension(); j++) {
                System.out.print(cov.getEntry(i, j) + " ");
            }
            System.out.println();
        }
        System.out.println("***************************************");
        EigenDecomposition e = new EigenDecomposition(cov);
        double[] arrayEigenValue = e.getRealEigenvalues();
        for (int i = 0; i < e.getRealEigenvalues().length; i++) {
            System.out.println("eigenValue with index " + i + " " + arrayEigenValue[i]);
            RealVector arrayEigenVector = e.getEigenvector(i);
            for (int j = 0; j < arrayEigenVector.getDimension(); j++) {
                System.out.print(arrayEigenVector.getEntry(j) + " ");
            }
            System.out.println();
            System.out.println();
        }
        System.out.println("***************************************");
    }

为了了解一切是否正确,我使用了一个已经计算出 covariance/eigenValues/eigenVector 的示例:

2.5,2.4
0.5,0.7
2.2,2.9
1.9,2.2
3.1,3.0
2.3,2.7
2,1.6
1,1.1
1.5,1.6
1.1,0.9

它有这个协方差矩阵eigenVectors和eigenValues的结果:

0,616555556 0.615444444
0.615444444 0.716555556

特征值:

0.0490833989
1.28402771

特征向量:

1° = -0.735178656 -0.677873309
2° = 0.677873399  -0.735178656

我的程序的结果:

协方差矩阵

0.6165555555555556 0.6154444444444446 
0.6154444444444446 0.7165555555555555 

特征值:

1.2840277121727839 
0.04908339893832714

特征向量:

1° = -0.7351786555444081  -0.6778733985280118 
2° = -0.6778733985280118   0.7351786555444081

如您所见,特征向量在第二个特征向量的第二个值的符号上是不同的 0.7351786555444081

谁能解释一下为什么?

【问题讨论】:

    标签: java matrix apache-commons eigenvector


    【解决方案1】:

    Oirc,

    如果您不知道矩阵中特征值的数学公式,我们使用公式来计算它|A-L.I| = 0 其中A 是矩阵(行数据) L 是 (lambda) 或常量,我们在这里说的特征值 I是单位矩阵,等于A矩阵阶。

    通过这个我们将得到L 可以是正数或负数的值 我们将把这些值放到该矩阵方程中以计算向量矩阵。 所以经过计算,矩阵元素可以是正数也可以是负数。

    理论上:"-"/"+"ive 符号表示向量值的方向。

    【讨论】:

      猜你喜欢
      • 2015-05-08
      • 1970-01-01
      • 2014-09-27
      • 1970-01-01
      • 2018-08-27
      • 1970-01-01
      • 2015-09-29
      • 1970-01-01
      • 2010-12-10
      相关资源
      最近更新 更多