Information Content and Entropy — Quantifying Uncertainty
Information Content and Entropy -- Quantifying Uncertainty
Information theory provides mathematical tools to quantify "information" and "uncertainty" for AI.
The less likely an event is to occur, the greater the information it carries once it happens.
Conceptual Analysis
Information theory seeks to answer a fundamental question: How to quantify the amount of "information" contained in a message?
Key Insight: Information content is inversely proportional to the probability of an event—the less likely an event is to happen, the more information it tells you once it does.
Why is information content defined as -log P(x)?
This definition includes three most natural intuitions:
- Inverse relationship: The smaller P(x) is (the more unexpected), the larger I(x) should be. The negative sign ensures this.
- Additivity: The information content of two independent events occurring simultaneously = the sum of their individual information contents. log turns the product of probabilities into the sum of information contents: ( -\log(p_1 \cdot p_2) = -\log p_1 + (-\log p_2) )
- Deterministic events are zero: When the certain event P=1, ( -\log 1 = 0 )—known facts bring no information.
Information content (self-information)
[ I(x) = -\log P(x) ]
Base 2 $\rightarrow$ bits, base e $\rightarrow$ nats. Natural logarithm is usually used in AI because it is easy to differentiate.
Entropy: The expected value of information content
[ H(X) = -\sum_x P(x) \log P(x) ]
Entropy measures the uncertainty of the entire probability distribution.
- Certain event (P=1): H = 0 (no uncertainty)
- Uniform distribution: H takes the maximum value (most uncertain)
Higher entropy = harder to predict. This provides the theoretical basis for decision tree splitting criteria (information gain) and exploration strategies in reinforcement learning.
Real-life examples
**News value
"The sun will rise tomorrow" -> Information content ≈ 0 (you already know).
"There will be an 8-magnitude earthquake tomorrow" -> Extremely high information content (an extremely rare event has occurred).
The more unexpected the news, the greater the information content—this is the intuition behind I(x) = -log P(x).
Python hands-on practice
Example
import
numpy
as
np
def
entropy
(
probs
)
:
probs
=
np.
array
(
probs
)
probs
=
probs
[
probs
0
]
return
-np.
sum
(
probs * np.
log
(
probs
)
)
(
"Distribution [1,0,0] confirmed:"
,
entropy
(
[
1
,
0
,
0
]
)
)
0
(
"2-class uniform [0.5,0.5]:"
,
entropy
(
[
0.5
,
0.5
]
)
)
0.693
(
"10 classes uniform:"
,
entropy
(
[
0.1
]
10
)
)
2.303
(
"Biased [0.9,0.05,0.05]:"
,
entropy
(
[
0.9
,
0.05
,
0.05
]
)
)
0.394
Runtime output:
Original prompt (Chinese, left untranslated)
确定分布 [1,0,0]: 0.0
2类均匀 [0.5,0.5]: 0.6931471805599453
10类均匀: 2.302585092994046
有偏 [0.9,0.05,0.05]: 0.3944479480436973
Binary classification entropy curve
Application scenarios in AI
Decision tree splitting criterion: Information gain
Decision trees calculate the difference in entropy before and after splitting—Information Gain = H(before split) - H(after split) when selecting a splitting feature. The feature and split point with the maximum information gain are chosen. Both C4.5 and ID3 algorithms are based on this principle.
Cross-entropy loss = Minimizing the difference between the predicted distribution and the true distribution
In classification tasks, the entropy H(p)=0 of the true distribution p (one-hot labels), so the cross-entropy H(p,q) equals KL(p||q). Minimizing cross-entropy = making the predicted distribution q as close as possible to the true distribution p. This will be elaborated in the next chapter.
Entropy Regularization in Reinforcement Learning
The SAC (Soft Actor-Critic) algorithm adds a policy entropy term to the optimization objective: maximize Reward + ( \alpha \cdot H(\pi) ). This encourages the policy to maintain a certain level of randomness (not be too certain), promoting exploration and preventing premature convergence to a suboptimal policy. (\alpha) is the entropy regularization coefficient, controlling the balance between exploration and exploitation.
Entropy in Model Calibration
A good classifier should not only have high accuracy, but the entropy of its predicted distribution should also reflect the true uncertainty. When the model encounters out-of-distribution (OOD) samples, ideally the entropy of the Softmax output should be high (close to a uniform distribution), indicating "I am uncertain." If the entropy is low but the prediction is wrong, it means the model is overconfident.