Information theory
Cross-entropy
info.cross-entropyAlso called cross entropy, crossentropy, xent, h pq
Expected information content under q of outcomes drawn from p, in nats. It equals H(p) + DKL(p ‖ q) and is not symmetric in p and q.
Notation
probability vector
p ∈ Δn: pi > 0, ∑pi = 1
second probability vector
q ∈ Δn: qi > 0, ∑qi = 1
number of outcomes
Size, at least 2
Result: the cross-entropy, in nats
scalar
Worked examples
Each result is solved exactly and confirmed by two independent computations.
Given
Result
≈ 0.836988216786
Given
Result
≈ 0.69314718056
Given
Result
≈ 0.562335144619
Common mistakes
Swaps p and q
The logarithm is taken of p and weighted by q.
Fix: Weight by p and take the logarithm of q.
Uses log base 2
The result is in bits.
Fix: Use the natural logarithm, or multiply by ln 2.
Sources
Cover and Thomas 2006
Cover, Thomas M.; Thomas, Joy A. Elements of Information Theory. 2nd ed. Wiley-Interscience, 2006. doi:10.1002/047174882X
Goodfellow et al. 2016, §3.13
Goodfellow, Ian; Bengio, Yoshua; Courville, Aaron. Deep Learning. MIT Press, 2016.