【问题标题】:Finding SVD matrices of a complex matrix in Java在 Java 中查找复杂矩阵的 SVD 矩阵
【发布时间】:2019-07-17 13:23:58
【问题描述】:

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

我一直在使用一些技巧来使用here 找到的技术从等效实矩阵中找到 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());

【问题讨论】:

  • ojAlgo 支持复数的 SVD。
  • @apete 我根本找不到复杂版本的任何文档...我只看到真实版本
  • 您只需使用名为 COMPLEX 的工厂而不是 PRIMITIVE – SingularValue.COMPLEX.make()
  • 从历史上看,Jampack (JAva Matrix PACKage)(从 1999 年开始)是第一个 Java 实现。你可以找到更精致的版本here

标签: java android matrix linear-algebra svd


【解决方案1】:

如果您可以使用本机库,那么jeigen 是一个选项

【讨论】:

    猜你喜欢
    • 2016-12-17
    • 1970-01-01
    • 1970-01-01
    • 2018-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多