hiddenmarkov
A simple Python library for Hidden Markov Models.
This library was created for educational purposes and does not aim to have the most efficient implementation.
Setup
Simple installation
pip install python-hiddenmarkov
Develop version
git clone https://github.com/neosatrapahereje/hiddenmarkov.git
cd hiddenmarkov
pip install -e .
Usage
Example from Wikipedia
import numpy as np
from hiddenmarkov import CategoricalObservationModel, ConstantTransitionModel, HMM
obs = ("normal", "cold", "dizzy")
observations = ("normal", "cold", "dizzy")
states = ("Healthy", "Fever")
observation_probabilities = np.array([[0.5, 0.1], [0.4, 0.3], [0.1, 0.6]])
transition_probabilities = np.array([[0.7, 0.3], [0.4, 0.6]])
observation_model = CategoricalObservationModel(
observation_probabilities, obs
)
init_distribution = np.array([0.6, 0.4])
transition_model = ConstantTransitionModel(
transition_probabilities, init_distribution
)
hmm = HMM(observation_model, transition_model, state_space=states)
path, prob = hmm.find_best_sequence(observations, log_probabilities=False)
print("Example Wikipedia")
print("Best sequence", path)
print("Expected Sequence", ["Healthy", "Healthy", "Fever"])
print("Sequence probability", prob)
print("Expected probability", 0.01512)
Licence
The code in this package is licensed under the MIT Licence. For details, please see the LICENSE file.
Metadata
Release files for python-hiddenmarkov 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| python_hiddenmarkov-0.1.4.tar.gz | 10.2 kB | With provenance |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| python_hiddenmarkov-0.1.4-py3-none-any.whl | Python 3 | none | any |
Total release size: 18.9 kB
Security for python-hiddenmarkov 0.1.4
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.
Full provenance
All 2 files in this release have been 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.