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

Fixes numerical accuracy issues in quantile. #16572

Merged
merged 1 commit into from
May 26, 2016
Merged

Conversation

simonbyrne
Copy link
Contributor

Fixes issue JuliaStats/StatsBase.jl#164, and another when p < eps().

@simonbyrne
Copy link
Contributor Author

cc @andreasnoack can you review and merge?


indlo = floor(index)
i = trunc(Int,indlo)
i = trunc(Int,t0) + 1
Copy link
Member

Choose a reason for hiding this comment

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

To avoid confusion, maybe just t0 = Int(f0) since f0 has already been truncated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

trunc(Int, t0) is technically faster, as it avoids the check of an integer.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense.

@andreasnoack
Copy link
Member

Except for the minor comment, it looks good.

@andreasnoack andreasnoack merged commit 5e32883 into master May 26, 2016
@andreasnoack andreasnoack deleted the sb/quantile-acc branch May 26, 2016 13:43
nalimilan added a commit to JuliaStats/Statistics.jl that referenced this pull request Jul 1, 2023
The `a + γ*(b-a)` introduced by JuliaLang/julia#16572 has the advantage that it
increases with `γ` even when `a` and `b` are very close, but it has the drawback
that it is not robust to overflow. This is likely to happen in practice with
small integer and floating point types.

Conversely, the `(1-γ)*a + γ*b` which is currently used only for non-finite quantities
is robust to overflow but may not always increase with `γ` as when `a` and `b`
are very close or (more frequently) equal since precision loss can give a slightly smaller
value for a larger `γ`. This can be problematic as it breaks an expected invariant.

So keep using the `a + γ*(b-a)` formula when `a ≈ b`, in which case it's almost
like returning either `a` or `b` but less arbitrary.
nalimilan added a commit to JuliaStats/Statistics.jl that referenced this pull request Jul 29, 2023
The `a + γ*(b-a)` introduced by JuliaLang/julia#16572 has the advantage that it
increases with `γ` even when `a` and `b` are very close, but it has the drawback
that it is not robust to overflow. This is likely to happen in practice with
small integer and floating point types.

Conversely, the `(1-γ)*a + γ*b` which is currently used only for non-finite quantities
is robust to overflow but may not always increase with `γ` as when `a` and `b`
are very close or (more frequently) equal since precision loss can give a slightly smaller
value for a larger `γ`. This can be problematic as it breaks an expected invariant.

So keep using the `a + γ*(b-a)` formula when `a ≈ b`, in which case it's almost
like returning either `a` or `b` but less arbitrary.
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.

None yet

2 participants