Last active
December 30, 2017 23:30
-
-
Save miku/1671b2014b003ee7b9054c0618c805f7 to your computer and use it in GitHub Desktop.
Bhattacharyya python.
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 math | |
def bhattacharyya(a, b): | |
""" Bhattacharyya distance between distributions (lists of floats). """ | |
if not len(a) == len(b): | |
raise ValueError("a and b must be of the same size") | |
return -math.log(sum((math.sqrt(u * w) for u, w in zip(a, b)))) | |
x = bhattacharyya([0.1, 0.9], [0.1, 0.9]) | |
print(x) | |
x = bhattacharyya([0.2, 0.8], [0.5, 0.5]) | |
print(x) | |
x = bhattacharyya([0.1, 0.9], [0.5, 0.5]) | |
print(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment