Skip to content

API Reference

entropium provides two families of functions: single-distribution measures (entropy variants) and two-distribution measures (divergences). All values are in bits.

Single-distribution measures

These functions take observed samples and characterise their uncertainty.

FunctionWhat it measures
entropyUncertainty of one variable — H(X)
joint_entropyTotal uncertainty of two variables together — H(X,Y)
conditional_entropyUncertainty of X once Y is known — H(XY)
mutual_informationInformation shared between two variables — I(X;Y)

Two-distribution measures

These functions compare two empirical distributions P and Q.

FunctionWhat it measures
kl_divergenceHow much P diverges from Q (asymmetric) — DKL(P|Q)
js_divergenceSymmetric, bounded "distance" between P and QJSD(P|Q)
cross_entropyCost of encoding P with a code optimised for QH(P,Q)

Error type

rust
pub enum InfoError {
    /// Any input slice is empty.
    EmptyInput,
    /// Two input slices have different lengths.
    LengthMismatch { left: usize, right: usize },
    /// P assigns positive probability to a value absent from Q,
    /// making the divergence infinite.
    UndefinedDivergence,
}

Relationships between functions

These identities hold exactly (up to floating-point precision) and are verified by the test suite:

H(X,Y) = H(X) + H(Y|X)          chain rule
H(X|Y) = H(X,Y) − H(Y)          conditional from joint
I(X;Y) = H(X) + H(Y) − H(X,Y)   mutual from marginals
I(X;Y) = H(X) − H(X|Y)          mutual from conditional
H(P,Q) = H(P) + D_KL(P‖Q)       cross-entropy decomposition

Released under the MIT OR Apache-2.0 License.