Statistics & probability

Jensen–Shannon divergence calculator from probabilities

Compare aligned categorical probability vectors with Jensen–Shannon divergence and its square-root distance in bits or nats.

Your numbers

Use 1–50 probabilities in category order, each between zero and one, summing to one.
Use the same category order and count as P; probabilities must sum to one.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Jensen–Shannon divergence compares two probability distributions through their equal mixture. Each distribution is compared with that mixture, and the two relative-entropy contributions are averaged. The result is symmetric in P and Q and remains finite when their positive categories differ. This page returns both divergence and its square root, with a declared logarithm base and an aligned category-contribution table.

THE FORMULAM=(P+Q)/2; JS(P,Q)=[KL(P||M)+KL(Q||M)]/2; distance=√JS.

A worked example

For P=(1,0) and Q=(0,1), the equal mixture is (1/2,1/2). Each distribution contributes one bit of KL divergence to that mixture, so JS is one bit and its square-root distance is one. With natural logarithms, the divergence becomes ln(2)≈0.69314718 and the distance becomes √ln(2)≈0.83255461. Changing the log base changes the numeric units, not the distributions.

Good to know

Supports 1–50 aligned categories. Both vectors must already sum to one within 10⁻¹²; arbitrary counts are not silently normalized. Zero-probability terms follow their limiting value without pseudocounts. The square root is the distance, while the unrooted quantity is divergence. No confidence interval or hypothesis-test p-value is inferred from the vectors, and continuous densities are not discretized automatically.

Category alignment matters as much as normalization

The first entry of P and the first entry of Q must represent the same outcome. Reordering one vector without reordering the other can turn identical labelled distributions into apparently different ones. A sum-to-one check cannot detect that labeling error. Keep a category key beside the worksheet and inspect the table’s aligned rows before interpreting the contributions or comparing several candidate models.

The equal mixture has positive mass wherever either input has positive mass. A category absent from P but present in Q therefore does not cause division by a zero mixture probability. When both inputs assign zero mass to a category, its contribution is zero. Adding arbitrary pseudocounts would change the distributions and their divergence; the calculator keeps literal zeros rather than modifying the model silently.

Disjoint categorical distributions share an equal mixture and have one bit of divergenceP → equal mixture M ← QP=(1,0)M=(½,½)Q=(0,1)JS = 1 bit; distance = √1 = 1
P = (1,0), M = (1/2,1/2), Q = (0,1). Each input has one bit of KL divergence from M, giving JS = 1 bit and square-root distance 1. The stacked bars illustrate category shares.

The Wasserstein distance calculator for two samples uses coordinate distances, while this categorical divergence depends on aligned probability shares.

Divergence and distance are related but have different numerical scales

Some libraries return the square root and call it Jensen–Shannon distance. Others report the unrooted divergence. Comparing those outputs without checking the convention can create an apparent discrepancy even when both calculations are correct. This page labels both values. Base-two divergence lies between zero and one for normalized inputs, while the natural-log maximum is ln(2); the corresponding square-root bounds differ too.

The vectors are treated as fixed probability distributions. When they come from finite observed counts, differences may reflect sampling variability as well as population differences. A large descriptive divergence does not by itself establish significance, causation or a poor prediction process. The discrete Shannon entropy calculator summarizes one distribution; this page instead compares two distributions through a common mixture and returns category-specific contributions.

A few questions, answered

Can I enter raw category counts?

Convert them to probabilities first. This page requires normalized probability vectors so that the model and units are explicit.

Does a zero entry require adding a tiny constant?

No. The mixture-based formula handles zeros using the appropriate limiting contribution. Adding a constant would change the question.

Find your calculator

Start typing to explore the library.