SciRuby / nmatrix

Dense and sparse linear algebra library for Ruby via SciRuby
Other
469 stars 133 forks source link

Add #least_squares for least squares approximation #539

Closed gtamba closed 8 years ago

gtamba commented 8 years ago

Fixes #513

Commits :-

1) Slight modification of #unmqr and #ormqr to prevent one of the input multiplicands from being overwritten

2) Adding of #least_squares

Usage :-


a = NMatrix.new([3,2], [2.0, 0, -1, 1, 0, 2]) 
b = NMatrix.new([3,1], [1.0, 0, -1])

a.least_squares(b)

=> 
[
  [0.33333333333333326]
  [-0.3333333333333334]
]

Currently only works for matrices that are not rank-deficient which can be tackled when QR factorization with column pivoting gets wrapped from Lapack. Would add a few more tests very soon.

translunar commented 8 years ago

@gau27 Can you please rebase against master? I think we've sorted out Travis-CI problems.

gtamba commented 8 years ago

The Travis build is failing because of a faulty spec I added this morning, I don't have Lapack available on my work laptop right now to check it out, will investigate when I reach home.