# hiddenmarkov
[![PyPI version](https://badge.fury.io/py/python-hiddenmarkov.svg)](https://badge.fury.io/py/python-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
```bash
git clone https://github.com/neosatrapahereje/hiddenmarkov.git
cd hiddenmarkov
pip install -e .
```
## Usage
Example from [Wikipedia](https://en.wikipedia.org/wiki/Viterbi_algorithm#Example)
```python
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](https://github.com/neosatrapahereje/hiddenmarkov/blob/main/LICENSE) file.
Raw data
{
"_id": null,
"home_page": "https://github.com/neosatrapahereje/hiddenmarkov",
"name": "python-hiddenmarkov",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "hmm hidden_Markov_models",
"author": "Carlos Cancino-Chac\u00f3n, Silvan Peter",
"author_email": "carloscancinochacon@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/91/31/5185a1d366b314924977fba773bee745b9eb2cf51085b4fc42f72075e089/python-hiddenmarkov-0.1.3.tar.gz",
"platform": null,
"description": "\n# hiddenmarkov\n\n[![PyPI version](https://badge.fury.io/py/python-hiddenmarkov.svg)](https://badge.fury.io/py/python-hiddenmarkov)\n\nA simple Python library for Hidden Markov Models.\n\nThis library was created for educational purposes and does not aim to have the most efficient implementation.\n\n## Setup\n\nSimple installation\n\n```\npip install python-hiddenmarkov\n```\n\nDevelop version\n```bash\ngit clone https://github.com/neosatrapahereje/hiddenmarkov.git\ncd hiddenmarkov\npip install -e .\n```\n\n## Usage\n\nExample from [Wikipedia](https://en.wikipedia.org/wiki/Viterbi_algorithm#Example)\n\n```python\nimport numpy as np\nfrom hiddenmarkov import CategoricalObservationModel, ConstantTransitionModel, HMM\n\nobs = (\"normal\", \"cold\", \"dizzy\")\nobservations = (\"normal\", \"cold\", \"dizzy\")\nstates = (\"Healthy\", \"Fever\")\nobservation_probabilities = np.array([[0.5, 0.1], [0.4, 0.3], [0.1, 0.6]])\ntransition_probabilities = np.array([[0.7, 0.3], [0.4, 0.6]])\n\nobservation_model = CategoricalObservationModel(\n\tobservation_probabilities, obs\n)\n\ninit_distribution = np.array([0.6, 0.4])\n\ntransition_model = ConstantTransitionModel(\n\ttransition_probabilities, init_distribution\n)\n\nhmm = HMM(observation_model, transition_model, state_space=states)\n\npath, prob = hmm.find_best_sequence(observations, log_probabilities=False)\nprint(\"Example Wikipedia\")\nprint(\"Best sequence\", path)\nprint(\"Expected Sequence\", [\"Healthy\", \"Healthy\", \"Fever\"])\nprint(\"Sequence probability\", prob)\nprint(\"Expected probability\", 0.01512)\n```\n\n## Licence\n\nThe code in this package is licensed under the MIT Licence. For details,\nplease see the [LICENSE](https://github.com/neosatrapahereje/hiddenmarkov/blob/main/LICENSE) file.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A simple Python package for Hidden Markov Models",
"version": "0.1.3",
"project_urls": {
"Homepage": "https://github.com/neosatrapahereje/hiddenmarkov"
},
"split_keywords": [
"hmm",
"hidden_markov_models"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "91315185a1d366b314924977fba773bee745b9eb2cf51085b4fc42f72075e089",
"md5": "5476ed20ea9bf005d5f4684107b0c208",
"sha256": "39a2a34917c9bc009146cebb4955a0d23743dba7bcb13a6ab44529108bafbe0e"
},
"downloads": -1,
"filename": "python-hiddenmarkov-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "5476ed20ea9bf005d5f4684107b0c208",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 8845,
"upload_time": "2022-11-09T00:30:44",
"upload_time_iso_8601": "2022-11-09T00:30:44.546910Z",
"url": "https://files.pythonhosted.org/packages/91/31/5185a1d366b314924977fba773bee745b9eb2cf51085b4fc42f72075e089/python-hiddenmarkov-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-11-09 00:30:44",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "neosatrapahereje",
"github_project": "hiddenmarkov",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "python-hiddenmarkov"
}