jsDiv (Continuous)

constexpr double jsDiv(Complex (*fr)(Complex), Complex (*fi)(Complex), Complex (*gr)(Complex), Complex (*gi)(Complex), double a, double b) noexcept

Calculates the continuous Kullback-Leibler (KL) divergence [1] of a function.

Parameters

Complex (*fr)(Complex)

The PDF of the first real distribution.

Complex (*fi)(Complex)

The PDF of the first imaginary distribution.

Complex (*gr)(Complex)

The PDF of the second real distribution.

Complex (*gi)(Complex)

The PDF of the second imaginary distribution.

double a

A real number.

double b

A real number.

Returns

double

A real number.

In information theory, the Jensen-Shannon divergence of two continuous probability distributions is defined as:

\[\DeclareMathOperator\JSD{JSD} JSD(P || Q) = \frac{1}{2}D(P || M) + \frac{1}{2}D(Q || M)\]

where \(M = \frac{1}{2}(P + Q)\) and where D(P || Q) is the Kullback-Leibler divergence.

Example

auto pdfRe1 = [](Complex z) { return exp(-z * z); }; // Example real PDF 1.
auto pdfRe2 = [](Complex z) { return exp(-z * z); }; // Example real PDF 2.
auto pdfIm1 = [](Complex z) { return exp(-z * z); }; // Example im PDF 1.
auto pdfIm2 = [](Complex z) { return exp(-z * z); }; // Example im PDF 2.
std::cout << jsDiv(pdfRe1, pdfIm1, pdfRe2, pdfIm2, -INF.real(), INF.real()) << "\n";

Output:

-1.60699e-07

References