entropy (Continuous)
-
constexpr double entropy(Complex (*fr)(Complex), Complex (*fi)(Complex), double a, double b) noexcept
Calculates the continuous entropy [1] of a function.
Parameters
Returns
- double
A real number.
In information theory, the entropy of a continuous random variable is defined as:
\[\DeclareMathOperator\H{H}
H(X) = -\int_{\mathcal{X}}f(x)\log f(x)dx\]
Example
auto pdfRe = [](Complex z) { return exp(-z * z); }; // Example PDF.
auto pdfIm = [](Complex z) { return exp(-z * z); }; // Example PDF.
std::cout << entropy(pdfRe, pdfIm, -INF.real(), INF.real()) << "\n";
std::cout << -std::sqrt(M_PI) << "\n";
Output:
-1.77102
-1.77245
References