java 使用java计算最小二乘法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14608998/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 16:48:47  来源:igfitidea点击:

Compute least squares using java

javaleast-squares

提问by Pegah

I am trying to find a java code to compute the least squares solution (x) in the Ax=b equation. Suppose that

我试图找到一个 java 代码来计算 Ax=b 方程中的最小二乘解 (x)。假设

A = [1 0 0;1 0 0];
b = [1; 2];

x = A\b

returns the

返回

x =

    1.5000
         0
         0

I found Class LeastSquares,

我找到了类 LeastSquares,

public LeastSquares(double[] a, double[] b, int degree)

but in the input both A and B are one dimensional arrays, however, in above example, A is a matrix and B is an array.

但是在输入中 A 和 B 都是一维数组,然而,在上面的例子中, A 是一个矩阵, B 是一个数组。

In Class NonNegativeLeastSquares

在类中 NonNegativeLeastSquares

public NonNegativeLeastSquares(int M, int N, double a[][],double b[])

A is a matrix and B is an array, but the description of the class says that it finds an approximate solution to the linear system of equations Ax = b, such that ||Ax - b||2 is minimized, and such that x >= 0. Which means that x must be always positive.

A 是矩阵,B 是数组,但是类的描述说它找到线性方程组 Ax = b 的近似解,使得 ||Ax - b||2 最小化,并且使得 x >= 0. 这意味着 x 必须始终为正。

I need a similar class as NonNegativeLeastSquares, however with out the x>=0 constraint. Could someone please help me?
thanks a lot.

我需要一个与 NonNegativeLeastSquares 类似的类,但是没有 x>=0 约束。有人可以帮助我吗?
多谢。

回答by maerics