DataHaskell / dh-core

Functional data science
138 stars 23 forks source link

Pull Request For Issue #14 #23

Closed AdLucem closed 5 years ago

AdLucem commented 5 years ago

Please review the tests?

AdLucem commented 5 years ago

Sorry, my bad! Removed .stack_work and stack.yaml.

bollu commented 5 years ago

BTW, Please add a closes #14 in the pull request description to make sure that the issue is automatically closed when the PR is merged :) That simplifies managing issues.

ocramz commented 5 years ago

Thank you @AdLucem for following up on this and @bollu for the thorough review. All contributions including code review are certainly welcome.

Currently there is a test error related to floating point comparison :

      test/LibSpec.hs:18: 
      1) Q-R Decomposition Matrix Q is orthogonal
           expected: True
            but got: False
AdLucem commented 5 years ago

@ocramz That's not a floating point error, I checked. Matrix Q is not orthogonal (orthogonal under the definition of matrix * matrix transpose = identity matrix) I commented out the test print in test/LibSpec.hs showing matrix Q for my test case (tried it for two separate matrices), but you can uncomment it and check.

Shimuuar commented 5 years ago

And I strongly susoect it is floating point rounding errors. There are two possible sourses of errors. 1) QR factorization itself 2) Q maybe not representable as orthogonal matrix and IEEE754 approximation may be not orthogonal

AdLucem commented 5 years ago

@Shimuuar Oh. I'm not sure, so I'll just write the example I tested here: For a test matrix, this was the matrix Q I got (the other matrix was an upper triangular matrix):

0.0000 0.9129 -0.9631 0.4472 0.3651 -0.2408 0.8944 -0.1826 0.1204

Calculating Q * (Q transpose), this is what I got:

1.7609 0.5652 -0.2826 0.5652 0.3912 0.3043
-0.2826 0.3043 0.8477

AFAIK it's not close enough to an identity matrix for it to be a floating point error, but I might be wrong?

Shimuuar commented 5 years ago

THAT is clearly bug in algorithm (or in test). Values of the order 1E-15 could and will arise due to rounding. But not valus of the order 1

AdLucem commented 5 years ago

@Shimuuar the result matrix above is hand-calculated (using a matrix calculator), not from the tests.

Shimuuar commented 5 years ago

One thing. When this PR will be merged please use "squash and merge". Otherwise *.o* &*.hi` files will be left in history and they're quite bulky

ocramz commented 5 years ago

@AdLucem will you have time to complete this? I think it's just a matter of picking a different test matrix. The zeros on the diagonal might be the problem.

AdLucem commented 5 years ago

@ocramz I tried test matrices without zeroes on the diagonal and it gave the same problem... I'll try fixing up some display-tests to maybe conclusively show what's going wrong?

ocramz commented 5 years ago

@AdLucem yes please!

AdLucem commented 5 years ago

@AdLucem could you remove the .stack-work folder from the PR ?

Ah, will do. I figured out what was wrong (thanks to @bollu ) and was correcting it

AdLucem commented 5 years ago

@marcozocca-seal I fixed the test issue. Sort of.