hmmm

Crates.iohmmm
lib.rshmmm
version0.2.0
sourcesrc
created_at2019-02-10 17:04:43.670185
updated_at2020-09-19 18:51:39.747438
descriptionHidden Markov Models in Rust
homepage
repositoryhttps://github.com/paulkernfeld/hmmm
max_upload_size
id113928
size46,434
Paul Kernfeld (paulkernfeld)

documentation

https://docs.rs/hmmm

README

🤔 hmmm 🤔

Hidden Markov Models in Rust.

This library contains a Rust implementation of a time-invariant Hidden Markov model with discrete observations. It includes maximum likelihood estimation via the Baum-Welch expectation-maximization algorithm and hidden state inference via the Viterbi algorithm.

See hmmm::HMM for detailed documentation on how to work with this library.

Below, the HMM is trained to recognize the pattern 001001001...

use hmmm::HMM;
use ndarray::{array, Array1};
use rand::SeedableRng as _;

let training_ys = array![0, 0, 1, 0, 0, 1, 0];
let mut rng = rand::rngs::StdRng::seed_from_u64(1337);
let hmm = HMM::train(&training_ys, 3, 2, &mut rng);
let sampled_ys: Array1<usize> = hmm.sampler(&mut rng)
    .map(|sample| sample.y)
    .take(10)
    .collect();
assert_eq!(array![0, 0, 1, 0, 0, 1, 0, 0, 1, 0], sampled_ys);

Building

This project uses cargo-make. See Makefile.toml for a full list of build commands, but the main useful command for this project is cargo make all.

There is a small amount of benchmarking functionality gated by the benchmark feature.

Notes

Sections 17.3 and 17.4 of Machine Learning a Probabilistic Perspective by Kevin Murphy, 2012 were invaluable as a reference, as was section 13.2 of Pattern Recognition and Machine Learning by Christopher Bishop, 2016.

I have attempted to make the math notation readable both as rendered HTML and from the source code. The notation is strongly inspired by the Wikipedia page on the Baum-Welch algorithm.

License: MIT/Apache-2.0

Commit count: 17

cargo fmt