fix(tdigest): interpolate quantiles toward the nearer centroid and normalize the left tail - #250
Merged
tisonkun merged 6 commits intoAug 31, 2026
Conversation
…rmalize the left tail
tisonkun
approved these changes
Aug 31, 2026
tisonkun
left a comment
Member
There was a problem hiding this comment.
Thanks for your contribution! Merging ...
tisonkun
enabled auto-merge (squash)
August 31, 2026 09:53
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
maxin the right quantile tail and normalize the left rank tail by total weight.0 / 0expression.Why
The interior interpolation paired each centroid mean with the distance from that same side of the bracket. Linear interpolation needs the opposite-side distance, so the previous result could move toward the lower centroid as rank increased and make quantiles non-monotonic.
The left and right tail branches contained two independent mirror errors. The right-tail formula also degenerates when the last centroid has weight two: at the only boundary that reaches the formula, both its numerator and denominator are zero. Returning the known maximum at that boundary keeps the handling local and avoids changing interpolation elsewhere.
Validation
cargo x checkcargo x testcargo x lintupdateandmerge