A simple Python package for Hidden Markov Models
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
python_hiddenmarkov-0.1.4.tar.gz
(10.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters