Hmmkay

🤔👌
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:
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.
Metadata
Release files for hmmkay 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hmmkay-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for hmmkay-0.0.1-py3-none-any.whl |
Release files / hmmkay-0.0.1-py3-none-any.whl
| Download URL | hmmkay-0.0.1-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
abdeb1a77a1bf8b9b9c4c245166dc47ccc97caa138edfdaecfdcd7387c0247ff
|
|
BLAKE2b-256 checksum How to use checksums |
a3149ba6a3ee319d99aa93b5bffaf6a5409f8deb9bd134cec18d6e2679ea1429
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for hmmkay 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.