Online Adaptive Conformal Inference (ACI) & Regime-Shift Tracking¶
flowchart TD
A1["1. Initialize Nominal Coverage & Step Size<br/>target_coverage (1 - alpha) · gamma (aci_gamma) · normalized=True"] --> A2["2. Observe Delayed h-Step Feedback<br/>err_{t,h} = 1{y_t not in [L_{t|t-h}, U_{t|t-h}]} · horizon_delay"]
A2 --> A3["3. Update Effective Miscoverage Rate Online<br/>alpha_{t+1,h} = clip(alpha_{t,h} + gamma * (alpha - err_{t,h}), 0.005, 0.50)"]
A3 --> A4["4. Recalibrate Intervals & Flag Regime Drift<br/>compute_aci_df · update_aci_online · ks_drift_stat · plot_aci"]
aci
¶
Online Adaptive Conformal Inference (ACI & Volatility-Normalized ACI) — pure.
Standard split/out-of-fold conformal prediction intervals assume exchangeability between historical backtest folds and future periods. Under mid-series volatility shocks, price regime shifts, or structural breaks, static conformal intervals can suffer severe miscoverage.
This module implements:
1. Gibbs & Candès (2021) Online Quantile Adaptation ("aci"):
$$\alpha_{t+1} = \text{clip}(\alpha_t + \gamma (\alpha_{\text{target}} - \text{err}t),
\; \epsilon,\; 1 - \epsilon)$$
where $\text{err}_t = \mathbb{I}{y_t \notin [\hat{L}_t, \hat{U}_t]}$.
2. Scale-Normalized / Volatility-Weighted ACI ("aci_normalized"):
Couples online $\alpha_t$ adaptation with an Exponentially Weighted Moving Average (EWMA) local
residual volatility multiplier $s} = \hat{\sigma{i,t} / \hat{\sigma}$
so prediction intervals expand immediately during volatility bursts and contract smoothly when
stability returns.
3. Leak-Free Multi-Step Horizon Feedback Delay ($h$-Step Lag):
For an $h$-step-ahead forecast at index $t$, online state updates $(\alpha_t, s_{i,t})$ depend
strictly on realized errors at indices $\tau \le t - h$ (i.e., available at forecast origin
$t - h + 1$), guaranteeing zero lookahead leakage across multi-step horizons.
AciCalibrationState
dataclass
¶
AciCalibrationState(
method,
target_alpha,
gamma,
terminal_alpha,
empirical_coverage_split,
empirical_coverage_aci,
mean_width_split,
mean_width_aci,
volatility_scale,
drift_detected,
alpha_trajectory,
err_trajectory,
q80_per_step,
q80_flat,
quantile_offsets_per_step,
quantile_offsets_flat,
)
Summary of online ACI state and empirical coverage across an OOF or streaming trajectory.
calibrate_aci_from_oof
¶
calibrate_aci_from_oof(
oof,
*,
method="aci",
gamma=0.05,
target_coverage=0.8,
quantiles=DEFAULT_QUANTILES,
residual_column="yhat_raw",
)
Learn an online ACI-adjusted Calibration and AciCalibrationState from an OOF frame.
Source code in src/scale_forecasting/aci.py
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 | |
compute_aci_df
¶
compute_aci_df(
oof_or_actuals_df,
predictions_df=None,
*,
gamma=0.05,
target_coverage=0.8,
normalized=True,
method=None,
horizon_delay=True,
ts_id_col="ts_id",
date_col="ds",
)
Compute online Adaptive Conformal Inference (ACI) trajectories and coverage diagnostics.
Accepts either:
- An out-of-fold DataFrame containing y_true and yhat (or yhat_raw), or
- Newly arrived actuals oof_or_actuals_df (with y or y_true) paired with
predictions_df (with yhat).
Source code in src/scale_forecasting/aci.py
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | |
plot_aci
¶
Plot static conformal vs. online ACI intervals, rolling coverage, and drift events.