Skip to main content

A simple Python package for Hidden Markov Models

Project description

hiddenmarkov

PyPI

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

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_hiddenmarkov-0.1.4-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file python_hiddenmarkov-0.1.4.tar.gz.

File metadata

  • Download URL: python_hiddenmarkov-0.1.4.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for python_hiddenmarkov-0.1.4.tar.gz
Algorithm Hash digest
SHA256 c0481c3d51d9feae5bcbf59fa5241a6fb682b19ab0f923e225826e23d3242775
MD5 93a52aa437c381d5264333c1a56bf51d
BLAKE2b-256 34a01cb23e35b82f2812ef3088359f1cf800c86cc79465930798a8a1d7e3c81b

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_hiddenmarkov-0.1.4.tar.gz:

Publisher: publish.yml on CarlosCancino-Chacon/hiddenmarkov

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_hiddenmarkov-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for python_hiddenmarkov-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2c2ddbd1c1d3751037153d2886d42b43ad094954764fd3a9a0b717d509044dd2
MD5 aa288ccbe22d6ace7965fe75cc8d6687
BLAKE2b-256 66be70edd6409df9d660ed1c03635f3c537bbc0688a2b914279828e87b63f428

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_hiddenmarkov-0.1.4-py3-none-any.whl:

Publisher: publish.yml on CarlosCancino-Chacon/hiddenmarkov

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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