entropy
-
constexpr double entropy(const std::vector<Complex> &X) noexcept
Calculates the discrete entropy [1] of a complex sequence.
Parameters
Returns
- double
A real number.
In information theory, the entropy of a discrete random variable is defined as:
\[\DeclareMathOperator\H{H}
H(X) = -\sum_{x \in \mathcal{X}}p(x)\log p(x)\]
The sequence \(X\) is normalized beforehand. The summand is defined to be \(0\) for \(p(x) = 0\) and the summation is set to \(-\infty\) if a negative probability is present.
Example
std::vector<Complex> X = {1 + 1_j, 2, 3, 4, 5};
std::cout << entropy(X) << "\n";
Output:
1.48975
References