Created
January 20, 2014 14:25
-
-
Save wadoon/8520742 to your computer and use it in GitHub Desktop.
Entropie-Berechnung
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
from math import log | |
log2 = lambda x: log(x,2) | |
def entropy(poss): | |
a = lambda p: p * log2( 1/p ) | |
return sum(map(a,poss)) | |
a = (1./6, 1./3, 1./3) | |
b = (1./2, 1./4, 1./4) | |
c = (0.01, 0.01, 0.98) | |
print "E%-65s = %f" % (str(a), entropy(a)) | |
print "E%-65s = %f" % (str(b), entropy(b)) | |
print "E%-65s = %f" % (str(c), entropy(c)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment