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

Floating point errors in nb_tie() #17

Open
fpavogt opened this issue Oct 19, 2020 · 0 comments
Open

Floating point errors in nb_tie() #17

fpavogt opened this issue Oct 19, 2020 · 0 comments
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@fpavogt
Copy link
Member

fpavogt commented Oct 19, 2020

Describe the bug
The np.histogram() function inside nb_tie() is subject to floating point errors. This can cause a mismatch, at times, with the R and/or Matlab implementations of the code (e.g. see mannkendall/Matlab#3).

To Reproduce
In the case of nb_tie_test2_in.csv, the first problematic case is bin 147 with edges [0.205, 0.215).

The data contains the number 0.215, which should belong to bin 148 with edges [0.215, 0.225) (all bins are semi-open on the right in np.histogram()). But in my case, it falls into bin 147 because, when plotted fully, the edges are:
[0.20500000000000007, 0.21500000000000008). That is, floating point errors make the bin edge slightly larger than it should be.

Expected behavior
We cannot fix floating point errors ... but can we make this function more robust against them ? Maybe through the use of Decimals (https://docs.python.org/2/library/decimal.html) ?

@fpavogt fpavogt added bug Something isn't working enhancement New feature or request help wanted Extra attention is needed labels Oct 19, 2020
@fpavogt fpavogt self-assigned this Oct 19, 2020
fpavogt added a commit that referenced this issue Oct 23, 2020
@fpavogt fpavogt removed the bug Something isn't working label Oct 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant