/** * router-calibrator.ts — Post-hoc isotonic calibration for the KRR router * (ADR-149 iter 22). * * The bundled KRR systematically under-predicts at the low end (gap 0.45 at * 0.0–0.1) and over-predicts at the high end (gap 0.15 at 0.9–1.0). Both * deviations are monotone, so a piecewise-constant non-decreasing function * fit via Pool-Adjacent-Violators (PAV) can correct them without retraining * the KRR. * * USAGE * * const cal = IsotonicCalibrator.fit([[0.07, 0.52], [0.55, 0.60], …]); * const corrected = cal.transform(rawKrrScore); * * // Persist & reload: * writeFileSync(path, JSON.stringify(cal.toJSON())); * const loaded = IsotonicCalibrator.fromJSON(JSON.parse(readFileSync(path, 'utf8'))); * * Pure TS — no native deps. ~25 lines of fitting logic, O(n log n) sort + * O(n) PAV pass. * * @module router-calibrator */ export interface CalibratorBucket { /** Inclusive lower bound of predicted-values pooled into this bucket. */ predMin: number; /** Inclusive upper bound. */ predMax: number; /** Calibrated output value (mean of observed values in the pool). */ calibrated: number; /** Number of (pred,obs) pairs pooled. */ count: number; } export interface CalibratorJSON { v: 1; buckets: CalibratorBucket[]; } export declare class IsotonicCalibrator { private buckets; private constructor(); /** * Fit an isotonic regression to (predicted, observed) pairs via PAV. * * Result is a non-decreasing piecewise-constant function over the * empirical predicted-value range, equivalent in spirit to sklearn's * IsotonicRegression(increasing=True, out_of_bounds='clip'). */ static fit(pairs: Array<[number, number]>): IsotonicCalibrator; /** * Map a raw predicted value to its calibrated value. Uses piecewise-linear * interpolation between adjacent bucket midpoints, clamped at the * empirical edges (extrapolation outside the training range returns the * nearest edge bucket's calibrated value). */ transform(x: number): number; /** Pure-JSON serialization — calibrator JSON is small (typically <2kB). */ toJSON(): CalibratorJSON; static fromJSON(j: CalibratorJSON): IsotonicCalibrator; /** Diagnostic — number of distinct calibration points after PAV. */ get bucketCount(): number; /** Diagnostic — return a copy of the bucket array (read-only view). */ inspect(): CalibratorBucket[]; } //# sourceMappingURL=router-calibrator.d.ts.map