Skip to content

Fixes numerical accuracy issues in quantile.#16572

Merged
andreasnoack merged 1 commit intomasterfrom
sb/quantile-acc
May 26, 2016
Merged

Fixes numerical accuracy issues in quantile.#16572
andreasnoack merged 1 commit intomasterfrom
sb/quantile-acc

Conversation

@simonbyrne
Copy link
Copy Markdown
Member

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

@simonbyrne
Copy link
Copy Markdown
Member Author

cc @andreasnoack can you review and merge?


indlo = floor(index)
i = trunc(Int,indlo)
i = trunc(Int,t0) + 1
Copy link
Copy Markdown
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
Copy Markdown
Member 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
Copy Markdown
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
Copy Markdown
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.

2 participants