Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用Java语言求复矩阵的SVD矩阵_Java_Android_Matrix_Linear Algebra_Svd - Fatal编程技术网

用Java语言求复矩阵的SVD矩阵

用Java语言求复矩阵的SVD矩阵,java,android,matrix,linear-algebra,svd,Java,Android,Matrix,Linear Algebra,Svd,我目前正在从事一个音频信号处理项目,需要在Java中的复杂矩阵上使用SVD。我目前的线性代数库是ApacheCommons。然而,它只提供实矩阵的SVD,JAMA、JBLAS、EJML和ojAlgo都不支持复杂的SVD 我一直在使用一些技巧,使用所发现的技术,从等效实矩阵中找到奇异值分解。然而,当我重建矩阵时,这种技术对于虚部来说有很大的不精确性 如果有人能为我找到一个替代方法,使用真正的SVD库或支持java中复杂SVD的库来查找复杂SVD,我将不胜感激 我是这样做的: //Arra

我目前正在从事一个音频信号处理项目,需要在Java中的复杂矩阵上使用SVD。我目前的线性代数库是ApacheCommons。然而,它只提供实矩阵的SVD,JAMA、JBLAS、EJML和ojAlgo都不支持复杂的SVD

我一直在使用一些技巧,使用所发现的技术,从等效实矩阵中找到奇异值分解。然而,当我重建矩阵时,这种技术对于虚部来说有很大的不精确性

如果有人能为我找到一个替代方法,使用真正的SVD库或支持java中复杂SVD的库来查找复杂SVD,我将不胜感激


我是这样做的:

    //Array2DRowFieldMatrix<Complex> A = some matrix defined earlier
    Array2DRowRealMatrix AA = new Array2DRowRealMatrix(2 * row, 2 * col);
    Complex Aentry;

    for (int c = 0; c < row; c++) {
        for (int s = 0; s < col; s++) {
            Aentry = A.getEntry(c, s);

            AA.setEntry(c, s, Aentry.getReal());
            AA.setEntry(c, col + s, -Aentry.getImaginary());
            AA.setEntry(row + c, s, Aentry.getImaginary());
            AA.setEntry(row + c, col + s, Aentry.getReal());
        }
    }

    Array2DRowRealMatrix UU, SS, VV;

    svd = new SingularValueDecomposition(AA);

    UU = (Array2DRowRealMatrix) svd.getU();
    SS = (Array2DRowRealMatrix) svd.getS();
    VV = (Array2DRowRealMatrix) svd.getV();

    double[][] tempU = new double[row][2 * row];
    double[][] tempV = new double[col][2 * row];
    double[] tempS = new double[row];

    Array2DRowFieldMatrix<Complex> U = new Array2DRowFieldMatrix<>(ComplexField.getInstance(), row, row);
    Array2DRowFieldMatrix<Complex> S = new Array2DRowFieldMatrix<>(ComplexField.getInstance(), row, row);
    Array2DRowFieldMatrix<Complex> V = new Array2DRowFieldMatrix<>(ComplexField.getInstance(), col, row);
    Array2DRowFieldMatrix<Complex> recon, diff;

    UU.copySubMatrix(row, 2 * row - 1, 0, 2 * row - 1, tempU);
    VV.copySubMatrix(col, 2 * col - 1, 0, 2 * row - 1, tempV);

    for (int i = 0; i < row; i++) {
        for (int j = 0; j < row; j++) {
            U.setEntry(i, j, new Complex(tempU[i][2 * j], tempU[i][2 * j + 1]));
        }
    }

    for (int i = 0; i < col; i++) {
        for (int j = 0; j < row; j++) {
            V.setEntry(i, j, new Complex(tempV[i][2 * j], tempV[i][2 * j + 1]));
        }
    }

    for (int i = 0; i < row; i++) {
        tempS[i] = SS.getEntry(i * row, i * row);
        if (tempS[i] == 0) {
            tempS[i] = EPSILON;
        }
    }

    for (int i = 0; i < row; i++) {
        for (int j = 0; j < row; j++) {
            if (i != j) {
                S.setEntry(i, j, Complex.ZERO);
            }
        }

        S.setEntry(i, i, new Complex(tempS[i]));
    }

    recon = (Array2DRowFieldMatrix<Complex>)U.multiply(S).multiply(conjugate(V).transpose());
//Array2DRowFieldMatrix A=前面定义的某个矩阵
ARRAY2DROREALMATRIX AA=新的ARRAY2DROREALMATRIX(2*行,2*列);
复杂通风;
对于(int c=0;c
如果您可以使用本机库,那么是一个选项

ojAlgo支持复数的SVD。@apete我根本找不到任何复杂版本的文档…我只看到真实版本您只需在历史基础上使用名为complex而不是PRIMITIVE的工厂–SingularValue.complex.make()(从1999年起)这是第一个Java实现。你可以找到更精致的版本