A robot category model can have a concentrated probability vector and still disagree strongly with a reference distribution. Entropy describes how spread out one distribution is. Kullback-Leibler divergence compares two distributions in a specified direction, with one supplying the weights in the average.
Those distinctions matter before interpreting any score as recognition quality. A mathematically valid probability vector is not automatically calibrated, and a chosen reference is not automatically physical ground truth. The original example below defines its distributions explicitly rather than making either inference.
Choose aligned categories and units
Use three hypothetical mutually exclusive categories, A, B, and C. Let the reference vector P be (0.60, 0.30, 0.10), and let a comparison vector Q be (0.30, 0.40, 0.30). Both have nonnegative entries summing to one, with the same category order.
Use logarithms to base two throughout, so information quantities are measured in bits. Natural logarithms would give nats instead. A change of base rescales a result by a constant; it does not change which category has the largest probability.
Define Shannon entropy H(P) = -sum over i of pi log2(pi). Define directed KL divergence D(P || Q) = sum over i of pi log2(pi/qi). The notation declares that P supplies the weights and Q appears in the denominator.
SciPy's official entropy and elementwise relative-entropy documentation gives these definitions and the zero-probability conventions. The following vectors, calculations, and comparisons are original. No inference library or robot classifier was executed.
Compute entropy for one distribution
For P, the three entropy contributions are approximately 0.442179, 0.521090, and 0.332193 bit. Their sum is approximately 1.295462 bits.
Q has entropy approximately 1.570951 bits, reflecting its more even spread across these three categories. The maximum for three categories is log2(3), approximately 1.584963 bits, reached by equal probabilities.
This comparison says that P is more concentrated than Q in the defined distributional sense. It does not say that P is more correct. A model can assign concentrated probability to the wrong category, and no labeled observations have been supplied here to evaluate that issue.
Entropy also ignores the names attached to a given collection of probabilities. Permuting the three entries preserves entropy because it only changes their summation order. A comparison between distributions, however, must respect the shared category labels.
Calculate a directional mismatch
For D(P || Q), category A contributes 0.60 log2(0.60/0.30) = 0.60 bit. Category B contributes 0.30 log2(0.30/0.40), approximately -0.124511 bit. Category C contributes 0.10 log2(0.10/0.30), approximately -0.158496 bit.
The sum is approximately 0.316993 bit. Two individual contributions are negative even though the total divergence is nonnegative. Nonnegativity applies to the normalized distribution sum, not to every elementwise term.
Reverse the order and compute D(Q || P). The result is approximately 0.341504 bit. The distributions did not change, but the averaging weights and probability ratios did. KL divergence is therefore not a symmetric geometric distance.
A result should preserve the order of its arguments. Reporting only a number labeled divergence can omit which distribution was the reference for the expected mismatch.
Connect divergence to expected log loss
Define cross entropy H(P, Q) = -sum pi log2(qi). For this pair it is approximately 1.612454 bits. Adding H(P), approximately 1.295462, to D(P || Q), approximately 0.316993, gives the same result.
This identity follows directly from splitting log2(pi/qi) into log2(pi) minus log2(qi). It separates uncertainty already present in P from the additional expected logarithmic mismatch associated with using Q under P's weights.
The three cross-entropy contributions are approximately 1.042179, 0.396578, and 0.173697 bits. Their sum again gives 1.612454. These are expected scores under the stipulated P, not an observed average from a robot test set.
Check why the sum cannot be negative
For strictly positive distributions, use the inequality -ln(x) greater than or equal to 1 - x. Substitute x = qi/pi and multiply by pi. Summing gives sum pi ln(pi/qi) greater than or equal to sum pi minus sum qi, which is zero.
Dividing by positive ln(2) preserves the inequality for base-two divergence. Equality holds when the aligned distributions agree. Normalization is essential to this proof; arbitrary unnormalized component values do not inherit the same conclusion just because the elementwise formula can be evaluated.
Treat zero probabilities explicitly
A category with pi = zero contributes zero to D(P || Q) under the limiting convention, including when qi is also zero. But if pi is positive and qi is zero, the divergence is infinite. Q assigns no probability to an outcome that P includes.
Replacing that zero with a small positive value creates a different Q. Such smoothing may be deliberately defined, but it changes the mathematical comparison and must retain its rule and renormalization. It does not recover missing evidence about the category's actual occurrence.
Keep labels and normalization attached
Permute P's probabilities into R = (0.10, 0.30, 0.60) while retaining category labels A, B, and C. R has the same entropy as P, but D(P || R) is approximately 1.292481 bits. Equal entropy did not imply agreement about which outcomes were likely.
If arrays instead store counts, define how each is converted to a distribution and which observation group it represents. The official entropy routine documents automatic normalization, but automatic arithmetic does not verify aligned labels, a common population, or appropriate sampling assumptions.
All numbers were independently recomputed with basic arithmetic. The example compares declared categorical models without claiming measured calibration, classification accuracy, or a validated robot behavior.
Sources checked October 24, 2026: SciPy1.18.0, entropy: https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.entropy.html
SciPy1.18.0, rel_entr: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.rel_entr.html
Illustration note: A generic robot vision or laptop image is a concept illustration. It does not show these invented category distributions, a trained classifier, or measured recognition performance.