Skip to content
ENExplore Calculators

Jensen-Shannon Divergence Calculator

Calculate the symmetric Jensen-Shannon divergence between two probability distributions.

About Jensen-Shannon Divergence Calculator

Jensen-Shannon divergence fixes KL divergence's asymmetry by measuring both distributions against their midpoint mixture M = (P+Q)/2: JSD = 0.5·KL(P‖M) + 0.5·KL(Q‖M). Because it averages two KL terms computed against a shared reference, JSD(P,Q) = JSD(Q,P) always — it is symmetric — and it is also bounded (between 0 and ln(2) when using natural log), unlike KL divergence which can grow unboundedly large. Its square root, √JSD, is additionally a true mathematical distance metric, which makes it popular for comparing distributions in generative models like GANs.

Formula

JSD(P, Q) = 0.5 × KL(P||M) + 0.5 × KL(Q||M), where M = (P + Q) / 2

P
First probability distribution
Q
Second probability distribution
M
Midpoint mixture distribution (P+Q)/2
KL
Kullback-Leibler divergence

Worked example

With the default values below, Jensen-Shannon Divergence Calculator returns Jensen-Shannon Divergence of 0.027866. Change any input above and every figure here is recalculated in your browser.

Inputs used

Distribution P (comma-separated)
0.4, 0.3, 0.2, 0.1
Distribution Q (comma-separated)
0.25, 0.25, 0.25, 0.25

Results

Jensen-Shannon Divergence
0.027866
JS Distance (√JSD)The square root of JSD is a true metric (satisfies the triangle inequality).
0.166930
KL(P‖M)
0.029641
KL(Q‖M)
0.026090

Step by step

  1. 1Mixture distribution: M = (P + Q) / 2= 0.3250, 0.2750, 0.2250, 0.1750
  2. 2KL(P‖M)= 0.029641
  3. 3KL(Q‖M)= 0.026090
  4. 4JSD: 0.5 × KL(P‖M) + 0.5 × KL(Q‖M)= 0.027866

Assumptions and limits

  • The result is derived only from the 2 inputs listed above. Anything not among them is not part of the calculation.
  • In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
  • Figures are rounded for display to 6 decimal places, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.

How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.

Frequently Asked Questions

Why use JSD instead of KL divergence?

JSD is symmetric (JSD(P,Q) = JSD(Q,P)) and always finite/bounded, whereas KL divergence is asymmetric and can become infinite when Q assigns near-zero probability to an event P considers likely — JSD avoids this by comparing both distributions to their shared mixture instead of directly to each other.

What is the maximum possible value of JSD?

Using natural log, JSD is bounded between 0 and ln(2) ≈ 0.693, reached when P and Q have completely disjoint support (no overlapping probability mass) — a value of 0 means the distributions are identical.

Where is Jensen-Shannon divergence used?

It's the theoretical basis for the original GAN (Generative Adversarial Network) loss function, and is also commonly used to measure semantic similarity between topic distributions in NLP and to detect data/label drift between two sampled datasets.

Jensen-Shannon Divergence Calculator | Calcrivo