Code Monkey home page Code Monkey logo

toyhmm.jl's Introduction

ToyHMM.jl

A simple Hidden Markov Model implementation in Julia. Intended mostly for educational purposes. Only supports discrete emission probabilities

I am developing HMM.jl for a more general-purpose module.

Installation

Pkg.clone("https://github.com/ahwillia/ToyHMM.jl.git")

Simple Example

using ToyHMM

n_states = 2
n_outputs = 3
hmm = dHMM(n_states,n_outputs)

println(hmm.A) # state-transition matrix (randomly initialized, rows sum to 1)
println(hmm.B) # emmission matrix (randomly initialized, rows sum to 1)
println(hmm.p) # initial state probabilities (randomly initialized)

o = [1,1,2,1,1,2,1,2,1,3,3,3,3,2,2,3,3,3] # example observation sequence

ch = baum_welch!(hmm,o) # fit model using Expectation-Maximization

println(ch) # log-likelihood values, convergence history

println(hmm.A) # fitted values of the hmm model
println(hmm.B)
println(hmm.p)

println(viterbi(hmm,o)) # most likely state sequence given hmm params

(also see test/runtests.jl for some examples)

How fast is it?

using ToyHMM

n_states = 2
n_outputs = 3

# create a very long output sequence
true_model = dHMM(n_states,n_outputs)
(s,o) = generate(true_model,100_000)

# try to recover similar params by fitting new model
fit_model = dHMM(n_states,n_outputs)
@time ch = baum_welch!(fit_model,o)

elapsed time: 7.958006041 seconds (4140814448 bytes allocated, 26.85% gc time)

References and Acknowledgements:

Michael Hamilton's implementation (python): http://www.cs.colostate.edu/~hamiltom/code.html

Guy Zyskind's implementation (python): https://github.com/guyz/HMM

Rabiner, Lawrence R. "A tutorial on hidden Markov models and selected applications in speech recognition." Proceedings of the IEEE 77.2 (1989): 257-286.

To Do (Variational Bayes):

MacKay DJC (1997). Ensemble Learning for Hidden Markov Models Technical report, University of Cambridge

MacKay DJC (1998). Choice of Basis for Laplace Approximation. Machine Learning. 33(1), 77-86.

Beal MJ (2003). Variational Algorithms for Approximate Bayesian Inference. PhD Thesis, University College London

toyhmm.jl's People

Contributors

ahwillia avatar

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.