开发者

numpy.linalg.lstsq equivalent in Apache Commons Math Java library?

I have the following call to numpy.linalg.lstsq:

http://docs.scipy.org/doc/numpy/reference/generated开发者_开发百科/numpy.linalg.lstsq.html

x = [[ 0.69314718] [ 1.09861229] [ 1.38629436] [ 1.60943791] [ 1.79175947] [ 1.94591015]]

y = [ 0. 0.20273255 0.5815754 0.7520387 0.96885669 1.09861229]

l = numpy.linalg.lstsq(x, y)

which returns

l -> tuple: (array([ 0.46323573]), array([ 0.25872885]), 1, array([ 3.63269497]))

Could somebody point out the equivalent function (if available) in

http://commons.apache.org/math/

(or possibly in some other Java math library ...)


Thank you for the pointer Joe.

Here is the code for reference:

double[][] testSquare = {{0.69314718}, {1.09861229}, {1.38629436}, {1.60943791}, {1.79175947}, {1.94591015}};
RealMatrix matrix = MatrixUtils.createRealMatrix(testSquare);
SingularValueDecomposition svd = new SingularValueDecomposition(matrix);
DecompositionSolver ds=svd.getSolver();
double[] b = {0.0, 0.20273255, 0.5815754, 0.7520387, 0.96885669, 1.09861229};
ds.solve(b)[0];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜