Jensen-Shannon Divergence

Decision Sciences
Introduced by
J. Lin
Year
1991
Type
Symmetric probability distribution dissimilarity
Family
Information-theoretic divergence

What does it do?

Jensen-Shannon divergence is a symmetric measure of how different two probability distributions are, built from Kullback-Leibler (KL) divergence.

It compares each distribution with their equal-weight mixture, so swapping the two inputs gives the same value. The divergence is non-negative, finite and bounded (with base-2 logarithms it lies between 0 and 1; with natural logarithms, between 0 and ln 2). Its square root is a metric, although the divergence itself does not satisfy the triangle inequality.

The intuition behind the method

KL divergence is asymmetric: KL(P||Q) and KL(Q||P) generally differ, and KL can be infinite when Q assigns zero probability to an outcome that P does not. Jensen-Shannon divergence avoids both problems by comparing P and Q each with their midpoint M = (P + Q) / 2, rather than with each other. Because M is positive wherever either P or Q is positive, each KL term stays finite. The result is an average of two directed comparisons, so neither distribution is treated as the reference. The cost is that the value lacks the direct information-theoretic reading that KL offers when one distribution models the other.

History

The measure is usually attributed to J. Lin, whose 1991 paper in IEEE Transactions on Information Theory introduced divergence measures based on Shannon entropy. That paper contrasts the new measures with the Kullback divergences, noting that they do not require absolute continuity of the distributions involved, and characterises them by nonnegativity, finiteness, semiboundedness and boundedness. It also relates them through bounds to the variational distance and to the probability of misclassification error.

When to use it

Choose Jensen-Shannon divergence when two distributions over the same outcomes are to be compared, neither serves as a reference or model for the other, and a symmetric score that is always finite is needed. Typical inputs are normalised histograms, normalised term-frequency vectors, or class-probability outputs. Do not use it when one distribution is a model approximating a reference and the direction of the error matters; KL divergence is the more natural choice there. Do not use it on values that cannot be expressed as probability distributions. If a downstream algorithm requires a metric, use the square root of the divergence.

Limitations and considerations

  • The divergence itself does not satisfy the triangle inequality, so it cannot be substituted directly into methods that need a metric.
  • There is no reference direction, so the value does not express how much information is lost when one distribution is used to approximate the other.
  • The numerical scale depends on the logarithm base; values computed with different bases are not directly comparable.
  • Each pair comparison requires two KL evaluations against the mixture, which adds cost when many distribution pairs are compared.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Symmetric by construction: JS(P||Q) = JS(Q||P), because both inputs enter through the same mixture M and the same 0.5 weight.
  • Finite for any pair of probability distributions, because M is positive wherever P or Q is, so each KL term is defined.
  • Non-negative and zero only when P and Q are identical, so the value can be read as a dissimilarity score.
  • Its square root is a metric, which allows use with distance-based methods that require the triangle inequality.

Applications

  • Comparing two estimated class-probability or topic distributions when neither serves as the reference.
  • Comparing normalised histograms or feature distributions of two samples.
  • Measuring similarity between two normalised word-frequency distributions of documents.
  • Scoring the divergence between two alternative probability assessments in a decision model where neither is the baseline.

How it works

How it works

1

Check that P and Q are non-negative vectors over the same set of outcomes, each summing to 1. If the inputs are raw counts or scores, divide each by its sum first.

Formula
P=(p_1,\dots,p_n),\; Q=(q_1,\dots,q_n),\; p_i,q_i\ge 0,\; \sum_i p_i=\sum_i q_i=1
2

Form the equal-weight mixture M = (P + Q) / 2, then compute the KL divergence of P to M and of Q to M. In JS(P, Q) = 0.5 * KL(P||M) + 0.5 * KL(Q||M), each KL term carries weight 0.5.

Formula
M=\tfrac{1}{2}(P+Q)
3

Add the two weighted terms to obtain the divergence. The value is symmetric in P and Q, non-negative, and zero only when P and Q are identical. It is bounded: with base-2 logarithms the maximum is 1, and with natural logarithms it is ln 2, so the logarithm base sets the scale. No universal cut-off separates 'similar' from 'different' distributions; compare values only within one logarithm base and one normalisation scheme, and calibrate any threshold to the application. It is the square root of this value, not the value itself, that is a metric.

Formula
\mathrm{JS}(P,Q)=\tfrac{1}{2}\,\mathrm{KL}(P\,\|\,M)+\tfrac{1}{2}\,\mathrm{KL}(Q\,\|\,M),\quad \mathrm{KL}(P\|M)=\sum_i p_i\log\frac{p_i}{m_i}

Common pitfalls

  • Reporting the divergence as if it were a metric; when a metric is required, take the square root first.
  • Passing raw counts or unnormalised scores as if they were probabilities; normalise each vector to sum to 1.
  • Assuming the measure is directional like KL; swapping the inputs does not change the result.
  • Comparing values produced with different logarithm bases, which changes the numerical scale.

Frequently asked questions

How does Jensen-Shannon differ from Kullback-Leibler divergence?

KL divergence is asymmetric and can be infinite when one distribution assigns zero probability to an outcome that the other assigns positive probability. Jensen-Shannon divergence is symmetric and always finite, because each KL term is taken against the mixture M, which is positive wherever either input is positive. KL remains more natural when one distribution models another, since its value has a direct information-theoretic reading.

Is Jensen-Shannon divergence a true metric?

No. The divergence is non-negative, zero exactly when P and Q are identical, and symmetric, but it does not satisfy the triangle inequality. Its square root does satisfy the metric properties, so take the square root when a metric is required.

Can I use Jensen-Shannon with non-probability vectors?

Not directly. The inputs must be non-negative and sum to 1. Divide each vector by its sum to obtain a probability distribution; the result depends on that normalisation choice.

How does Jensen-Shannon handle zero probabilities?

Zero entries do not make the divergence undefined. Where P is zero, its contribution to the KL term is zero by the standard convention, and the mixture M remains positive wherever Q is positive. Inputs must still be valid, normalised distributions.

Related methods

Sources

  1. Lin, J. (1991). Divergence measures based on the Shannon entropy. IEEE Transactions on Information Theory, 37(1), 145-151.

    Open DOI reference
  2. Cover, T. M., & Thomas, J. A. (1991). Elements of Information Theory. Wiley-Interscience.

    Open DOI reference