Skip to main content

Discrete Hidden Markov Models with Numba

Project description

Hmmkay Build Status Documentation Status python versions

🤔👌

Discrete Hidden Markov Models with Numba

Hmmkay is a basic library for discrete Hidden Markov Models that relies on numba's just-in-time compilation. It supports decoding, likelihood scoring, fitting (parameter estimation), and sampling.

Hmmkay accepts sequences of arbitrary length, e.g. 2d numpy arrays or lists of iterables. Hmmkay internally converts lists of iterables into Numba typed lists of numpy arrays.

Installation

pip install hmmkay

Requires Python 3.6 or higher.

Examples

Scoring and decoding:

from hmmkay.utils import make_observation_sequences
sequences = make_observation_sequences(n_seq=100, n_observable_states=4, random_state=0)
hmm.fit(sequences)

from hmmkay.utils import make_proba_matrices
from hmmkay import HMM

init_probas, transition_probas, emission_probas = make_proba_matrices(
    n_hidden_states=2,
    n_observable_states=4,
    random_state=0
)
hmm = HMM(init_probas, transition_probas, emission_probas)

sequences = [[0, 1, 2, 3], [0, 2]]
hmm.log_likelihood(sequences)
-8.336
hmm.decode(sequences)  # most likely sequences of hidden states
[array([1, 0, 0, 1], dtype=int32), array([1, 0], dtype=int32)]

Fitting:

from hmmkay.utils import make_observation_sequences
sequences = make_observation_sequences(n_seq=100, n_observable_states=4, random_state=0)
hmm.fit(sequences)

Sampling:

hmm.sample(n_obs=2, n_seq=3)  # return sequences of hidden and observable states
(array([[0, 1],
        [1, 1],
        [0, 0]]), array([[0, 2],
        [2, 3],
        [0, 0]]))

Documentation

Docs are online at https://hmmkay.readthedocs.io/en/latest/

Benchmark

It should be faster than hmmlearn. Here's the result of the benchmark.py script on my laptop:

bench

Status

Highly experimental, API subjet to change without deprecation.

Development

The following packages are required for testing:

pip install pytest hmmlearn scipy

For benchmarks:

pip install matplotlib hmmlearn

For docs:

pip install sphinx sphinx_rtd_theme

For development, use pre-commit hooks for black and flake8.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

hmmkay-0.0.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file hmmkay-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: hmmkay-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.4

File hashes

Hashes for hmmkay-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 abdeb1a77a1bf8b9b9c4c245166dc47ccc97caa138edfdaecfdcd7387c0247ff
MD5 e25a34428b861d27b5d81199b645d886
BLAKE2b-256 a3149ba6a3ee319d99aa93b5bffaf6a5409f8deb9bd134cec18d6e2679ea1429

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page