Skip to content

feat(conformal): add finite-sample corrected error intervals - #92

Merged
AzulGarza merged 6 commits into
TimeCopilot:mainfrom
viventriglia:feat/conformal-finite-sample
Nov 11, 2026
Merged

AzulGarza merged 6 commits into
TimeCopilot:mainfrom
viventriglia:feat/conformal-finite-sample

Conversation

@viventriglia

Copy link
Copy Markdown
Contributor

Adds opt-in conformal_error_finite_sample intervals using the exact
ceil((n + 1) * level / 100)-th absolute-error order statistic, without
interpolation. When the rank exceeds the calibration sample size,
bounds are infinite. Existing methods and defaults are unchanged.

Documents the exchangeability assumption and adds an executed M4 Hourly
rolling-origin comparison reporting coverage, width, and finite intervals.

Refs #89. This PR covers finite-sample correction; ACI and persistent
online state remain separate follow-up work.

Validation:

  • 237 core/API tests passed, 1 skipped; weight-dependent cases excluded.
  • 3 real Chronos checkpoint cases passed.
  • 3 conformal documentation tests passed.
  • Conformal module coverage: 99%.
  • Full pre-commit checks and strict documentation build passed.
  • New contract test parametrized over every registered model.

@CLAassistant

CLAassistant commented Nov 6, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@AzulGarza
AzulGarza self-requested a review November 9, 2026 20:17

@AzulGarza AzulGarza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @viventriglia, thanks for this. the exact ceil((W+1)·level/100) rank with the inf sentinel is right, the tests are really thorough (the leave-one-out rank coverage one is great), and i like that the docs don't oversell exchangeability on rolling windows. also thanks for fixing the stale "must pass level or quantiles" line.

the main thing: infinite bounds are silent. with n_windows=2 (or anything under what the level needs) forecast() returns ±inf and nothing tells the user. the notebook shows it (coverage 1.0, width inf), and inf breaks plotting and anything that scores intervals. i would not rely on the docs alone here.

could we emit a UserWarning at forecast time when any requested level has rank > W? something like "level 95 needs at least 19 calibration windows, got 4; bounds are infinite". it can't live in ConformalIntervals.__post_init__ since level is not known there, so add_conformal_error_intervals (or the forecaster, right before calling the method) is the natural spot. keep the behavior itself as is, inf is the correct answer, it should just not be a surprise.

for the notebook: the 19-window rows show it working, but as a metrics table. i would add a short cell before the coverage check with a plain forecast(h=24, level=[80, 95]) using n_windows=19 on one M4 Hourly series, plotted with the finite bounds, so the reader first sees the method producing usable intervals and then sees what happens when there are too few windows.

smaller things:

  • max(1, ...) clamp. a comment saying level 0 is only reachable through odd quantile conversions would help, since rank 1 is not a zero width interval.
  • notebook wording. "corrected ranks give intervals at least as wide as the uncorrected" holds for levels ≥ 50. below that it can be narrower (your own test at level 20 shows it). fine for 80 and 95, but i would scope the sentence.
  • cost note in the docs. 95% needs 19 windows, so each forecast() runs about 20 forecasts per model, and history must be at least h + 18 * step_size + 1 observations (456+ at h=24). you mention the history part, a line on compute would help.
  • README. the highlight bullet became a paragraph. i would keep one sentence and link to the guide for the details.

CI has not run yet because it is a fork PR, i will approve the workflows so we get the full matrix.

wdyt?

@viventriglia

Copy link
Copy Markdown
Contributor Author

Thanks @AzulGarza, agreed, and addressed all points. Infinite bounds now emit a UserWarning with the required window counts, and the notebook includes a finite 19-window forecast and plot before the coverage check. I also clarified the clamp and width wording, added the compute/history cost, and shortened the README. Local tests, lint and docs checks pass!

@AzulGarza AzulGarza left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @viventriglia, thanks for the quick turnaround, this looks great now. approving, i'll merge once CI is green. thanks again for the contribution!:)

@codspeed

codspeed Bot commented Nov 11, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 note

ℹ️ 13 benchmarks have no flamegraph

The flamegraph wasn't generated: the symbols of the profiling trace could not be resolved, because no information about the language frames was collected.

See affected benchmarks

✅ 17 untouched benchmarks


Comparing viventriglia:feat/conformal-finite-sample (657b101) with main (c32ad5d)

Open in CodSpeed

@viventriglia

Copy link
Copy Markdown
Contributor Author

Thanks for enabling CI, @AzulGarza! Python 3.10/3.11, lint, docs and CodSpeed passed, while 3.12/3.13 and both replication jobs failed. Could the replication failures be related to secrets being unavailable to fork PRs?

@AzulGarza

Copy link
Copy Markdown
Member

yes, @viventriglia! that's the reason, meging it now;) thanks!

@AzulGarza
AzulGarza merged commit cd67b60 into TimeCopilot:main Nov 11, 2026
9 of 13 checks passed
@viventriglia
viventriglia deleted the feat/conformal-finite-sample branch November 19, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants