klBern#

statrl.settings.utils.klBern(x, y)[source]#

Kullback-Leibler divergence between two Bernoulli distributions.

\[\mathrm{kl}(x, y) = x \log\frac{x}{y} + (1-x)\log\frac{1-x}{1-y}\]
Parameters:
  • x (float) – Means in \([0, 1]\). Both are clipped into \([\varepsilon, 1-\varepsilon]\) with eps = 1e-15 so the divergence stays finite at the boundary.

  • y (float) – Means in \([0, 1]\). Both are clipped into \([\varepsilon, 1-\varepsilon]\) with eps = 1e-15 so the divergence stays finite at the boundary.

Returns:

The divergence.

Return type:

float

See also

klGauss, klPoisson, klExp

Examples

>>> round(klBern(0.5, 0.5), 12)
0.0
>>> klBern(0.5, 0.9) > 0
True