Code Monkey home page Code Monkey logo

hmm's Introduction

Hidden Markov Model

Crates.io Crates.io docs.rs

hmm is an early-stage open-source project. It means that API can change at any time. If you think that this library can help you, then let me know. We can discuss future direction and try to stabilize the API.

Features

  • Viterbi MAP estimation

Example

Lets say that we have 2 coins:

  • Fair which generates H (Head) and T (Tails) with probability of 1/2
  • Biased - with probabilities H: 1/4, T: 3/4

We also know that after each toss we can switch coin with the probability of

  • Use the same coin: 3/4
  • Switch coin: 1/4

First time we select coin with probability of 1/2

Using this library we can answer the following question:

Given the observations 'H H T T T' which coins were used during each toss?

Lest build HMM model and check the answer:

extern crate hmm;

use hmm::models::{HiddenMarkov};


fn main() {
    // 50%:50% chance to start at either coin
    let initials = vec![0.5, 0.5];

    // state transitions between coins:
    //   3/4 to stay on same coin (on matrix diagonals)
    //   1/4 chance to switch
    let st = vec![ vec![0.75, 0.25],
                   vec![0.25, 0.75]];

    // observation probabilities for each coin:
    //    first coin is fair, second one is biased
    let obs = vec![ vec![0.5, 0.5],
                    vec![0.25, 0.75]];

    // generate the HMM model
    let hmm = HiddenMarkov::new(initials, st, obs).unwrap();
    let coins = hmm.map_estimate(vec![0, 0, 1, 1, 1]);
    println!("Coins used: {:?}", coins);
}

For more check Examples.

License

Licensed under either of

at your option.

Contributions

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

hmm's People

Contributors

juleskers avatar klangner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

holtgrewe

hmm's Issues

Implementation of forward and backward algorithm

Hi

I found your library and it appears to be the only HMM library in Rust. It's a bit of a shame that only viterbi is implemented and I'll see whether I can find the time and imement the forward backward algorithm.

Cheers

Fix the documentation

  • Add example to the module.
  • Check function descriptions.
  • Hide not essential functions

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.