Fix RegimeSwitchingModel: MEADS+GHMC with k-fold adaptation (Rhat ≤ 1.01)#82
Merged
junpenglao merged 1 commit intomainfrom Mar 28, 2026
Merged
Fix RegimeSwitchingModel: MEADS+GHMC with k-fold adaptation (Rhat ≤ 1.01)#82junpenglao merged 1 commit intomainfrom
junpenglao merged 1 commit intomainfrom
Conversation
The notebook was producing divergent chains (Rhat ~ 1e14) due to two issues:
1. Linear-space HMM forward filter was numerically unstable; replaced with
a fully log-space implementation (logpdf, logaddexp, logsumexp).
2. MEADS+GHMC was initialised with all chains tightly clustered, making
inter-chain gradient covariance ~0, which caused MEADS to set a huge
step_size and GHMC chains to diverge. Fixed with a two-stage init:
(a) NUTS window adaptation to reach the posterior, anchoring sigma/rho
to break regime symmetry;
(b) 64 short NUTS chains (200 steps each) from the warm endpoint to
generate diverse starting positions that span the true posterior width,
giving MEADS a well-conditioned covariance estimate.
Result: all Rhat ≤ 1.01, n_eff 6k-11k, runtime ~27s with 64 chains × 1000
draws using MEADS k-fold (num_folds=4) + GHMC.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
norm.pdfwith a fully log-space implementation (norm.logpdf,logaddexp,logsumexp) to avoid underflow in the filtered state probabilities.sigma/rhoto break regime symmetry (sigma=[3,10]in constrained space).num_folds=4, Algorithm 3 of Hoffman & Sountsov 2022) + GHMC, 64 chains × 1000 draws.Results
Runtime: ~27s (2× A100 or equivalent).
Test plan
🤖 Generated with Claude Code