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