Skip to main content

A simple Python package for Hidden Markov Models

Project description

hiddenmarkov

PyPI version

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


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.3.tar.gz (8.8 kB view details)

Uploaded Source

File details

Details for the file python-hiddenmarkov-0.1.3.tar.gz.

File metadata

  • Download URL: python-hiddenmarkov-0.1.3.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.11.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.10

File hashes

Hashes for python-hiddenmarkov-0.1.3.tar.gz
Algorithm Hash digest
SHA256 39a2a34917c9bc009146cebb4955a0d23743dba7bcb13a6ab44529108bafbe0e
MD5 5476ed20ea9bf005d5f4684107b0c208
BLAKE2b-256 91315185a1d366b314924977fba773bee745b9eb2cf51085b4fc42f72075e089

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