You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Weighted ApproximateQuantiles depends on the scale of the weights #41559
With weighted=True, ApproximateQuantiles gives different quantiles when every weight is multiplied by the same number, which shouldn't change a weighted quantile. Small weights give quantiles that are all the minimum:
The weighted example in the ApproximateQuantiles docstring ([(i, 1 if i<10 else 1e-5) for i in range(101)], documented output [0, 2, 5, 7, 100]) gives [0, 2, 4, 7, 100] on master. It gives the documented output only when the weights are multiplied by 1000.
ApproximateQuantilesCombineFn.extract_output uses offset = (total_weight - 1) / (num_quantiles - 1) in both cases. The - 1 turns an element count into the index of the last element, which is right without weights, but with weights it subtracts one unit of weight, so the targets move with the scale. With offset = step for the weighted case, the k-th quantile is the first element whose cumulative weight exceeds k * total_weight / (num_quantiles - 1). That gives [0, 25, 50, 75, 100] for every scale above and the documented docstring output, and the existing tests in stats_test.py still pass. I have a PR ready.
Issue Priority
Priority: 2 (default / most bugs should be filed as P2)
Activity