Jensen-Shannon Distance: Comparing Two Robot Histograms
2026-11-10

Jensen-Shannon Distance: Comparing Two Robot Histograms

Jensen-Shannon Distance compares two probability distributions through a shared midpoint. A robotics team could use it to describe how the proportions of recorded inspection outcomes differ between two batches. Each outcome must have the same meaning and occupy the same position in both arrays. Once those categories are aligned, the calculation can compare distributions even if one batch has no observations in a category that appears in the other.

Make the midpoint from corresponding categories

Suppose two inspection batches have the same two outcome categories. In the first batch the proportions are 0.75 and 0.25. In the second they are 0.25 and 0.75. The equal-weight midpoint assigns 0.50 to the first category and 0.50 to the second. It comes from averaging each pair of corresponding probabilities. Figure one keeps the same category order for the two inputs and their midpoint.

The midpoint gives each normalized distribution the same weight. If the batches contain different numbers of records, pooling their raw observations would instead give the larger batch more influence. SciPy's distance routine normalizes the two input arrays individually if needed. That behavior is consistent with comparing proportions, provided the numbers are counts or valid nonnegative weights for the same categories and each input has a positive total.

Three side by side two-category histograms show P at 0.75/0.25, M at 0.50/0.50 and Q at 0.25/0.75.
All bars use the same probability scale and category order. Source: Zhilianhai editorial desk, original AI-assisted concept; no real product, event or measured data.

For example, counts of 30 and 10 in the first batch and 20 and 60 in the second produce the two proportion vectors above. Pooling the counts would give 50 of 120 records to the first category, about 0.4167. The equal-weight reference remains 0.50 there. The difference comes from choosing whether a batch or an individual observation supplies a unit of weight.

Compare each distribution with the same reference

The SciPy definition uses two Kullback–Leibler divergence terms, one from the first input to the midpoint and one from the second input to the midpoint. Their arithmetic mean is the equal-weight Jensen–Shannon divergence. Swapping the two inputs leaves the midpoint unchanged and merely exchanges the terms. This is the reason the resulting comparison is symmetric.

Lin's original paper presents the divergence through the entropy of a mixture compared with the weighted entropies of its inputs. Equal weights give the same mixture used in the SciPy definition. The two expressions describe the same equal-weight quantity from different perspectives. One emphasizes the shared comparison reference. The other emphasizes how mixture entropy changes relative to the average input entropy.

A zero in one batch leaves a nonzero midpoint when needed

Consider an outcome with positive probability in the first batch and zero probability in the second. The midpoint still gives that category half of the first probability. The term from the first batch therefore compares a positive probability against a positive reference. The category contributes zero to the other batch's divergence sum because that batch gives it zero weight.

If both batches give a category zero probability, there is no contribution from either side. This explains how the shared reference avoids the division-by-zero issue of a direct comparison from a positive bin to a zero bin. A zero category still has a role in the input definition. A missing field with no known category count is a different data condition and cannot simply be read as a zero observation count.

The square root distinguishes distance from divergence

For the two illustrative batches above, the equal-weight divergence is approximately 0.1887 with base-two logarithms. SciPy's jensenshannon returns the square root of that divergence, about 0.4344. A report that expects the distance and a report that expects divergence therefore need different fields even when their inputs match.

A curve on zero to one axes shows distance equals the square root of divergence, with 0.1887 mapped to 0.4344.
Identical distributions map to zero and disjoint supports map to one. Source: Zhilianhai editorial desk, original AI-assisted concept; no real product, event or measured data.

Identical distributions give zero. At the other extreme, when the inputs have disjoint support, the midpoint is half the relevant input on each occupied category. Every positive term then has a probability-to-midpoint ratio of two. With base-two logarithms, the divergence reaches one and its square root is also one. Using another logarithm base changes the numerical scale, so that endpoint needs the base stated alongside it.

A histogram distance describes a difference in composition

The output measures how far apart the represented proportions are under this definition. It does not identify which outcome changed unless the category values are examined, and the distance alone does not incorporate a batch's sample size. A robot data report can retain the category counts, normalization rule and logarithm base beside the distance. Those fields help a reader distinguish a large observed change in proportions from the strength of the evidence behind it.

The SciPy 1.15.3 distance reference documents the midpoint formula, normalization and return value. Lin's original divergence paper presents the entropy formulation and bound. See the robot statistics reference and technical article directory.

18028484626 CONTACT US

公司:智联海(惠州)科技有限公司

地址:惠州仲恺高新区陈江街道白云山工业大道 5 号六楼 601

Q Q:18028484626

Copyright © 2002-2026

粤xxx

咨询 在线留言 电话:18028484626
微信 微信扫码添加我