Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid double-precision rounding error in dropq test #1067

Merged
merged 3 commits into from
Nov 17, 2016
Merged

Avoid double-precision rounding error in dropq test #1067

merged 3 commits into from
Nov 17, 2016

Conversation

martinholmer
Copy link
Collaborator

This pull request makes no substantive changes in test_dropq.py, but does scale back expectations about the equality of two large floating-point numbers in a test that was added in pull request #1060. That new test expected two numbers that are conceptually equal to be the same down to the third decimal place. The new test passed on one local computer, but failed on another local computer (as described in the #1060 conversation). Travis-CI does not run this test because the test uses the confidential puf.csv file. But the two numbers being compared are large: about 1.081e11. So the original test would fail if the two numbers were (for example):

108,100,000,000.001 and
108,100,000,000.002

The expectation was for 15 digits of accuracy, which is at the outer limits of double-precision accuracy. This pull request simply scales back expectations for how close two large floating-point numbers must be to be considered equal.

@talumbau

@codecov-io
Copy link

codecov-io commented Nov 17, 2016

Current coverage is 98.76% (diff: 100%)

Merging #1067 into master will not change coverage

@@             master      #1067   diff @@
==========================================
  Files            38         38          
  Lines          2761       2761          
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
  Hits           2727       2727          
  Misses           34         34          
  Partials          0          0          

Powered by Codecov. Last update 464010c...80de40e

diff_yr0 = 1e-9 * (reform_yr0.loc['combined_tax'] -
baseline_yr0.loc['combined_tax']).values
delta_yr0 = 1e-9 * delta_yr0.loc['combined_tax'].values
npt.assert_array_almost_equal(diff_yr0, delta_yr0, decimal=9)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the docs for assert_array_almost_equal:

https://docs.scipy.org/doc/numpy/reference/generated/numpy.testing.assert_almost_equal.html

it looks like the more highly recommended choice is assert_allclose:

https://docs.scipy.org/doc/numpy/reference/generated/numpy.testing.assert_allclose.html#numpy.testing.assert_allclose

So I probably should have done that in the first place. I believe that in assert_array_almost_equal the decimal argument is interpreted as "digits of accuracy after the decimal point" so I was surprised to see the decimal=9. We can merge this if you would like and I can do a follow up PR to change to assert_allclose or if you are willing to change to assert_allclose I think that would be the more maintainable solution.

@martinholmer
Copy link
Collaborator Author

@talumbau, Is commit 80de40e in pull request #1067 more like what you want?

@talumbau
Copy link
Member

Yes, I think that's better. The default relative tolerance in assert_allclose is 1e-7 which seems good for this use case.

@talumbau
Copy link
Member

+1

@martinholmer martinholmer merged commit c52217c into PSLmodels:master Nov 17, 2016
@martinholmer martinholmer deleted the fix-dropq-test branch November 17, 2016 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants