Skip to content

Instantly share code, notes, and snippets.

@wadoon
Created January 20, 2014 14:25
Show Gist options
  • Save wadoon/8520742 to your computer and use it in GitHub Desktop.
Save wadoon/8520742 to your computer and use it in GitHub Desktop.
Entropie-Berechnung
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