最小二乘



我正在尝试为一个过度确定的系统计算最小二乘。

DenseMatrix64F D_dense = RandomMatrices.createRandom(dimension, 3 * dimension, -1, 1, r);
D1 = SimpleMatrix.wrap(D1).transpose().getMatrix();
LinearSolver<DenseMatrix64F> x2 = LinearSolverFactory.leastSquares(D1.numRows, D1.numCols);
x2.setA(D1);
DenseMatrix64F D_i = new DenseMatrix64F(D1.numRows, D1.numCols);
x2.invert(D_i);

然后我得到错误

Exception in thread "main" java.lang.IllegalArgumentException: Unexpected dimensions for X: X rows = 9 expected = 3

我需要调用什么才能返回矩阵D1的最小二乘?

看起来你在试图反转一个矩形矩阵。你只能求一个方阵的逆。这也不是最好的解法。请看下面的手册链接:

https://code.google.com/p/efficient-java-matrix-library/wiki/SolvingLinearSystems

最新更新