Skip to content

Posterior SBC Support#54

Merged
aloctavodia merged 23 commits into
arviz-devs:mainfrom
Cab14bacc:feat/Posterior_SBC_Support
Jun 1, 2026
Merged

Posterior SBC Support#54
aloctavodia merged 23 commits into
arviz-devs:mainfrom
Cab14bacc:feat/Posterior_SBC_Support

Conversation

@Cab14bacc
Copy link
Copy Markdown
Contributor

@Cab14bacc Cab14bacc commented May 7, 2026

Closes #12 and referenced #49
Depends on #53 and #52

This PR introduces support for Posterior SBC using PyMC Models. Given original posterior samples, generate posterior predictive samples, augment them with the original observed data, sample from posterior conditioned on the augmented data, and compute rank statistics comparing the original posterior samples and the augmented posterior samples.

Constraint of Implmentation

Posterior SBC augments the observed data (concatenating original + replicated), which changes its size. For this to work, store observed data in pm.Data containers, and specify size using the dims parameter instead of setting a static shape.

If your model uses dims and coords, you are also responsible for resizing them to the correct size corresponding to the new augmented dataset via the update_data callback. Similarly, if your model has covariates, store them in pm.Data so they can be resized in the same callback.

New Parameters for SBC Class

  • method="posterior": You can now pass an original trace (containing posterior distributions) alongside method="posterior" to execute Posterior SBC.
  • Custom Callbacks: These are included to deal with needed updates to the model when conditioning on the augmented dataset.
    • augment_observed: Custom logic for how to augment the posterior predictive sample and the observed data, the default behavior is to concatenate on the first axis.
    • update_data: Called before conditioning on the augmented dataset. custom logic to update the covariates, coords to conform to the new augmented data. There is no default behavior, but if user does not modify variable that are of type pm.Data that are used for observed data, the code will update according to the augmented data.

Misc

  • Added tests for posterior sbc.
  • Added toy example for posterior sbc.

@Cab14bacc Cab14bacc force-pushed the feat/Posterior_SBC_Support branch from 68263df to 3189ee0 Compare May 26, 2026 20:05
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 27, 2026

Codecov Report

❌ Patch coverage is 96.41256% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.69%. Comparing base (d48ceb7) to head (6e715df).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
simuk/sbc.py 94.64% 6 Missing ⚠️
simuk/tests/test_posterior_sbc.py 98.13% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #54      +/-   ##
==========================================
+ Coverage   96.30%   96.69%   +0.39%     
==========================================
  Files           3        4       +1     
  Lines         352      545     +193     
==========================================
+ Hits          339      527     +188     
- Misses         13       18       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread docs/examples/gallery/posterior_sbc.md Outdated
Comment thread docs/examples/gallery/posterior_sbc.md Outdated
Comment thread docs/examples/gallery/posterior_sbc.md Outdated
Comment thread simuk/tests/test_posterior_sbc.py Outdated
Comment thread simuk/tests/test_posterior_sbc.py Outdated
Comment thread simuk/sbc.py Outdated
Comment thread simuk/sbc.py Outdated
@aloctavodia
Copy link
Copy Markdown
Contributor

Docs seem to be too heavy for RTD, we should run them locally so RTD only handles rendering the results.

@aloctavodia aloctavodia merged commit cb3e950 into arviz-devs:main Jun 1, 2026
4 checks passed
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.

Add posterior SBC

3 participants