Information theory
Shannon entropy
info.entropyAlso called entropy, shannon entropy, information entropy, h
Expected information content of a discrete distribution, in nats. Zero for a point mass, ln n for the uniform distribution.
Notation
probability vector
p ∈ Δn: pi > 0, ∑pi = 1
number of outcomes
Size, at least 2
Result: the entropy, in nats
scalar
Worked examples
Each result is solved exactly and confirmed by two independent computations.
Given
Result
≈ 0.69314718056
Given
Result
≈ 1.03972077084
Given
Result
≈ 1.09861228867
Given
Result
≈ 0.325082973391
Common mistakes
Uses log base 2
The result is in bits; entropy in nats is ln 2 times larger.
Fix: Use the natural logarithm, or multiply by ln 2.
Uses log base 10
The result is in hartleys (base-10 logarithm).
Fix: Use the natural logarithm.
Sources
Shannon 1948
Shannon, Claude E. A Mathematical Theory of Communication. Bell System Technical Journal 27(3): 379-423, 1948. doi:10.1002/j.1538-7305.1948.tb01338.x
Cover and Thomas 2006
Cover, Thomas M.; Thomas, Joy A. Elements of Information Theory. 2nd ed. Wiley-Interscience, 2006. doi:10.1002/047174882X