komm.binary_entropy
Computes the binary entropy function. For a given probability $p$, it is defined as $$ \Hb(p) = p \log_2 \frac{1}{p} + (1 - p) \log_2 \frac{1}{1 - p}, $$ and corresponds to the entropy of a Bernoulli random variable with parameter $p$.
Parameters:
-
p
(float
) –A probability value. It must satisfy $0 \leq p \leq 1$.
Returns:
-
float
–The value of the binary entropy function $\Hb(p)$.
Examples:
>>> [komm.binary_entropy(p) for p in [0.0, 0.25, 0.5, 0.75, 1.0]]
[0.0, 0.8112781244591328, 1.0, 0.8112781244591328, 0.0]