fundamentals

Calibration

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.

Definitions

Empirical coverage

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(α) ≈ α.

Calibration curve

The function α → coverage(α) over a sweep of nominal levels. A calibrated model produces the diagonal; deviations diagnose over- / under-confidence.

Expected calibration error (ECE)

L₁ deviation from the diagonal::

ECE = (1 / L) Σ_ℓ |coverage(α_ℓ) − α_ℓ|

Smaller is better; ECE = 0 means perfect calibration on the sampled levels.

API

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 that pin it down

Pitfalls

See also