Skip to content

Comments

Add diagnose#299

Open
aloctavodia wants to merge 5 commits intomainfrom
diagnose
Open

Add diagnose#299
aloctavodia wants to merge 5 commits intomainfrom
diagnose

Conversation

@aloctavodia
Copy link
Contributor

@aloctavodia aloctavodia commented Feb 15, 2026

This follows the diagnose function from CmdStan. A couple of differences are :

  • This is also computing if ESS > 100 * number of chains
  • It is directly using "reached_max_treedepth" from sample_stats. Not sure if this is available for all PPLs.

Before adding tests, I would like to get feedback about the overall behaviour of this function.

@codecov-commenter
Copy link

codecov-commenter commented Feb 15, 2026

Codecov Report

❌ Patch coverage is 4.65116% with 82 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.21%. Comparing base (b388767) to head (09d248e).

Files with missing lines Patch % Lines
src/arviz_stats/sampling_diagnostics.py 3.52% 82 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #299      +/-   ##
==========================================
- Coverage   84.40%   83.21%   -1.20%     
==========================================
  Files          42       42              
  Lines        5702     5786      +84     
==========================================
+ Hits         4813     4815       +2     
- Misses        889      971      +82     

☔ 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.

@read-the-docs-community
Copy link

read-the-docs-community bot commented Feb 15, 2026

Documentation build overview

📚 arviz-stats | 🛠️ Build #31455294 | 📁 Comparing 09d248e against latest (b388767)


🔍 Preview build

Show files changed (43 files in total): 📝 42 modified | ➕ 1 added | ➖ 0 deleted
File Status
array_stats_only.html 📝 modified
background.html 📝 modified
genindex.html 📝 modified
api/index.html 📝 modified
_modules/arviz_stats/sampling_diagnostics.html 📝 modified
api/generated/arviz_stats.SamplingWrapper.html 📝 modified
api/generated/arviz_stats.base.array_stats.quantile.html 📝 modified
api/generated/arviz_stats.bayes_factor.html 📝 modified
api/generated/arviz_stats.bayesian_r2.html 📝 modified
api/generated/arviz_stats.bfmi.html 📝 modified
api/generated/arviz_stats.ci_in_rope.html 📝 modified
api/generated/arviz_stats.diagnose.html ➕ added
api/generated/arviz_stats.ecdf.html 📝 modified
api/generated/arviz_stats.ess.html 📝 modified
api/generated/arviz_stats.eti.html 📝 modified
api/generated/arviz_stats.hdi.html 📝 modified
api/generated/arviz_stats.histogram.html 📝 modified
api/generated/arviz_stats.kde.html 📝 modified
api/generated/arviz_stats.kl_divergence.html 📝 modified
api/generated/arviz_stats.loo.html 📝 modified
api/generated/arviz_stats.loo_approximate_posterior.html 📝 modified
api/generated/arviz_stats.loo_expectations.html 📝 modified
api/generated/arviz_stats.loo_i.html 📝 modified
api/generated/arviz_stats.loo_kfold.html 📝 modified
api/generated/arviz_stats.loo_moment_match.html 📝 modified
api/generated/arviz_stats.loo_pit.html 📝 modified
api/generated/arviz_stats.loo_score.html 📝 modified
api/generated/arviz_stats.loo_subsample.html 📝 modified
api/generated/arviz_stats.mcse.html 📝 modified
api/generated/arviz_stats.mean.html 📝 modified
api/generated/arviz_stats.median.html 📝 modified
api/generated/arviz_stats.mode.html 📝 modified
api/generated/arviz_stats.psense.html 📝 modified
api/generated/arviz_stats.psense_summary.html 📝 modified
api/generated/arviz_stats.qds.html 📝 modified
api/generated/arviz_stats.reloo.html 📝 modified
api/generated/arviz_stats.residual_r2.html 📝 modified
api/generated/arviz_stats.rhat.html 📝 modified
api/generated/arviz_stats.rhat_nested.html 📝 modified
api/generated/arviz_stats.summary.html 📝 modified
api/generated/arviz_stats.thin.html 📝 modified
api/generated/arviz_stats.update_subsample.html 📝 modified
api/generated/arviz_stats.wasserstein.html 📝 modified

@kylejcaron
Copy link

Nice work @aloctavodia, I think the overall structure is good! The message tracking approach is great for PPLs like numpyro that wont have the same sample stats available by default.

The one callout I have is that I think ESS and rhat calculations will get expensive on larger deterministic sites. Is it worth excluding them or having a flag that excludes them by default? At the very least, filter_vars covers this (I think)


# Check tree depth
if sample_stats_available and "tree_depth" in sample_stats:
reached_max_treedepth = sample_stats["reached_max_treedepth"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you mentioned this isnt ready for review yet, but I noticed this bug when trying to skim through at a high level so figured I might as well call it out

its checking for a tree_depth key but then selecting reached_max_treedepth

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, in the first version I followed cmdstan too closely and I used tree_depth.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ready for review, if you have more comments. I was just waiting for feedback before adding tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add reached_max_treedepth to https://python.arviz.org/en/stable/schema/schema.html#sample-stats. It is not there so I would assume it is PyMC only

ess_min_ratio=0.001,
bfmi_threshold=0.3,
show_diagnostics=True,
return_diagnostics=False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we could take a page from the plots side here and allow a stats dictionary argument. That being said, here I would only allow providing pre-computed elements to keep things simple. For example:

rhat = az.rhat_nested(idata, superchains=...)
az.diagnose(idata, stats={"rhat": rhat})

In that particular case it would make it easier to take advantage of diagnose even if wanting to use rhat_nested instead of regular rhat. They could also change the probability at which to compute ess_tail

Minimum acceptable ratio of ESS to total samples. Parameters with
ESS/N < ess_min_ratio will be flagged.
A flag is also emitted if ESS is lower than 100 * number of chains.
bfmi_threshold : float, default 0.3
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have this as an rcParam I think now

aloctavodia and others added 2 commits February 18, 2026 07:35
Co-authored-by: Oriol Abril-Pla <oriol.abril.pla@gmail.com>
Co-authored-by: Oriol Abril-Pla <oriol.abril.pla@gmail.com>
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.

4 participants