GithubHelp home page GithubHelp logo

berlinchen7 / geomhmm Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 217 KB

Trainer for manifold-valued Hidden Markov Models

License: MIT License

Python 100.00%
hmm geometry information-geometry spd-manifold poincare-disk gaussian-mixture-models

geomhmm's Introduction

geomhmm: Geometric Hidden Markov Models

MIT license

This is an implementation of a learner for the generalized Hidden Markov Models, where the observed random variables are manifold-valued (we call such model a geometric hidden Markov model).

Getting started

Testing the code in your local environment is as simple as:

  1. Clone this repository.
  2. Navigate to the corresponding directory in the terminal.
  3. Run pip install -r requirements.txt to install all dependencies.1
  4. Run python func_tests.py to do a smoke test of the code.

Of course, you may want to do the above in a virtual environment (see here or here if you're not familiar with Python's virtual environment). We developed the code in Python 3.8.12, so we recommend running the code in a similar Python version.

Here is an example on how to use the code:

from geomhmm import PoincareDiskGaussianHMM
from exp import gen_chain_Tupker2021

_, y, _ = gen_chain_Tupker2021() # Generate an example Poincare-disk-valued HMM
m = PoincareDiskGaussianHMM(S=3, max_lag=3, num_samples_K=500) # Initialize the learner
m.partial_fit(y) # Learning step
print(m.B_params, m.pi_inf_hat, m.P_hat) # Print the current estimates

What's inside

  • The file geomhmm.py is the meat of the code and contains the implementation of the learner itself. Currently we have EuclideanGaussianHMM, PoincareDiskGaussianHMM, and SPDGaussianHMM, which are learners for HMMs with observed values in Euclidean space / Poincare Disk / SPD matrices, respectively. The mixture estimation uses the approach outlined in Zanini et al., 2017, and the estimation for the transition matrix uses the method of moments algorithm which we adopted from Mattila et al., 2020.
    • In addition, the file extensions.py contains the variants of the learner, such as SPD_EM_GaussianHMM, which uses the expectation-maximization (EM) algorithm for mixture estimation in place of the Zanini et al., 2017 approach.2 To run the code for most of the learners in this file (including SPD_EM_GaussianHMM), one will need a valid Matlab license in order to use the Matlab engine for Python (see here for more details).
    • More documentations on how to initialize/use these learners to come.
  • The files randSPDGauss.py/randPoincGauss.py contain the code to sample a Gaussian distribution of SPD manifolds / Poincare Disk.
  • The file func_test.py contains a suite of examples used to test the implementation.
  • The file exp.py runs experiments that replicate the set-up used by Salem et al., 2021 and by Tupker et al., 2021.
    • For example, you can run python exp.py --mode Salem2021 --oname output --opath ./out --seed=202 --givenTrue False to replicate the set-up used by Salem et al., 2021 (the givenTrue flag controls whether the we want the learner to learn the emission probabilities/stationary distribution as well; False means we do want to learn those variables).
    • The directory exp_config_templates contains example config files used to run some of the experiments, such as hyperparameter tuning (hyp_tuning). More documentation about how to run each experiment to come.

Acknowledgement

The algorithm was developed by Berlin Chen, Dr. Cyrus Mostajeran, and Dr. Salem Said. The development for the implementation is still ongoing. Any feedback is appreciated.

Footnotes

  1. The file requirements-dev.txt contains packages that are strictly not needed for the learners, but are useful if one were to further develop/experiment with our implementation. To install these packages, simply run pip install -r requirements-dev.txt.

  2. The Matlab code for EM estimation and Riemannian gradient descent is currently proprietary and not publicly available. We are working to release a publicly available version.

geomhmm's People

Contributors

berlinchen7 avatar

Stargazers

 avatar

Watchers

 avatar  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.