Last active
February 2, 2016 03:16
-
-
Save wfwei/c8933ec826b98d8ea1da to your computer and use it in GitHub Desktop.
entropy
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
def entropy(x:Double, y:Double):Double = { | |
if(x==0 || y==0){ | |
0 | |
} else { | |
val p1 = x / (x + y) | |
val p2 = y / (x + y) | |
- (p1*math.log(p1) + p2*math.log(p2))/math.log(2) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment