Jensen-Shannon Divergence Calculator
Calculate the symmetric Jensen-Shannon divergence between two probability distributions.
Inputs
First distribution. Values are normalized to sum to 1 automatically.
Second distribution. Same length as P.
Jensen-Shannon Divergence
0.027866
JS Distance (√JSD)
0.166930
The square root of JSD is a true metric (satisfies the triangle inequality).
KL(P‖M)
0.029641
KL(Q‖M)
0.026090
Step by step
Mixture distribution: M = (P + Q) / 2
M_i = (P_i + Q_i) / 2
= 0.3250, 0.2750, 0.2250, 0.1750
KL(P‖M)
Σ P(x) × ln(P(x)/M(x))
= 0.029641
KL(Q‖M)
Σ Q(x) × ln(Q(x)/M(x))
= 0.026090
JSD: 0.5 × KL(P‖M) + 0.5 × KL(Q‖M)
0.5 × 0.029641 + 0.5 × 0.026090
= 0.027866
How it works
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
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.