Approximating KL Divergence
This post is about Monte-Carlo approximations of KL divergence. πΎ πΏ [ π , π ] = β π₯ π ( π₯ ) log β‘ π ( π₯ ) π ( π₯ ) = πΈ π₯ βΌ π [ log β‘ π ( π₯ ) π ( π₯ ) ] KL[q,p]= x β β q(x)log p(x) q(x) β =E xβΌq β [log p(x) q(x) β ] It explains a trick Iβve used in various code, where I approximate K L [ π , π ] KL[q,p] as a sample average of 1 2 ( log β‘ π ( π₯ ) β log β‘ π ( π₯ ) ) 2 2 1 β (logp(x)βlogq(x)) 2 , for samples π₯ x from π q, rather the more standard log β‘ π ( π₯ ) π ( π₯ ) log p(x) q(x) β . This post will explain why this expression is a good (though biased) estimator of KL, and how to make it unbiased while preserving its low variance. Our options for computing KL depend on what kind of access we have to π p and π q. Here, weβll be assuming that we can compute the probabilities (or probability densities) π ( π₯ ) p(x) and π ( π₯ ) q(x) for any π₯ x, but we canβt calculate the sum over π₯ x analytically. Why wouldnβt we be able to calculate
Approximating KL Divergence John Schulman's Homepage Approximating KL Divergence Posted on 2020/03/07 β back to blog index \gdef\ratio{\tfrac{p(x)}{q(x)}} \gdef\iratio{\tfrac{q(x)}{p(x)}} \gdef\half{\tfrac{1}{2}} \gdef{\klqp}{\mathrm{KL}[q,p]} \gdef{\klpq}{\mathrm{KL}[p,q]} This post is about Monte-Carlo approximations of KL divergence. KL[q, p] = \sum_x q(x) \log \iratio = E_{ x \sim q}[\log \iratio ] It explains a trick Iβve used in various code, where I approximate \klqp as a sample average of \half (\log p(x) - \log q(x))^2 , for samples x from q , rather the more standard \log \frac{q(x)}
saved by
- Adithya V
- Sarah Pan
- Dhruv Gautam
- Dhruv Sheth
- Julian H
- Jo J.
- Akira Yoshiyama
- Zeyneb Kaya
- Ishaan Panigrahi
- Evie Hu
- Bhagyesh Kumar
related reading
- Six (and a half) intuitions for KL divergence β LessWronglesswrong.com
- KullbackβLeibler divergence - Wikipediaen.wikipedia.org
- Andy Jonesandrewcharlesjones.github.io
- Short Notes on Divergence Measuresdanilorezende.com
- Gregory Gundersengregorygundersen.com
- blog.alexalemi.com KL is All You Needblog.alexalemi.com
- Coordinate Ascent Mean-field Variational Inference (Univariate Gaussian Example)suzyahyah.github.io
- Tuan Anh Letuananhle.co.uk
- Sampling: Two Basic Algorithmsgregorygundersen.com
- Eric Jang: A Beginner's Guide to Variational Methods: Mean-Field Approximationblog.evjang.com
- blog.alexalemi.com Why KL?blog.alexalemi.com
- Exponential families from a single KL identityarxiv.org