Worked Example: Worked Mathematical Example: KL & Jensen-Shannon Divergence
Compute H(P), Cross-Entropy H(P,Q), D_KL(P||Q), and symmetric Jensen-Shannon Divergence.
- Specify the function parameters, matrix entries, or confusion matrix counts.
- Apply the closed-form or iterative formula: D_KL(P || Q) = Σ P(i) × log₂(P(i) / Q(i)); JSD = 0.5·D_KL(P || M) + 0.5·D_KL(Q || M), M = (P+Q)/2.
- Examine the primary result, error bounds, and 3 interactive SVG plots.
Result: Computes KL & Jensen-Shannon Divergence via D_KL(P || Q) = Σ P(i) × log₂(P(i) / Q(i)); JSD = 0.5·D_KL(P || M) + 0.5·D_KL(Q || M), M = (P+Q)/2.
Mathematics & Statistics · Machine Learning & Classification Metrics
Kullback-Leibler Divergence D_KL(P || Q), Cross-Entropy & Jensen-Shannon Calculator: inputs, method, and how to read the result
Compute H(P), Cross-Entropy H(P,Q), D_KL(P||Q), and symmetric Jensen-Shannon Divergence.
Choose inputs for the case you are checking
The defaults are illustrative. Replace them with values for your case and keep the units shown beside each field.
- True Distribution P1: True probability P(1) of outcome 1 (P(0) = 1 − P(1)).
- Model Distribution Q1: Approximating probability Q(1) of outcome 1 (Q(0) = 1 − Q(1)).
What the calculation includes
With the default values shown, Forward KL Divergence D_KL(P || Q) is 0.184 bits. The calculation follows KL & Jensen-Shannon Divergence Formula; the formula and variable definitions above show how the inputs combine.
One-input check: With the other defaults held constant, changing True Distribution P1 from 0.7 P(1) to 0.77 P(1) changes Forward KL Divergence D_KL(P || Q) from 0.184 bits to 0.307 bits. This is a comparison inside the calculator's stated model, not a prediction.
Where to use caution
- Uses exact analytical or standard numerical analysis formulations from NIST DLMF.
- Double-precision floating-point arithmetic has ~15–17 significant decimal digits of precision.
Scope: Global Mathematical & Statistical Standard Check the assumptions and limitations against your situation before relying on the estimate.
More in Mathematics & Statistics: Scientific Calculator, Statistics & Standard Deviation Calculator, Permutations, Combinations, Probability, Sample Size & P-Value Calculator.