Created
October 27, 2022 03:52
-
-
Save jlcarvalho/9cc15a4d4d708f00130eb8266a7b8162 to your computer and use it in GitHub Desktop.
Get KL Divergence from Normal Distribution
This file contains hidden or 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
export function getKLDivergence(d1: Array<number>, d2: Array<number>) { | |
const [mu1, sigma1] = d1; | |
const [mu2, sigma2] = d2; | |
const eq1 = Math.log(sigma2) / Math.log(sigma1); | |
const eq2 = (sigma1 ** 2 + (mu1 - mu2) ** 2) / (2 * sigma2) ** 2; | |
return eq1 + eq2 - 1 / 2; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment