klDiv
-
constexpr double klDiv(const std::vector<Complex> &X, const std::vector<Complex> &Y) noexcept
Calculates the Kullback–Leibler (KL) divergence [1] of two complex sequences.
Parameters
Returns
- double
A real number.
In information theory, the KL divergence of two discrete probability distributions is defined as:
\[\DeclareMathOperator\KL{KL}
D_{\KL}(P || Q) = -\sum_{x \in \mathcal{X}}P(x)\log(\frac{P(x)}{Q(x)})\]
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 << klDiv(X, Y) << "\n";
Output:
0
References