Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion design/quantile-selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,10 @@ quantiles, inverse-CDF queries, and Harrell-Davis calculations are unchanged.

## Choosing a weighted quantile query API

Use a scalar call for one probability and a batch when the full set of probabilities is known. For separately arriving queries over the same data, the weighted table prepares sorted rows and cumulative weights once. See the [runnable weighted quantile comparison](../benchmarks/weighted-quantiles/README.md) for preparation and query costs across workloads.
Use a scalar call for one probability and a batch when the full set of probabilities is known. For separately arriving queries over the same data, the weighted table prepares sorted rows and cumulative weights once. The explicit `weightedQuantileTableSortFirst`, `rcWeightedQuantileTableSortFirst`, and `makeWeightedQuantileTableSortFirst` factories perform this same preparation and return the same table type as their unsuffixed counterparts. See the [runnable weighted quantile comparison](../benchmarks/weighted-quantiles/README.md) for preparation and query costs across workloads.

The explicit `weightedQuantileTableByPartition!frequency` family copies positive-count rows and retains up to 64 partitions shared by copies of the table. The GC, RC and custom factories allocate rows at construction. A single positive-count row needs no cache. Larger tables reserve one node per positive-count row up to the 64-node limit. Once the cache fills, further queries partition unresolved row intervals without saving additional nodes. Type 7 and type 8 select the requested ranks from raw counts. When interpolation within a tied value would round differently from conversion, a second partition by count within that group identifies boundaries between rows in their sorted count order. When a zero pivot groups both signs of zero, a partition by raw count resolves their sorted rank order. Zero observations with the same positive count must have the same sign because sorted preparation can permute those rows. Zero-count rows are ignored.

For relative weights, `tryWeightedQuantileTableByPartition`, `tryRcWeightedQuantileTableByPartition`, and `tryMakeWeightedQuantileTableByPartition` return a nullable table. The validation traversal expresses the positive weights as integers on a common power-of-two grid. The integer total must fit in the smaller of the `real` significand and 64 bits. This makes every partial mass exact regardless of partition order. Positive-weight observations containing both signs of zero also decline. A single positive-weight row always qualifies. A decline allocates no storage; the caller can choose `SortFirst` for ordered accumulation. Eligibility can depend on the target precision of `real`.

On success the copy uses the same power-of-two normalization as sorted inverse CDF. The table shares the bounded node cache and ownership policy used for frequencies. Each pivot stores normalized mass before and through the equal-value group. Queries compare probabilities with those cumulative masses divided by total mass. At an exact interior group boundary, averaged inverse CDF locates the successor using the next representable probability and applies the sorted evaluator's midpoint interpolation.
10 changes: 10 additions & 0 deletions source/mir/stat/descriptive/univariate/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,20 @@ $(TR $(TH Module) $(TH Public declarations))
$(REF weightedQuantileSortFirstInto, mir, stat, descriptive, univariate, quantiles)$(NBSP)
$(REF weightedQuantileAssumeSortedInto, mir, stat, descriptive, univariate, quantiles)$(NBSP)
$(REF weightedQuantileScratchLength, mir, stat, descriptive, univariate, quantiles)$(NBSP)
$(REF PartitionedWeightedQuantileTable, mir, stat, descriptive, univariate, quantiles)$(NBSP)
$(REF WeightedQuantileTable, mir, stat, descriptive, univariate, quantiles)$(NBSP)
$(REF weightedQuantileTable, mir, stat, descriptive, univariate, quantiles)$(NBSP)
$(REF weightedQuantileTableSortFirst, mir, stat, descriptive, univariate, quantiles)$(NBSP)
$(REF weightedQuantileTableByPartition, mir, stat, descriptive, univariate, quantiles)$(NBSP)
$(REF tryWeightedQuantileTableByPartition, mir, stat, descriptive, univariate, quantiles)$(NBSP)
$(REF rcWeightedQuantileTable, mir, stat, descriptive, univariate, quantiles)$(NBSP)
$(REF rcWeightedQuantileTableSortFirst, mir, stat, descriptive, univariate, quantiles)$(NBSP)
$(REF rcWeightedQuantileTableByPartition, mir, stat, descriptive, univariate, quantiles)$(NBSP)
$(REF tryRcWeightedQuantileTableByPartition, mir, stat, descriptive, univariate, quantiles)$(NBSP)
$(REF makeWeightedQuantileTable, mir, stat, descriptive, univariate, quantiles)$(NBSP)
$(REF makeWeightedQuantileTableSortFirst, mir, stat, descriptive, univariate, quantiles)$(NBSP)
$(REF makeWeightedQuantileTableByPartition, mir, stat, descriptive, univariate, quantiles)$(NBSP)
$(REF tryMakeWeightedQuantileTableByPartition, mir, stat, descriptive, univariate, quantiles)$(NBSP)
$(BR)
$(B Spread:)
$(REF weightedInterquartileRange, mir, stat, descriptive, univariate, quantiles)$(NBSP)
Expand Down
Loading
Loading