Entropy in Deep Learning

Overview of Entropy

Entropy is a fundamental concept in information theory that quantifies the uncertainty or unpredictability associated with a probability distribution. It measures the amount of information content in a random variable. High entropy indicates that events are equally probable, leading to high uncertainty, while low entropy suggests that some events are more probable, leading to low uncertainty.

Geometrical Intuition

Geometrically, entropy can be visualized as a function of the shape of the probability density function (PDF). If all inputs are equally probable, the PDF is flat and uniform, indicating high entropy. Conversely, if a few inputs have high probabilities, the PDF has tall peaks, indicating low entropy. This geometrical perspective helps in understanding how the distribution of probabilities affects the entropy of a system.

Entropy of Gaussian Distributions

The entropy of a Gaussian distribution is closely related to its variance. A wider Gaussian, which is less peaked, has higher entropy. Specifically, the entropy of a univariate Gaussian is an increasing function of its variance, σ. This relationship highlights how the spread of a distribution influences its entropy.

Computing Entropy of a Gaussian

The entropy of a Gaussian distribution can be computed using a specific formula. Below is a Python code snippet that demonstrates how to compute the entropy of a Gaussian distribution using both a direct formula and the PyTorch library:

Listing 6.1 Computing the entropy of a Gaussian distribution

def entropy_gaussian_formula(sigma):
    return 0.5 * torch.log(2 * math.pi * math.e * sigma * sigma) #1

p = Normal(0, 10)                                                #2

H_formula = entropy_gaussian_formula(p.stddev)                   #3

H = p.entropy()                                                  #4

assert torch.isclose(H_formula, H)                               #5
#1 Equation <a style="text-decoration: none; color: #4080C0;" href="../Text/06.html#eq-entropy-gauss-univar">6.7</a>
#2 Instantiates a Gaussian distribution
#3 Computes the entropy using the direct formula
#4 Computes the entropy using the PyTorch interface
#5 Asserts that the entropies computed two different ways match

Example: Entropy in Image Distributions

Entropy can also be illustrated through examples involving image distributions. Consider two 4 × 4 images with different pixel color distributions:

Figure 6.1 Two 4 × 4 images with different pixel color distributions. In the left image, the four colors R, G, B, and Y are equally probable. In the right image, one color (green) is much likelier than the others. The left image has higher entropy (uncertainty): we cannot predict any color with much certainty. In the right image, we can predict green with relative certainty. Figure 6.1 Two 4 × 4 images with different pixel color distributions. In the left image, the four colors R, G, B, and Y are equally probable. In the right image, one color (green) is much likelier than the others. The left image has higher entropy (uncertainty): we cannot predict any color with much certainty. In the right image, we can predict green with relative certainty.

In the left image, the four colors (R, G, B, and Y) are equally probable, resulting in higher entropy. In contrast, the right image has one color (green) that is much likelier than the others, leading to lower entropy. This example demonstrates how entropy reflects the predictability of color distributions in images.

Practical Example

An example of computing entropy in a practical scenario involves calculating the entropy of a weight variable ( W ) under the condition that a height variable ( H ) is fixed. This involves restricting the universe to a single row of a table and calculating the entropy of that row, showcasing how entropy can be applied to specific data conditions.