-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Compute Metropolis average accept probability with logsumexp
#7783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Compute Metropolis average accept probability with logsumexp
#7783
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7783 +/- ##
==========================================
+ Coverage 92.83% 92.84% +0.01%
==========================================
Files 107 107
Lines 18354 18381 +27
==========================================
+ Hits 17039 17066 +27
Misses 1315 1315
🚀 New features to boost your workflow:
|
@ricardoV94 any thoughts about just clipping the acceptance probability to be in 0,1 ? |
Co-authored-by: Ricardo Vieira <28983449+ricardoV94@users.noreply.github.com>
Is that why you were getting nans after the exp? Shouldn't hurt, as long as it's all cheap stuff |
Yes I assume it was overflowing. In the progress bar I was seeing large values for acceptance |
Then feel free to clip the exp from above or the log to be at most 0 for the returned stat |
In the Metropolis step stats that we report on the progressbar, we have a probability of acceptance. This is currently computed in a very direct way, just
np.mean(np.exp(log_accept_prob))
. We can do better withnp.exp(logsumexp(log_accept_prob) - log(len(log_accept_prob)))
.In really gnarly models, I've encountered overflows in this step. This might also be because there's a max(delta_logp, 1) missing from the acceptance probabilities. But even if we add that, the computation method in this PR is more numerically stable and accurate.
📚 Documentation preview 📚: https://pymc--7783.org.readthedocs.build/en/7783/