Calculators

Jensen–Shannon Distance Calculator

Calculate Jensen–Shannon distance and divergence in bits between probability distributions with automatic normalization, privately in your browser.

Enter matching non-negative counts, weights or probabilities. Each vector is normalized independently to sum to 1. Separate values with spaces, commas or semicolons. Each vector allows 1–10000 values and 200000 characters; nonzero values must be between 1e-100 and 1e100. At least one value per vector must be positive. Coordinates must represent the same categories in the same order. Calculation runs locally in your browser.

Your Jensen–Shannon distance will appear here.

How Jensen–Shannon distance works

Jensen–Shannon divergence is JSD(P, Q) = [KL₂(P ∥ M) + KL₂(Q ∥ M)] / 2, where M = (P + Q) / 2. This calculator uses equal mixture weights and base-2 logarithms, so divergence ranges from 0 to 1 bit. Distance is the square root of divergence and ranges from 0 to 1. Matching distributions give zero; disjoint support gives one. For A = (1, 0) and B = (0, 1), both results are 1. Each vector is independently normalized, so proportional counts such as (1, 3) and (2, 6) give zero. This compares proportions rather than absolute totals. Coordinates must represent the same categories in the same order. Zero entries are supported, including shared zeros, but each vector needs a positive total. Enter 1 to 10000 non-negative numbers separated by spaces, commas or semicolons, up to 200000 characters per vector. Scientific notation is supported; nonzero values must be between 1e-100 and 1e100. Scaled normalization avoids overflowing totals; a symmetric calculation reduces cancellation near equality. Results use browser floating-point arithmetic and show up to 12 significant digits, so extremely small differences may round away. All calculations run locally.

Frequently Asked Questions

Everything you need to know about this tool, how it works, and privacy.

What is the difference between distance and divergence?

Distance is the square root of Jensen–Shannon divergence. The distance is a metric; the divergence itself is not. Both range from zero to one with the base-2 equal-weight convention used here.

Must my values sum to one?

No. Each vector is normalized independently. Enter matching non-negative counts, weights or probabilities with at least one positive value per vector.

Are zeros allowed?

Yes. Zero terms contribute zero, and the mixture ensures finite results even when the distributions have disjoint support.

Which logarithm base is used?

Base 2 is used, so divergence is reported in bits. Natural logarithms would instead give a maximum divergence of ln(2).

What input limits apply?

Enter matching vectors of 1 to 10000 values, up to 200000 characters each. Nonzero values must be from 1e-100 to 1e100. Results show up to 12 significant digits and are subject to floating-point rounding.