Skip to main content

Module conformal

Module conformal 

Source
Expand description

Conformal nonconformity scores and prediction sets.

Split-conformal usage: compute a nonconformity score per calibration observation, take the finite-sample-corrected quantile (conformal_quantile) at the target miscoverage α, and construct prediction sets on new observations from the same score. All scores are deterministic (no randomized tie-breaking), which makes them slightly conservative and fully reproducible.

  • Nominal (noul/choice): aps_nonconformity / aps_set (Romano et al. 2020) and raps_nonconformity / raps_set (Angelopoulos et al. 2021).
  • Ordinal (score): probability-sorted sets are order-blind and can be non-contiguous over an ordered scale, which is semantically broken for a score (S6b2). This module provides the ordinal alternatives MAPIE does not ship:
    • rps_nonconformity / ordinal_set_rps — RPS-based nonconformity; sets are median-centered contiguous intervals by construction (Haas et al. 2026, arXiv:2606.24959);
    • ordinal_aps_interval — contiguous interval grown around the mode (Ordinal APS; Lu, Angelopoulos, Pomerantz 2022, arXiv:2207.02238);
    • min_cps_nonconformity / min_cps_interval — minimum-length contiguous sliding-window sets (min-CPS style; Zhang et al. 2025, arXiv:2511.16845).

Ordinal sets are returned as inclusive index intervals (lo, hi) over levels and are always contiguous; any score-defined label set is returned as its contiguous hull.

Functions§

aps_nonconformity
APS nonconformity: cumulative probability mass, in descending-probability order, up to and including the realized label. Deterministic (the full label mass is included), hence slightly conservative vs the randomized form.
aps_set
APS prediction set: labels in descending-probability order until the cumulative mass reaches qhat; the crossing label is included.
check_distribution
Validate that a distribution is usable for conformal scoring.
conformal_quantile
Finite-sample-corrected split-conformal quantile of calibration nonconformity scores: the ⌈(n+1)(1−α)⌉-th smallest score. Returns f64::INFINITY when the rank exceeds n (the prediction set is then “everything” — the guarantee is uninformative at requested α for this calibration size).
min_cps_interval
min-CPS prediction interval: the contiguous hull of {k : min_cps_nonconformity(p, k) ≤ qhat} — the minimum-length contiguous set with the calibrated coverage guarantee.
min_cps_nonconformity
min-CPS-style nonconformity (Zhang et al. 2025): the smallest mass threshold τ at which the minimum-length contiguous window with mass ≥ τ contains the realized label. Computed by enumerating candidate thresholds (distinct contiguous-window masses); O(K³) worst case, intended for calibration-fitting batches, with the serving-time set constructed by min_cps_interval.
ordinal_aps_interval
Ordinal APS interval (Lu, Angelopoulos, Pomerantz 2022): start at the modal level and grow a contiguous interval, always extending toward the adjacent side with the larger probability, until the enclosed mass reaches qhat.
ordinal_set_rps
RPS-CP prediction interval: the contiguous hull of {k : rps_nonconformity(p, k) ≤ qhat}. (The raw set is already contiguous for unimodal histograms; the hull guarantees the interval contract for multimodal ones.) Falls back to the lowest-nonconformity single level if no level clears qhat.
raps_nonconformity
RAPS nonconformity: APS cumulative mass plus the regularization penalty lambda · max(rank(label) − k_reg, 0) where rank is the 1-based rank in descending-probability order (Angelopoulos et al. 2021). k_reg is the number of penalty-free top ranks.
raps_set
RAPS prediction set: labels in rank order while the penalized cumulative mass stays below qhat; the crossing label is included.
rps_nonconformity
RPS-based ordinal nonconformity: the ranked probability score of the candidate label against the predicted histogram (Haas et al. 2026). Cheap and model-agnostic; the induced sets are median-centered and contiguous by construction.