crossEntropy
-
constexpr double crossEntropy(const std::vector<Complex> &X, const std::vector<Complex> &Y) noexcept
Calculates the cross-entropy [1] of two complex sequences.
Parameters
Returns
- double
A real number.
In information theory, the cross-entropy of two discrete probability distributions is defined as:
\[H(p, q) = -\sum_{x \in \mathcal{X}}p(x)\log 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:
1.48975
References