Skip to main content

entr

Function entr 

Source
pub fn entr(x_i: f64) -> f64
Expand description

Elementwise function for computing the entropy

$$ \mathrm{entr}(x_i) = \begin{cases} -x_i \ln(x_i) & x_i > 0 \\ 0 & x_i = 0 \\ -\infty & \text{otherwise} \end{cases} $$

Translated from scipy.special.entr into pure Rust.

§Notes

This function is concave.

The origin of this function is in convex programming 1. Given a discrete probability distribution $p_1,\dotsc,p_n$, the definition of entropy in the context of information theory is

$$ H[ \{ p_i \} ] = \sum_{i} \mathrm{entr}(p_i). $$

§See also


  1. S. Boyd and L. Vandenberghe. Convex optimization. Cambridge University Press, 2004. https://doi.org/10.1017/CBO9780511804441 ↩