Last active
December 5, 2020 07:05
-
-
Save davidlenz/879735d64f8b0be570a684ac5fd79d3b to your computer and use it in GitHub Desktop.
Implementation of Jensen-Shannon-Divergence based on https://github.com/scipy/scipy/issues/8244
This file contains 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
import numpy as np | |
from scipy.stats import entropy | |
def js(p, q): | |
p = np.asarray(p) | |
q = np.asarray(q) | |
# normalize | |
p /= p.sum() | |
q /= q.sum() | |
m = (p + q) / 2 | |
return (entropy(p, m) + entropy(q, m)) / 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just for those who land here looking for jensen shannon distance (using monte carlo integration) between two distributions:
https://stats.stackexchange.com/questions/345915/trying-to-implement-the-jensen-shannon-divergence-for-multivariate-gaussians/419421#419421