feat(conjugate): stamp the Metropolis acceptance rate on the posterior attrs - #210
Merged
Merged
Conversation
…r attrs `select_and_sample` already returns the hyperparameter-sampler acceptance rate and `ConjugateVAR.fit` discarded it — the one MCMC-quality signal a conjugate fit has. Stash it as `posterior.attrs["metropolis_acceptance_rate"]` alongside the existing `in_sample_length` stamp so a convergence report can surface it. Only stamped when at least one hyperparameter was estimated. With no free hyperparameters the sampler takes the closed-form fast path and returns a placeholder rate of 1.0; stamping that would read as a perfectly-mixing chain in a report, so the attr is omitted there instead. The diagnostics-side consumption belongs to the feat/142 follow-up; the attr name is the contract. Refs #178 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Egjd7ToFeb9TQqFnfRQZxV
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #210 +/- ##
=====================================
Coverage 94.8% 94.8%
=====================================
Files 40 40
Lines 2416 2418 +2
Branches 280 281 +1
=====================================
+ Hits 2292 2294 +2
Misses 81 81
Partials 43 43 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_conjugate_sampler.select_and_samplealready computes the hyperparameter random-walk-Metropolis acceptance rate andConjugateVAR.fitthrew it away — the one MCMC-quality signal a conjugate fit has. It is now stamped asposterior.attrs["metropolis_acceptance_rate"], next to the existing attrs.Fast-path decision: on the fixed-prior fast path (
d == 0, no Metropolis chain runs — the sampler returns a hardcoded 1.0), the attr is deliberately omitted rather than stamped: a 1.0 would read in a convergence report as a perfectly-mixing chain instead of "not applicable". The gate isresult["hyperparameters"]truthiness, which is empty exactly on that path. Documented in the docstring and inline.Contract note for the #176 (convergence report) follow-up: the attr name
metropolis_acceptance_rateis the interface; consumers must treat absence as "no rate to report", never render it as 100%.Closes #178
Tests
+3: selected-tightness and volatility-break fits carry a finite rate in (0, 1]; the fixed-prior fast path omits the attr. Fast suite 530 passed, 29 deselected; ruff/ty clean.
🤖 Generated with Claude Code
https://claude.ai/code/session_01Egjd7ToFeb9TQqFnfRQZxV