Skip to main content

entrenar/quant/calibration/
helpers.rs

1//! Helper functions for calibration
2//!
3//! Contains utility functions used by the calibration module.
4
5use super::calibrator::Calibrator;
6use super::types::CalibrationResult;
7
8/// Simple deterministic pseudo-random for reservoir sampling
9pub(crate) fn rand_simple(seed: usize) -> usize {
10    // Simple LCG-based PRNG
11    let a: usize = 1103515245;
12    let c: usize = 12345;
13    let m: usize = 1 << 31;
14    (a.wrapping_mul(seed).wrapping_add(c)) % m
15}
16
17/// Convenience function for min-max calibration
18pub fn calibrate_min_max(data: &[f32], bits: usize, symmetric: bool) -> CalibrationResult {
19    let mut calibrator = Calibrator::min_max(bits, symmetric);
20    calibrator.observe(data);
21    calibrator.compute()
22}
23
24/// Convenience function for percentile calibration
25pub fn calibrate_percentile(
26    data: &[f32],
27    bits: usize,
28    symmetric: bool,
29    lower: f32,
30    upper: f32,
31) -> CalibrationResult {
32    let mut calibrator = Calibrator::percentile(bits, symmetric, lower, upper, data.len());
33    calibrator.observe(data);
34    calibrator.compute()
35}