信息熵(香农)

🌡️ Shannon Entropy

Compute Shannon entropy H (bits/symbol) from discrete source symbol probabilities (probabilities should sum to 1; zero-probability terms count as 0).

📐 计算公式与说明

四符号信息熵(本页代码口径):H=−Σ pᵢ×log₂pᵢ(bit/符号,仅累加 pᵢ>0 的符号,按 ln÷ln2 换底)。校验:无强校验,空值按 0 兜底,不校验 Σp=1。判据:无固定分级,四符号等概率(各 0.25)时 H 最大为 2 bit/符号,分布越集中熵越小、趋近 0;输入非归一化概率时结果仍按原始 p 直接累加。

概率应之和为 1;某事件概率为 0 时该项记 0。

📚 深度解析:信息熵(香农)

💡 常见使用场景

示例:公平硬币
p=0.5/0.5 → H=−2×0.5·log2(0.5)=1 bit/符号;偏倚越小熵越低。

❓ 常见问题(FAQ)

概率必须和为 1 吗?
是,离散信源概率归一;若输入频率会自动归一化。
零概率项怎么处理?
按极限 0·log(0)=0 计入,不贡献熵。
熵高一定好?
压缩场景高熵意味着难压缩;安全场景高熵(密钥)是好事。

Formula & Standard References

Item Formula / Rule Source / Standard
Shannon entropy H = −∑ pi log2 pi in bits per symbol Shannon, A Mathematical Theory of Communication, 1948
Boundary conditions H peaks at log2 n for a uniform distribution and falls to 0 when one symbol is certain Shannon 1948 §1, Theorem 1
Practical estimator Sample estimate Ĥ = −∑ (ci/N) log2(ci/N) with counts ci Cover & Thomas, Elements of Information Theory, Ch. 2