Read the equation
The mathematical entropy sums −p log p over a normalized nonnegative distribution, with a zero contribution at p=0. The function uses log₂, so its output is in bits, but skips probabilities at or below EPSILON_PHI and near one. It does not validate normalization, making it a truncated entropy calculation whose input assumptions matter.
Terms & definitions
| Term | Meaning in this source |
|---|---|
| p | Probability masses |
| H | Entropy in bits |
| EPSILON_PHI | Approximately 0.001618 cutoff |
How it works
Read the definition from its right-hand expression to the quantity on the left. Its surrounding source records the intended input, state, or parameter context. Where the source leaves an operation unspecified, this page preserves that gap.
Assumptions & limits
Source recovery establishes that the expression appears in this record. Its mathematical validity, implementation behavior, and interpretation must be assessed separately. See the linked source and research notes for the checks available for this version.
Original context
Read the surrounding source passage
return -float64(n*(n-1)) * PHI * 0.5 / float64(n*n)
}
// ═══════════════════════════════════════════════════════════════════════════════
// INFORMATION THEORY EQUATIONS
// ═══════════════════════════════════════════════════════════════════════════════
// ShannonEntropy computes H(X) = -Σ p(x) log p(x)
func ShannonEntropy(probs []float64) float64 {
h := 0.0
for _, p := range probs {
if p > EPSILON_PHI && p < 1.0-EPSILON_PHI {
h -= p * math.Log2(p)
}
}
return h
}
Exact original notation
ShannonEntropy computes H(X) = -Σ p(x) log p(x)