Skip to content

Instantly share code, notes, and snippets.

@wfwei
Last active February 2, 2016 03:16
Show Gist options
  • Save wfwei/c8933ec826b98d8ea1da to your computer and use it in GitHub Desktop.
Save wfwei/c8933ec826b98d8ea1da to your computer and use it in GitHub Desktop.
entropy
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