fix: correct biased pymc HMC sampling (target_accept)#1908
Open
janfb wants to merge 3 commits into
Open
Conversation
The hmc parametrizations of test_c2st_pymc_sampler_on_Gaussian were failing in CD (c2st ~0.62). Root cause is PyMC's HamiltonianMC default target_accept=0.65, which mixes poorly on this peaked target regardless of seed, warmup, or number of draws (NUTS is unaffected). Expose seed and target_accept on PyMCSampler and set target_accept=0.95 (c2st ~0.51-0.54 across seeds and chain counts) plus a fixed seed in the test for reproducibility.
MCMCPosterior._pymc_mcmc left PyMC's HamiltonianMC at its default target_accept=0.65, which produces biased hmc_pymc posteriors (c2st ~0.62 on a Gaussian). Default it to 0.9 for the HMC step, leaving nuts_pymc and slice_pymc unchanged. hmc_pymc now samples accurately (c2st ~0.51).
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1908 +/- ##
==========================================
+ Coverage 87.81% 87.89% +0.07%
==========================================
Files 143 143
Lines 13387 13403 +16
==========================================
+ Hits 11756 11780 +24
+ Misses 1631 1623 -8
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
Follow-up to #1894 because CD is failing again. Once the lockfile fix let the pymc tests run again in CD,
test_c2st_pymc_sampler_on_Gaussianfailed on thehmcparametrizations with c2st around 0.62.However, it's not flaky: pymc's
HamiltonianMCdefaults totarget_accept=0.65, which mixes poorly on this peaked Gaussian and biases the samples, regardless of seed, warmup, or number of draws. NUTS works fine.To fix this:
seedandtarget_acceptonPyMCSamplertarget_accept=0.9for thehmc_pymcstep inMCMCPosteriorto get accurate HMC posteriors (c2st ~0.51 vs ~0.62);nuts_pymc/slice_pymcunchangedtarget_accept=0.95in the c2st test for reproducible samplingslicedoes not taketarget_accept, so it is only applied to hmc/nuts.Note: the c2st test is marked
slow, I will run the CD on this branch via workflow dispatch.