Function conditional_tail_percentile
pub fn conditional_tail_percentile(
art: &CalibrationArtifact,
language: &str,
metric: &str,
value: f64,
) -> Option<f64>Expand description
Percentile of value within the corpus’s non-trivial tail for
(language, metric) — the conditional lookup the anchored hotspot score
uses in place of percentile.
The plain percentile compares against the whole pool, which for a
complexity metric is dominated by trivial functions — the corpus median
cognitive is 0 — so every real file saturates the top percentiles and the
anchored score stops discriminating. This conditions the comparison on the
functions that carry any decision structure (metric value above
[TRIVIALITY_THRESHOLD]), re-spreading the informative upper tail across
[0, 1]:
p0 = corpus fraction of the pool at value <= 0 (the trivial share)
cp_tail = clamp((cp - p0) / (1 - p0), 0, 1) for value above 0
= 0 for value <= 0where cp is the plain percentile. p0 is read straight off the stored
breakpoints by [trivial_share] as the highest index still holding a
trivial value — the percentile the lookup itself assigns to the top of the
zero plateau — so a value just above the plateau maps to cp_tail ≈ 0 and
the corpus maximum to cp_tail = 1. It is pure arithmetic on breakpoints
every artifact already carries: no format change, no corpus rebuild.
Returns None under the same conditions as percentile (unknown
language / metric, or the language pooled below MIN_LANG_SAMPLE) and
when the pool is entirely trivial (p0 == 1, an empty tail with no
informative content) — an honest omission, never a fabricated value,
matching the no-anchor path the caller already handles.