binaryEntropy
-
inline double binaryEntropy(const double p) noexcept
Calculates the discrete binary entropy [1] of a probability.
Parameters
- const double p
A real number between 0 and 1 inclusive.
Returns
- double
A real number.
The binary entropy of a probability \(p\) is defined as follows:
\[\DeclareMathOperator\H{H}
H(X) = -p\log(p) + (1 - p)\log(1 - p)\]
Example
std::cout << binaryEntropy(0.5) << "\n";
Output:
0.693147
References