Skip to content

Conversation

@lasse-meixner
Copy link

Resolves #577.

Description

Creates coverage plots showing empirical coverage of posterior credible intervals.
A well-calibrated model would have coverage exactly match interval width (i.e. 95% credible interval contains the true value 95% of the time) as shown by a diagonal line.

The coverage for the provided simulated datasets is accompanied by credible intervals for coverage proportion (in form of a gray ribbon). These are calculated via the standard (conjugate) Beta-Binomial model for binomial proportions with a uniform prior.

Changes

  • adds module bayesflow.diagnostics.plots.coverage implementing coverage plot and coverage diff plot
  • adds auxiliary function compute_empirical_coverage in bayesflow.utils.plot_utils

Example
Here an example of a model that is "too uncertain", or too conservative. It over-covers:

Screenshot 2025-09-23 at 13 35 47
@stefanradev93
Copy link
Contributor

Hi Lasse, I agree that this would be a very nice feature (which we implicitly care about when we compute the expected calibration error / ECE metric). And thank you for the PR, which I will review asap.

@stefanradev93 stefanradev93 self-assigned this Sep 23, 2025
@stefanradev93
Copy link
Contributor

Hi Lasse, thanks for the PR and for following all contribution guidelines! I think the PR is almost merge-ready up to a small discussion on the following point:

  • Since the two new functions coverage and coverage_diff share a lot of code and logic, I wonder if it would make sense to merge them into a single function with an optional difference boolean flag, akin to what we have for the ECDF plots?

Also, do you happen to have a reference for the beta formulation of the coverage confidence bands which we can include in the docstring?

@lasse-meixner
Copy link
Author

@stefanradev93 sure!
I agree with your first point, I merged the two as suggested. Regarding a source for the beta-binomial model I added a docstring reference to Chapter 2 of `Bayesian Data Analysis (2013, 3rd ed.) by Gelman A., et al. where this is covered.

@codecov
Copy link

codecov bot commented Sep 24, 2025

Codecov Report

❌ Patch coverage is 93.58974% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
bayesflow/utils/plot_utils.py 89.18% 4 Missing ⚠️
bayesflow/diagnostics/plots/coverage.py 97.50% 1 Missing ⚠️
Files with missing lines Coverage Δ
bayesflow/diagnostics/plots/__init__.py 100.00% <100.00%> (ø)
bayesflow/utils/__init__.py 100.00% <ø> (ø)
bayesflow/diagnostics/plots/coverage.py 97.50% <97.50%> (ø)
bayesflow/utils/plot_utils.py 76.47% <89.18%> (+3.53%) ⬆️

... and 5 files with indirect coverage changes

@stefanradev93 stefanradev93 merged commit 8ef46f6 into bayesflow-org:dev Sep 24, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants