jsDiv

constexpr double jsDiv(const std::vector<Complex> &X, const std::vector<Complex> &Y) noexcept

Calculates the Jensen-Shannon divergence [1] of two complex sequences.

Parameters

const std::vector<Complex> &X

A complex sequence.

const std::vector<Complex> &Y

A complex sequence.

Returns

double

A real number.

In information theory, the Jensen-Shannon divergence of two discrete probability distirbution 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. Both sequences are normalized beforehand.

Example

std::vector<Complex> X = {1, 2, 3, 4, 5};
std::vector<Complex> Y = {1, 2, 3, 4, 5};

std::cout << jsDiv(X, Y) << "\n";

Output:

0

References