
#163 How to make your models sample faster, with Adrian Seyboldt & Eliot Carlson
Learning Bayesian StatisticsShow Notes
Support & Resources → Support the show on Patreon → Bayesian Modeling Course (first 2 lessons free)
Our theme music is « Good Bayesian », by Baba Brinkman (feat MC Lars and Mega Ran). Check out his awesome work
Takeaways:
Q: What is mass matrix adaptation, in plain terms? A: Mass matrix adaptation is best understood as an automatic, fairly dumb, but very effective reparameterization of your model. The simplest version, the diagonal mass matrix, just rescales each parameter so its posterior standard deviation becomes one, which is exactly what you'd do by hand if you had the patience. Every time you sample a PyMC or Stan model, this kind of reparameterization is happening under the hood.
Q: How does Nutpie's approach to mass matrix adaptation differ from Stan and PyMC's default? A: Stan and PyMC's default sampler only use one source of information for diagonal mass matrix adaptation: the posterior standard deviation estimated from warm-up draws. Nutpie also uses the gradients of the log density, which HMC is already computing at every step to build its trajectory. For a standard normal distribution, the covariance of the gradients is exactly the inverse covariance of the draws, so Nutpie takes the geometric mean of the two resulting standard deviations. There's no guarantee it's always better, but in practice it usually is.
Q: What problem does "Preconditioning Hamiltonian Monte Carlo by Minimizing Fisher Divergence" actually solve? A: Preconditioning HMC means transforming your target distribution into one that's friendly to sample, but doing that well requires knowing things about the distribution, like its covariance, that sampling itself is supposed to discover. This chicken-and-egg problem is usually handled by sketching a rough estimate from a handful of early warm-up draws, which can burn a large share of total sampling time. Adrian and Eliot's paper formalizes how to make better use of a second signal, the score function, that HMC already computes for free but that Stan-style preconditioning ignores.
Chapters: 00:00:00 What is HMC preconditioning? 00:09:03 A more robust low-rank mass matrix 00:11:58 What is mass matrix adaptation? 00:18:06 What does preconditioning HMC mean? 00:20:57 What is normalizing flow adaptation, and when does a linear mass matrix fall short? 00:23:50 When does normalizing flow adaptation actually help, and when is classic mass matrix adaptation enough? 00:27:13 What is Fisher divergence? 00:30:10 Why is HMC's trajectory, not its density, the right target for preconditioning? 00:33:04 What are the diagonal, dense, and low-rank-plus-diagonal versions of mass matrix adaptation? 00:46:25 How much faster is low-rank-plus-diagonal adaptation? 00:51:07 What's the practical recommendation for using Nutpie and its mass matrix adaptation? 00:54:31 Why does low-rank adaptation sometimes fail spectacularly? 01:01:35 Where does this research fit in the bigger picture of HMC? 01:12:12 How could centered vs. non-centered parameterization be chosen automatically?
Thank you to my Patrons for making this episode possible!
Links from the show here
More from Learning Bayesian Statistics
Support & Resources → Support the show on Patreon → Bayesian Modeling Course (first 2 lessons free)
Today's clip is from Episode 166, featuring Bill Engels & Jesse Grabowski. In this conversation, Bill explains what a kernel means in a Gaussian process and how it defines the idea of similarity between data points. He then breaks down the role of the length scale, showing how it controls how quickly the relationship between two points changes, and how amplitude controls the overall scale of the functions a GP can represent.
Support & Resources → Support the show on Patreon → Bayesian Modeling Course (first 2 lessons free)
Today's clip is from Episode 165, featuring Alex Fengler. In this conversation, Alex introduces Bayesify , a tool that uses AI to analyze research papers and assess how well they follow a Bayesian workflow.
Support & Resources → Support the show on Patreon → Bayesian Modeling Course (first 2 lessons free)