我目前正在从事音频信号处理项目,需要在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());