entropium
Information-theory primitives for Rust. All values are in bits (base-2 logarithm).
| Function | Formula |
|---|---|
entropy |
$H(X) = -\sum p(x)\log_2 p(x)$ |
joint_entropy |
$H(X,Y) = -\sum p(x,y)\log_2 p(x,y)$ |
conditional_entropy |
$H(X \mid Y) = H(X,Y) - H(Y)$ |
mutual_information |
$I(X;Y) = \sum p(x,y)\log_2 \frac{p(x,y)}{p(x),p(y)}$ |
Install
[]
= "0.1"
Usage
Every function comes in two variants:
- Checked — returns
Result<f64, InfoError>, errors on empty input or length mismatch. - Unchecked (
_unchecked) — panics on error, for when you've already validated inputs.
use ;
// Shannon entropy — fair coin = 1 bit
let x = vec!;
assert_eq!;
// Joint entropy — two independent fair bits = 2 bits
let y = vec!;
assert_eq!;
// Conditional entropy — H(X|X) = 0 (no uncertainty if you already know X)
assert_eq!;
// Mutual information — I(X;X) = H(X)
assert_eq!;
Works with any type that implements Eq + Hash:
let words = vec!;
let h = entropy.unwrap;
Error handling
use InfoError;
match entropy
match mutual_information
No dependencies
entropium has zero production dependencies.
License
MIT OR Apache-2.0