Entropy, Information and Uncertainty

A concise introduction to Shannon entropy and the mathematical measurement of uncertainty in discrete systems.

Published
By
Author Name
Reading
3 minutes
Abstract field of connected points representing information and uncertainty

Abstract

This article introduces entropy as a measure of uncertainty, derives the familiar expression for a discrete random variable, and connects the equation to practical reasoning about information.

The fundamental problem of communication is that of reproducing at one point a message selected at another point.

Claude E. Shannon

Why uncertainty can be measured#

Information theory begins with a restrained but powerful question: how much uncertainty is resolved when an outcome becomes known? A result that was nearly certain carries little surprise. A result drawn from many equally plausible alternatives carries more.

For a discrete random variable XX with possible outcomes x1,x2,,xnx_1, x_2, \ldots, x_n, Shannon entropy is defined as

H(X)=i=1np(xi)log2p(xi).H(X) = -\sum_{i=1}^{n} p(x_i)\log_2 p(x_i).

The logarithm uses base two when information is measured in bits. The negative sign ensures that the sum is non-negative because 0<p(xi)10 < p(x_i) \leq 1 implies log2p(xi)0\log_2 p(x_i) \leq 0.

The fair coin#

For a fair coin,

p(heads)=p(tails)=12.p(\text{heads}) = p(\text{tails}) = \frac{1}{2}.

Therefore,

H(X)=2(12log212)=1.H(X) = -2\left(\frac{1}{2}\log_2\frac{1}{2}\right)=1.

One binary decision resolves the uncertainty completely. A biased coin has lower entropy because one outcome is easier to anticipate.

entropy.ts
export function entropy(probabilities: readonly number[]): number {
  const total = probabilities.reduce((sum, probability) => sum + probability, 0)
 
  if (Math.abs(total - 1) > 1e-9) {
    throw new Error("Probabilities must sum to one")
  }
 
  return -probabilities.reduce((information, probability) => {
    if (probability === 0) return information
    return information + probability * Math.log2(probability)
  }, 0)
}

Maximum entropy#

Among all distributions over nn outcomes, entropy is greatest when every outcome has equal probability:

p(xi)=1n,H(X)=log2n.p(x_i)=\frac{1}{n}, \qquad H(X)=\log_2 n.

This result explains why uniform distributions represent maximum uncertainty when no additional constraints distinguish one outcome from another.

From equation to practice#

Entropy appears in compression, decision trees, statistical learning, cryptography, and experimental design. Its usefulness comes from turning uncertainty into a quantity that can be compared, optimized, and decomposed.

Closing observation#

The elegance of entropy lies in its economy. A single expectation combines probability, surprise, and the practical cost of representation. It is both a theorem-bearing mathematical object and a disciplined language for talking about what is not yet known.

References

  1. Shannon, C. E. “A Mathematical Theory of Communication.” Bell System Technical Journal, 1948.
  2. Cover, T. M., and Thomas, J. A. Elements of Information Theory. Wiley, 2006.