Skip to content

feat(conjugate): stamp the Metropolis acceptance rate on the posterior attrs - #210

Merged
thomaspinder merged 1 commit into
mainfrom
feat/178-conjugate-acceptance-rate
Jul 29, 2026
Merged

feat(conjugate): stamp the Metropolis acceptance rate on the posterior attrs#210
thomaspinder merged 1 commit into
mainfrom
feat/178-conjugate-acceptance-rate

Conversation

@thomaspinder

Copy link
Copy Markdown
Owner

Summary

_conjugate_sampler.select_and_sample already computes the hyperparameter random-walk-Metropolis acceptance rate and ConjugateVAR.fit threw it away — the one MCMC-quality signal a conjugate fit has. It is now stamped as posterior.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 is result["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_rate is 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

…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-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.8%. Comparing base (a378a8f) to head (cf2d1cf).

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

@thomaspinder
thomaspinder merged commit 6622982 into main Jul 29, 2026
9 checks passed
@thomaspinder thomaspinder added the enhancement New feature or request label Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Surface the conjugate Metropolis acceptance rate in the convergence report

2 participants