Skip to main content

fragility

fragility

selection_fragility.fragility — the decision breakdown point (k*) and ranking-fragility diagnostics.

The question it answers: on a pooled accuracy metric, how FEW evaluation periods must you delete before the “best model” changes? A low number means the pooled verdict rests on a handful of periods (e.g. one shock) and is fragile — don’t trust it. A high number means the ranking is robust.

Lineage: this repurposes the breakdown-point idea (Hampel; Donoho & Huber) and the clinical-trials Fragility Index (Walsh et al. 2014, J. Clin. Epidemiol. — the minimum number of outcomes to flip statistical significance) to a model-selection decision on a WEIGHTED PANEL of per-period losses. It complements the Model Confidence Set (which models are statistically tied) by quantifying how trustworthy the ranking itself is to a few influential periods.

Design: k* is defined on the FIXED-WEIGHT ADDITIVE loss-differential margin, so deleting periods is exactly additive and the greedy algorithm is provably optimal (and O(T log T)). Inputs are the per-period, cross-sectionally-aggregated scaled losses (e.g. per-year MASE) plus per-period weights (e.g. observation counts).

NOTE ON WEIGHTS. w supports non-uniform per-period weighting (e.g. observation counts), and the greedy is exact for ANY fixed weights. The weighting choice can change both the pooled winner and k* on some panels, so weight sensitivity is worth checking rather than assumed away.

Functions

Name Description
breakdown_number k* for a PAIR: the minimum number of periods to DELETE to flip ‘a beats b’ on the pooled metric, where a is the
condorcet_status Classify the pairwise-majority tournament among the models:
condorcet_winner The CONDORCET winner: the model that beats every other model in pairwise per-period majority (lower loss more
decision_breakdown DECISION-LEVEL k*: the fewest periods whose deletion makes the pooled winner a lose to ANY opponent
exchangeable_benchmark The distribution of winner_stability when the winner is ARBITRARY BY CONSTRUCTION.
fragility Full ranking-fragility diagnostic for a selection decision.
per_period_winner The robust winner: the model that wins the MOST periods (majority vote over per-period lowest loss).
pooled_winner Model with the lowest weighted-mean loss (the pooled ‘best’). L: {model: array(T)}; w: array(T). Lower=better.
surprise_concentration How concentrated is the IRREDUCIBLE forecast difficulty across periods? This is the DATA-side driver of ranking
winner_stability Block-bootstrap the evaluation PERIODS and recompute the pooled winner on each resample -> the distribution of

breakdown_number

fragility.breakdown_number(la, lb, w)

k* for a PAIR: the minimum number of periods to DELETE to flip ‘a beats b’ on the pooled metric, where a is the current pooled winner of the pair. Margin contributions c_t = w_t * (lb_t - la_t) (>0 means period t favors a; net margin M = sum(c_t) > 0 iff a beats b pooled). Deleting set S gives M_S = M - sum_{t in S} c_t. To make M_S <= 0 with the fewest deletions, remove the largest positive c_t first (greedy) – EXACT because the margin is additive in fixed weights. Returns (k*, responsible_period_indices). If a does not beat b pooled, returns (0, []).

ASYMMETRY, NOT A BUG. responsible_period_ indices names periods propping up A’s (the CURRENT winner’s) margin – the largest w_t*(lb_t-la_t) contributions – never periods where B unusually outperforms A. A real disruption that TEMPORARILY favors the challenger (e.g. a platform regression that briefly helps a losing variant) is therefore nearly invisible here even though something genuinely anomalous happened: verified directly on a 13-period disruption window, 11/13 disrupted periods were named when the disruption reinforced the champion’s lead, but only 1/13 when it inverted (favored the challenger instead). This is the mathematically correct answer to “which periods would need to disappear to flip the CURRENT winner” – it is not an answer to “which periods look anomalous” in general, and a reader should not read PIVOT’s silence during an inverting disruption as “nothing happened.”

DEGENERATE-MARGIN FLOOR. An EXACT pooled tie (mean_a == mean_b) must give k=0 – there is no strict winner to break down. But summing T individually-rounded float64 differences does not reliably land on exactly 0.0 even when the true means are equal (verified: exact_tie_panel’s means agree exactly in Decimal arithmetic, but the naive float64 M came out ~1e-16, a positive residual). The greedy loop below would then remove the single largest c_t – often orders of magnitude bigger than the residual – and report k=1 on data that is an exact tie, i.e. M > 0 in floating point is picking up rounding noise, not a genuine margin. Same relative-floor discipline as mcs.py’s _SE_REL_FLOOR and this module’s own _MARGIN_REL_FLOOR (used downstream in fragility()’s degenerate-margin guard) – applied HERE, at the source, so k* itself is correct rather than merely flagged wrong after the fact.

TIE-BREAK for equal-value margin contributions. np.argsort(c) does not guarantee stability for equal values (default kind=‘quicksort’), and a bare [::-1] then reverses the WHOLE result – so two periods with the EXACT same margin contribution could be named/removed in an order that is an accidental byproduct of the sort algorithm, undisclosed and not necessarily even stable across numpy versions, rather than a deliberate convention. k* (the removal COUNT) is unaffected – deleting either member of a tied pair removes the same amount – but WHICH periods land in removed_period_indices is not. np.argsort(-c, kind='stable') gives an identical result whenever no two contributions tie exactly, and for a genuine tie deterministically prefers the EARLIER period (ascending original index) – stated and reproducible rather than an artifact of an unstable sort’s internal behavior.

condorcet_status

fragility.condorcet_status(L)

Classify the pairwise-majority tournament among the models: ‘winner’ – a Condorcet winner exists (one model strictly beats every other in per-period majority); ‘cycle’ – NO Condorcet winner AND the strict-beats digraph contains a directed cycle of ANY length (a1>a2>…>ak>a1) – a genuine intransitive majority cycle; ‘tie’ – NO Condorcet winner and NO directed cycle (the absence is driven by pairwise majority TIES, not intransitivity). ‘cycle’ and ‘tie’ are BOTH ‘no Condorcet winner’, but only ‘cycle’ is the severe intransitive disagreement. Cycles are detected at ANY length via a topological-sort (Kahn) test on the strict-beats digraph: a 3-permutation search misses longer cycles – e.g. a genuine 4-cycle with no 3-cycle, which can occur when some pairs are TIED (ties make the tournament incomplete, so ‘no winner’ no longer implies a 3-cycle exists). ‘x beats y’ iff x has strictly more per-period wins than y (same strict relation as condorcet_winner).

Accepts a LossPanel directly (see per_period_winner’s docstring).

condorcet_winner

fragility.condorcet_winner(L)

The CONDORCET winner: the model that beats every other model in pairwise per-period majority (lower loss more often than not). Completes the three canonical voting rules {score=pooled, plurality=per_period, Condorcet}. Returns the model name, or None if no Condorcet winner exists (a majority cycle or a pairwise tie). L: {model: array(T)}.

Accepts a LossPanel directly (see per_period_winner’s docstring).

decision_breakdown

fragility.decision_breakdown(L, w=None, a=None, return_ties=False)

DECISION-LEVEL k: the fewest periods whose deletion makes the pooled winner a lose to ANY opponent (not just the pooled runner-up). k = min over opponents m of the pairwise breakdown_number(a, m); greedy is exact per pair, so the min over pairs is exact for the decision. k* is a descriptive diagnostic – a deletion count, not a hypothesis test – and applies no multiple-comparisons correction to the minimum taken over the K-1 opponents.

Returns (k, binding_opponent, removed_idx), or with return_ties=True (k, binding_opponent, removed_idx, all_binding_opponents).

NOT THE SAME MODEL AS resolution.py’s “binding_rival”. binding_opponent here is picked by the FEWEST-DELETIONS criterion (the opponent whose pairwise breakdown_number against the champion is smallest); resolution.py’s _binding_rival (feeding minimum_detectable_edge/ significance_boundary/mcb_bound/resolution_report’s own binding_rival field) is picked by a DIFFERENT criterion – whichever rival’s pooled mean is closest to the champion’s. These answer different questions (which opponent is cheapest to flip to, vs. which rival is statistically closest) and can name different models on the same panel – a measured 18.25% disagreement rate across 20,000 random panels. report()’s PIVOT section (k*/concentration) reflects THIS opponent; its RESOLUTION section reflects resolution.py’s rival. The near-identical names are a known source of possible confusion, not an error – read the field name in context, not just “binding X”.

TIE-BREAK. k* is a minimum and is unambiguous, but SEVERAL opponents can attain it, and they disagree about the derived quantities – removed, the pivotal period, and above all concentration, which is computed against whichever opponent is named. This previously resolved by dict insertion order, i.e. silently. It now resolves by sorted model name: still arbitrary, but deterministic and stated. Use return_ties=True to recover the full tied set and report a range, which is what an honest write-up should do when more than one opponent ties.

exchangeable_benchmark

fragility.exchangeable_benchmark(
    K,
    T,
    n_rep=200,
    n_boot=500,
    block=None,
    seed=0,
    circular=True,
)

The distribution of winner_stability when the winner is ARBITRARY BY CONSTRUCTION.

K models drawn from one identical distribution, so no model is better and any winner is an artifact of the draw. Returns (median, p05, p95) of the statistic over n_rep such panels.

This exists because winner_stability was being read against 1/K – “0.50 is a coin flip” – which is wrong for K > 2: the statistic does not go to 1/K under the null, it goes to roughly 0.52 at K=6, T=30. A threshold or a median is only interpretable against this benchmark, and the benchmark is cheap enough to compute that asserting one instead is indefensible.

ASSUMPTION (i.i.d. null): the simulated null panels are drawn independently across periods. Under positive autocorrelation – the normal case for forecast-loss series – the true null winner_stability distribution shifts UPWARD (e.g. at AR(1)=0.8 the null p05 is ~0.51 vs the i.i.d. ~0.42), so comparing an observed stability against this i.i.d. benchmark’s p05 will UNDER-detect fragility on a persistent panel (it calls a genuinely-fragile winner “not fragile”). Treat a “not fragile relative to this benchmark” verdict with caution when your loss differentials are autocorrelated; check their ACF, or build a null matching your panel’s own serial dependence.

fragility

fragility.fragility(
    L,
    w=None,
    shock_periods=None,
    labels=None,
    n_boot=2000,
    seed=0,
    *,
    stability_block=None,
    benchmark=None,
)

Full ranking-fragility diagnostic for a selection decision.

Parameters

Name Type Description Default
L dict {model_name: array(T)} per-period loss for each model (lower is better). required
w array(T) or None per-period weights (e.g. observation counts). Defaults to equal weights. None
shock_periods iterable or None labels of known shock periods; if given, shock_coincidence reports whether the k* responsible periods are all known shocks. None
labels iterable(T) or None period labels (e.g. years); used to report the responsible periods by name. None
n_boot block-bootstrap settings for winner_stability. 2000
seed block-bootstrap settings for winner_stability. 2000
Returns required
concentration required
reversal_condorcet required
condorcet_status required
responsible required

Notes

  • k_star == 0 means the pooled winner does NOT strictly beat some opponent (a tie / no strict winner). It is NOT “maximally fragile” – it signals no strict winner exists; read the Model Confidence Set for identification.
  • TWO DIFFERENT FIELDS, not to be conflated. screen is the uncalibrated convenience flag: True if the margin is degenerate, OR winner_stability < 0.60, OR k_star/T < 0.25. That 0.60 cut is NOT calibrated – under exchangeable_benchmark() (no true skill difference at all) the null median is about 0.50 at K=6/T=32, so it flags much of a pure-null panel. fragile is the CALIBRATED verdict and is None – unknown – unless you pass benchmark=, because fragility relative to chance cannot be decided without the null at your own (K, T). Note that an exact tie is a degenerate margin and returns fragile=True, and without a benchmark the answer is None rather than False. Read fragile together with the MCS: it does not by itself capture non-identification.
  • concentration is np.nan when there is no strict winner (k_star == 0); a value > 1 means one period’s margin exceeds the champion’s whole net margin.
  • stability_block sets the winner_stability bootstrap block length (default T**(1/3)); set it to reflect the serial dependence of your losses (e.g. ~12 for monthly data).

per_period_winner

fragility.per_period_winner(L, return_ties=False)

The robust winner: the model that wins the MOST periods (majority vote over per-period lowest loss). In social-choice terms this is the PLURALITY winner over periods-as-voters (the pooled winner is the SCORE/range winner). Their disagreement is the classic score-vs-plurality reversal.

STRICT WINS ONLY. A period counts toward a model’s total only if that model’s loss is the UNIQUE minimum that period; a tied period counts toward nobody. Using M.argmin(axis=0) instead would, on a tie, silently resolve to the LOWEST SORTED-NAME INDEX – so a period where two models tie would be counted as a WIN for whichever model happened to sort first, fabricating a “plurality winner” (and a spurious pooled-vs-plurality reversal) out of pure name order. Confirmed on dominance_panel (b weakly dominates a – never worse, strictly better once – the naive code awarded the 2 tied periods to ‘a’ and called ‘a’ the plurality winner) and on a byte-identical triple (should report a genuine 3-way tie; the naive code picked a unique “winner” by sorted name). Both are regression-tested and rename-invariant (tests/test_stage3_kstar_prop22.py).

TIE-BREAK for the reported POINT winner among several models tied for the most strict wins: name-sorted, deterministic, independent of dict insertion order – but this only selects which name is reported as tied[0], never fabricates a win out of a tie. Pass return_ties=True to get (winner, all_tied) and report the honest range.

Accepts a LossPanel directly, matching pooled_winner/decision_breakdown/winner_stability. This and its two “Core API” siblings below, condorcet_winner/condorcet_status, accept a LossPanel for consistency with the other functions in the same README “Core API” group.

pooled_winner

fragility.pooled_winner(L, w=None)

Model with the lowest weighted-mean loss (the pooled ‘best’). L: {model: array(T)}; w: array(T). Lower=better.

surprise_concentration

fragility.surprise_concentration(L, labels=None)

How concentrated is the IRREDUCIBLE forecast difficulty across periods? This is the DATA-side driver of ranking fragility, and it distinguishes the two fragility flavors (shock-concentration vs near-tie noise).

NOTE – do not confuse this function’s sci with fragility()’s concentration field. sci is a property of the DATA (how lopsided task difficulty is across periods, independent of any winner); concentration in fragility() is a property of the DECISION (the champion’s margin concentrated in one period). A series can score high on one and low on the other.

Per period t: difficulty d_t = min_m loss_{m,t} (the best ANY model achieved -> the surprise no model escaped; strips model-specific incompetence, isolates TASK difficulty). Normal difficulty b = median_t d_t (a robust, shock-label-free baseline). Excess surprise s_t = max(0, d_t - b). Returns: sci = max(s)/sum(s) in [0,1] – share of all excess surprise in the SINGLE hardest period eff_surprising_periods = (sum s)^2 / sum(s^2) – effective number of surprising periods (participation ratio) hardest = label of argmax d_t – WHICH period is the surprise d_max_over_median = max(d)/b – how many times normal the hardest period was; NaN if b and max(d) have opposite signs (the ratio is then undefined – reachable with negative losses, e.g. log/skill scores) Reading: high sci + fragile ranking = SHOCK-driven inversion; low sci + fragile = NEAR-TIE leaderboard noise.

Accepts a LossPanel directly, like per_period_winner/condorcet_winner/condorcet_status above.

winner_stability

fragility.winner_stability(
    L,
    w=None,
    n_boot=2000,
    block=None,
    seed=0,
    circular=True,
)

Block-bootstrap the evaluation PERIODS and recompute the pooled winner on each resample -> the distribution of ‘who wins’. Returns (stability, freq): stability = fraction of resamples whose pooled winner equals the observed pooled winner; freq = {model: win share}.

THIS STATISTIC IS NOT INTERPRETABLE ON ITS OWN. Read it against exchangeable_benchmark(K, T), which returns (median, p05, p95) of this same statistic on panels where NO model is better and the winner is arbitrary by construction. It does NOT go to 1/K under that null – at K=6, T=32 the null median is about 0.51 and the 5th percentile about 0.31, so a value in the 0.4-0.6 range is what CHANCE produces, not evidence of fragility. A result is unusually fragile RELATIVE TO CHANCE only if it falls below the benchmark’s 5th percentile.

It is the bootstrap companion to k* (a one-axis, period-resampling view of the winner’s sampling variability), calibrated only when paired with exchangeable_benchmark().