java - 在 Java 中查找复杂矩阵的 SVD 矩阵
问题描述
我目前正在从事音频信号处理项目,需要在 Java 中的复杂矩阵上使用 SVD。我目前的线性代数库是 Apache Commons。但是,它只提供实矩阵的 SVD,JAMA、JBLAS、EJML、ojAlgo 也不支持复杂的 SVD。
我一直在使用一些技巧来使用此处找到的技术从等效实数矩阵中找到 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());
解决方案
如果您可以使用本机库,那么jeigen是一个选项
推荐阅读
- python - 在没有基类的情况下调用 super()
- javascript - 为什么事件处理程序返回的事件最初是“未定义的”?
- vapor - Vapor 3 使用内联脚本渲染叶子模板
- java - 创建蓝牙连接的步骤是什么?
- javascript - 使用 chrome HTML 时自动播放问题
- python - 对于列表 L 中的每个项目,在数据框中找到所有相应的项目
- javascript - 使用带像素的背景位置的中心图像
- python - 将 TFlearn 模型转换为 Keras - Python 3.7
- webstorm - WebStorm 与 Visual Studio 中的调试
- sql-server - 使用 LEFT() 和 SUBSTRING() 从字符串中只提取这么多字符