CalcWorldHub
Free online calculator · no signup

Bernoulli KL divergence calculator

This measure compares probability model P with model Q. Reversing P and Q can change the result, so keep the direction explicit.

A better way to figure it out
Clear
inputs.
∑
Clear result · useful details
Free calculatorNo signup ✓

Related calculators

Use these tools when your question extends to a neighboring part of the same calculation.

Browse statistics tools →

Bernoulli KL divergence calculator — Statistics inputs and calculation method
Bernoulli KL divergence calculator: inputs and calculation method.

How to use this calculator

Compare two Bernoulli event-probability models with directed Kullback–Leibler divergence in natural-log units (nats).

  1. Event probability in P (0–1) Event probability in Q (0–1)
  2. Read the worked example below to check the expected input format and result.
  3. Compare another scenario by changing one input at a time. Use Reset to return to the starting values.
Calculation guide

Bernoulli KL divergence calculator

This measure compares probability model P with model Q. Reversing P and Q can change the result, so keep the direction explicit.

Inputs and units

  • Event probability in P (0–1)
  • Event probability in Q (0–1)

Formula and method

Formula: Dₖₗ(P‖Q) = p ln(p/q) + (1−p) ln((1−p)/(1−q)). Natural logarithms return nats.

Worked example

For p = 0.7 and q = 0.5, Dₖₗ = 0.7 ln(1.4) + 0.3 ln(0.6) ≈ 0.0823 nats.

Interpreting the result

Zero means the two Bernoulli distributions match. A larger value means more directed information loss when Q is used to represent P; it is not a distance because it is asymmetric.

Assumptions and limits

Both values are probabilities. The current form accepts 0 ≤ p ≤ 1 and 0 < q < 1 to keep the displayed result finite; cases with q at an endpoint may yield an infinite divergence.

Sources and method notes

  • SciPy defines relative entropy using x ln(x/y), including boundary conventions; the Bernoulli formula is the two-outcome sum. SciPy: relative entropy

Frequently asked questions

Does swapping P and Q preserve the result?

Generally no. KL divergence is directional, so D(P‖Q) can differ from D(Q‖P).

Why are results in nats?

The formula uses natural logarithms. Using base-2 logarithms would express the same comparison in bits.

How do I use the Bernoulli KL divergence calculator?

Event probability in P (0–1) Event probability in Q (0–1)

What is a worked example of Bernoulli KL divergence?

For p = 0.7 and q = 0.5, Dₖₗ = 0.7 ln(1.4) + 0.3 ln(0.6) ≈ 0.0823 nats.

What does the Bernoulli KL divergence calculator calculate?

Compare two Bernoulli event-probability models with directed Kullback–Leibler divergence in natural-log units (nats).