pub fn train_quantizer(residuals: &[f32], nbits: u32) -> (Vec<f32>, Vec<f32>)Expand description
Learn bucket cutoffs and reconstruction weights from a sample of residual values.
The returned tuple is (bucket_cutoffs, bucket_weights) with
2^nbits - 1 cutoffs and 2^nbits weights, ready to plug into a
ResidualCodec. Buckets are equal-quantile slices of the input:
cutoffs are picked at i / (2^nbits) quantile positions, and each
weight is the arithmetic mean of the residuals falling into that
bucket. This matches fast-plaid’s “fit” step and keeps the codec
unbiased on the training distribution.
residuals does not need to be sorted; this function sorts a
locally-owned copy. NaN values are rejected up front since they
would poison the sort order.
§Panics
Panics if residuals is empty, if nbits is zero or exceeds 8, or
if residuals contains NaN.