无法使用Eigen获得负特征向量。 jblas中的特征向量方法

时间:2017-01-18 11:42:12

标签: java jblas

我正在尝试为下面的矩阵计算特征向量和特征值。我能够得到结果,但所有特征向量都是正的

示例:

12.48 -1.88 -6.7

-1.88 26.7 4.32

-6.7 4.32 21.2

[1] Real Eigenvalue = 8.8362 = S3

[1] Real Eigenvector:

0.8753

-0.0247

0.4830

[2] Real Eigenvalue = 20.9867 = S2

[2] Real Eigenvector:

0.3873

0.6337

-0.6696

[3] Real Eigenvalue = 30.5570 = S1

[3] Real Eigenvector:

0.2895

-0.7731

-0.5643

以下是我测试时的方法和输出。

 /**
 * Computes the Principal eigenvalues of a given matrix
 *
 * @param matrix matrix in which eigenvalues are computed
 * @return Principal eigenvalues list in an ascending order
 */
public List<Double> getPrincipalEigenValues(DoubleMatrix matrix) {

    List<Double> EigenValuesList = new ArrayList<Double>();// initialize a list to store eigenvalues
    ComplexDoubleMatrix eigenvalues = Eigen.eigenvalues(matrix);// compute eigenvalues
    for (ComplexDouble eigenvalue : eigenvalues.toArray()) {
        Double value = Double.parseDouble(String.format("%.2f ", eigenvalue.abs()));
        EigenValuesList.add(value);
    }
    //it returns Principal Eigen Values in the  order of [S3, S2, S1]
    return EigenValuesList;
}

/**
 * Computes the Principal eigenvectors of a given matrix
 *
 * @param matrix matrix in which eigenvectors are computed
 * @return Principal eigenvectors list in the same order as the eigenvalues
 */
public List<Double> getPrincipalEigenVectors(DoubleMatrix matrix) {

    List<Double> EigenVectorList = new ArrayList<Double>();// initialize a list to store veigenvectors
    ComplexDoubleMatrix eigenvectors = Eigen.eigenvectors(matrix)[0];// compute veigenvectors
    for (ComplexDouble eigenvector : eigenvectors.toArray()) {
        Double value = Double.parseDouble(String.format("%.4f ", eigenvector.abs()));
        EigenVectorList.add(value);
    }
    //it returns Principal Eigen Vectors in the  order of [n3x, n3y, n3z,n2x, n2y, n2z,n1x, n1y, n1z]
    return EigenVectorList;
}

测试方法后的结果。

主要特征值[8.84,20.99,30.56] Principal EigenVectors [0.8753,0.0247,0.483,0.3873,0.6337,0.6666,0.2895,0.7771,0.5643]

0 个答案:

没有答案