How can you calculate the entropy of a discrete random variable using its probability mass function?

Calculating Entropy of a Discrete Random Variable

Entropy is a measure of the average information content or uncertainty in a random variable. Given a discrete random variable XX with a probability mass function P(X)P(X), the entropy H(X)H(X) can be calculated as follows:

  1. Probability Mass Function (PMF): P(X)P(X) gives the probability that the random variable XX takes on a specific value xx. For a discrete random variable, P(X)P(X) is a function that maps each possible value of XX to a probability between 0 and 1, such that the sum of probabilities over all possible values is 1.

  2. Entropy Formula: The entropy H(X)H(X) is calculated using the PMF:

    H(X)=P(x)logP(x)H(X) = -\sum P(x) \log P(x)

    Here's a breakdown of the formula:

    • \sum represents the sum over all possible values xx of the random variable XX.
    • P(x)P(x) is the probability of XX taking the value xx.
    • log\log is the base-2 logarithm, which is commonly used in information theory. If you prefer to use the natural logarithm (base ee), you can do so, but you'll need to adjust the base of the logarithm accordingly.
  3. Example: Suppose XX is a discrete random variable with the following PMF:

    P(X)={0.2if X=10.3if X=20.5if X=3P(X) = \begin{cases} 0.2 & \text{if } X = 1 \\ 0.3 & \text{if } X = 2 \\ 0.5 & \text{if } X = 3 \end{cases}

    Plugging these values into the entropy formula, we get:

    H(X)=(0.2log0.2+0.3log0.3+0.5log0.5)1.52H(X) = - (0.2 \log 0.2 + 0.3 \log 0.3 + 0.5 \log 0.5) \approx 1.52
How can you calculate the entropy of a discrete random variable using its probability mass function? — Entropy | Unlo