Repository navigation
Separate frequency-count and relative-weight quantile APIs - #391
Merged
Merged
Conversation
Add frequencyQuantile for observations paired with occurrence counts. It defaults to type 7 and also supports type 8. Both use the ranks of the represented sample without expanding it. For values [0, 10] and counts [1, 3], the type 7 first quartile is 7.5, as for [0, 10, 10, 10]. Provide sort-first, assume-sorted, and caller-storage variants, along with frequency median, interquartile range, and median absolute deviation. Cover scalar and batch results, sorted observation/count pairs, and the GC, reference-counted, and custom allocation paths. AI-Assisted-By: Codex (GPT-6.2 Astra Medium)
Add frequencyQuantileTable, frequencyQuantileTableSortFirst, and frequencyQuantileTableByPartition for repeated queries over counts. Expose distinct table types for counts and relative weights across the GC, reference-counted, and custom allocator factories. Separate the partition query calculations. A frequency query locates a rank in the represented sample and finds the next rank when interpolation requires it. A relative query locates a cumulative-mass boundary and finds its successor for averaged inverse CDF. Both reuse the same partition search and cache. AI-Assisted-By: Codex (GPT-6.2 Astra Medium)
Select the meaning of the weights by function name. Callers using weightedQuantile!(WeightInterpretation.frequency) switch to frequencyQuantile. Callers explicitly passing WeightInterpretation.relative drop that argument. Existing calls to weightedQuantile without a selector keep their relative-weight behavior. Apply the same change to sorted queries, caller storage, tables, and summary statistics. Update histogram factories to call the appropriate quantile family while preserving their public interpretation option. Migrate the benchmark and examples, test that the old quantile calls are rejected, and document how to choose between the two families. AI-Assisted-By: Codex (GPT-6.2 Astra Medium)
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
A weight of 3 can mean that an observation occurred three times, or that one observation carries three times the relative weight of another. Those meanings can produce different quantiles even when all weights are integers. This PR makes the choice visible in the function name.
frequencyQuantiletreats the rows as the sample[0, 10, 10, 10]and computes its type 7 first quartile without expanding the counts.weightedQuantileuses the inverse CDF by default. The observation0carries one quarter of the total mass, so it is the first value to reach the requested probability.Migration
This is a breaking change for quantile calls that explicitly pass
WeightInterpretation.weightedQuantile!(WeightInterpretation.frequency)(x, counts, p)frequencyQuantile(x, counts, p)weightedQuantile!(WeightInterpretation.frequency, WeightedQuantileAlgo.type8)(x, counts, p)frequencyQuantile!(WeightedQuantileAlgo.type8)(x, counts, p)weightedQuantile!(WeightInterpretation.relative)(x, weights, p)weightedQuantile(x, weights, p)weightedQuantileTableByPartition!(WeightInterpretation.frequency)(x, counts)frequencyQuantileTableByPartition(x, counts)Existing
weightedQuantile(x, weights, p)calls keep their relative-weight behavior. Histogram factories and other statistics that acceptWeightInterpretationcontinue to expose that option.Scope
The first commit adds the frequency family for scalar and batch quantiles, median, interquartile range, and median absolute deviation. It covers sort-first and assume-sorted calls, caller-provided storage, and GC, reference-counted, and custom allocation.
The second commit adds frequency table factories and separates the two partition queries. A frequency query locates a rank in the represented sample. A relative-weight query locates a cumulative-mass boundary. Both reuse the same partition search and cache.
The third commit removes the quantile selector and migrates callers, tests, benchmarks, and documentation. The sorted and partitioned tables have concrete public types so generic callers can infer their template arguments from factory results.
Validation
On Windows, the final tree passed the focused DMD 2.114.0 DIP1000 run across 49 modules. An external caller that relies on table type inference compiled and ran with DMD 2.114.0 and LDC 1.43.0. Ddoc passed with warnings treated as errors, and the generated documentation contains method anchors for all four public table types.
The full LDC DIP1000 suite passed 113 modules before the final review fixes. The benchmark runner also checked its results for frequency counts, integer relative weights, and fractional relative weights.
AI-Assisted-By: Codex (GPT-6.2 Astra Medium)