A model is calibrated if a credible interval at nominal mass
α actually contains the truth α-of-the-time across many
trials. Calibration is the most basic sanity check on any
probabilistic prediction; failure usually points to either a bad
prior, an under-dispersed likelihood, or a model–data mismatch.
For a fixed credible mass α and a batch of trials each with truth
x_t* and credible interval [ℓ_t, h_t]::
coverage(α) = (1 / T) Σ_t 𝟙[ x_t* ∈ [ℓ_t, h_t] ]
If the model is calibrated, coverage(α) ≈ α.
The function α → coverage(α) over a sweep of nominal levels. A
calibrated model produces the diagonal; deviations diagnose
over- / under-confidence.
L₁ deviation from the diagonal::
ECE = (1 / L) Σ_ℓ |coverage(α_ℓ) − α_ℓ|
Smaller is better; ECE = 0 means perfect calibration on the
sampled levels.
| Symbol | Signature | Notes |
|---|---|---|
coverage_from_intervals |
(truths, lows, highs) -> float |
Pointwise hit rate; raises on shape mismatch. |
calibration_curve |
(truths, lower_fn, upper_fn, nominal_levels) -> CalibrationCurve |
Sweeps nominal levels; both lower_fn and upper_fn take a level and return a per-trial array. |
CalibrationCurve |
dataclass with nominal, empirical, n_trials, calibration_error() |
|
plot_calibration |
(curve, ...) -> Figure |
Reliability diagram with the in-figure ECE. |
animate_calibration_growth |
(nominal, empirical_history, ...) -> FuncAnimation |
Reliability diagram filling in trial-by-trial. |
coverage_from_intervals, calibration_curve, and CalibrationCurve
live in active_inference.core.diagnostics. The plotting helpers live
in active_inference.visualizations.diagnostics and animations.
tests/core/test_diagnostics.py::TestCalibration::test_perfect_calibration_for_oracle
— perfect coverage when the credible interval is centered on the truth.tests/core/test_diagnostics.py::TestCalibration::test_well_calibrated_predictions
— ECE < 0.05 when the model matches the data-generating process.tests/estimators/test_recovery.py::TestBLRRecovery::test_posterior_predictive_calibration
— empirical 90 % predictive interval covers between 85 % and 95 % of
the held-out data.T = 200 is
the minimum for stable curves at the 0.05 levels.σ_y.scoring_rules.md — log-score / CRPS penalize
miscalibrated forecasts, complementary to coverage.../topics/learning_and_inference.md
— how Bayesian linear regression produces calibrated intervals.../chapters/chapter_03.md — the
visualize_calibration.py script.../reference/core.md — full API.