#frequency #entropy #calculate #histogram #iterator #shannon #b-tree-map-histogram

entropiter

A no-dep iterator-compatible frequency and Shannon entropy calculator

3 unstable releases

0.2.1 Mar 14, 2022
0.2.0 Mar 14, 2022
0.1.0 Mar 14, 2022

#1147 in Math

Download history 13/week @ 2024-02-22 3/week @ 2024-02-29 27/week @ 2024-03-28 28/week @ 2024-04-04

55 downloads per month

MIT license

7KB
182 lines

Entropiter

Easily calculate the frequency and probability of symbol occurrence in an iterator, and effortlessly calculate the entropy.

Usage

To use this library you only need an iterator containing the symbol of your choice, and the choice of histogram backing store to accumulate into. The generic backing stores available are BTreeMapHistogram and HashMapHistogram, while for u8 symbols ByteHistogram is also available.

Example

use entropiter::{FrequencyIteratorExt, HashMapHistogram};

fn main() {
    let shannon_entropy = "shannon".chars().shannon::<HashMapHistogram<_>>().entropy();
    println!("entropy: {}", shannon_entropy);
}

No runtime deps