{"id":17486787,"url":"https://github.com/sumolari/hmm","last_synced_at":"2025-04-22T15:45:45.741Z","repository":{"id":15337348,"uuid":"18067872","full_name":"Sumolari/hmm","owner":"Sumolari","description":"A Hidden Markov Model implemented in Javascript","archived":false,"fork":false,"pushed_at":"2018-04-08T10:14:52.000Z","size":80,"stargazers_count":32,"open_issues_count":1,"forks_count":4,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-17T04:19:32.337Z","etag":null,"topics":["classification","clustering","hidden-markov-model","machine-learning"],"latest_commit_sha":null,"homepage":"","language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Sumolari.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-24T15:44:46.000Z","updated_at":"2024-09-01T15:00:59.000Z","dependencies_parsed_at":"2022-08-04T04:15:12.585Z","dependency_job_id":null,"html_url":"https://github.com/Sumolari/hmm","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sumolari%2Fhmm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sumolari%2Fhmm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sumolari%2Fhmm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sumolari%2Fhmm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sumolari","download_url":"https://codeload.github.com/Sumolari/hmm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250271661,"owners_count":21403233,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["classification","clustering","hidden-markov-model","machine-learning"],"created_at":"2024-10-19T02:12:00.627Z","updated_at":"2025-04-22T15:45:45.717Z","avatar_url":"https://github.com/Sumolari.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![NPM version][npm-image]][npm-url]\n[![Build status][travis-image]][travis-url]\n[![Test coverage][coveralls-image]][coveralls-url]\n[![License][license-image]][license-url]\n[![Downloads][downloads-image]][downloads-url]\n\nThis module implements a **Hidden Markov Model** featuring methods to obtain the real generation probability and Viterbi approximations as well as methods to initialize and/or reestimate a HMM given a set of generated items with Viterbi re-estimation and linear segmentation.\n\n# Dependencies\n\nImplementation itself depends on **no additional module**.\n\n# Usage\n\nThis project can be used as a NodeJS module:\n\n```javascript\nvar hmm = require( './hmm.js' );\nvar aModel = new hmm();\n```\n\n## Initializing with explicit details\n\nA Hidden Markov Model can be initialized giving the explicit list of states (including final state), symbols, initial probabilities, transition probabilities and emission probabilities.\n\n```javascript\naModel = new hmm(\n\t[ '1', '2', '3', 'F' ],\n\t'F', [ 'a', 'b', 'c' ], {\n\t\t'1': 1\n\t}, {\n\t\t'1': {\n\t\t\t'1': 0.2,\n\t\t\t'2': 0.5,\n\t\t\t'3': 0.3\n\t\t},\n\t\t'2': {\n\t\t\t'1': 0.1,\n\t\t\t'3': 0.9\n\t\t},\n\t\t'3': {\n\t\t\t'3': 0.4,\n\t\t\t'F': 0.6\n\t\t}\n\t}, {\n\t\t'1': {\n\t\t\t'b': 0.3,\n\t\t\t'c': 0.7\n\t\t},\n\t\t'2': {\n\t\t\t'a': 0.3,\n\t\t\t'b': 0.6,\n\t\t\t'c': 0.1\n\t\t},\n\t\t'3': {\n\t\t\t'a': 1,\n\t\t}\n\t}\n);\n```\n\n## Reestimating an existing Hidden Markov Model\n\nIf you have an existing HMM and want to reestimate it with some training samples you can do it with `reestimate` method:\n\n```javascript\naModel.reestimate( [ [ 'b', 'c', 'b', 'a' ], [ 'b', 'c', 'b', 'b' ], [ 'b', 'c', 'b', 'd' ] ] );\n\n```\n\nOptionally you can give an array of optimal paths as second parameter. If you don't give that array of paths the method will compute the optimal paths for each one of given items, so be sure that given items could be generated with the model.\n\n## Initializing a new Hidden Markov Model given some training samples\n\nTo initialize a new Hidden Markov Model without having a previous model you can use `initialize` method:\n\n```javascript\naModel.initialize( [ [ 'b', 'c', 'b', 'a' ], [ 'b', 'c', 'b', 'b' ], [ 'b', 'c', 'b', 'd' ] ], 3 );\n```\n\nThis method will initialize the model, using linear segmentation to decide which will be the optimal state sequence for each one of the items and after that will reestimate the model.\n\n## Getting the probability that a given item is generated by the model\n\nThis implementation offers methods to get the real generation probability (using Forward algorithm), the Viterbi approximation and the most probable state sequence.\n\n* **Real probability**: Given an array of symbols, `generationProbability` method will return the probability that those symbols are generated in that order by the model.\n* **Viterbi approximation**: Given an array of symbols, `viterbiApproximation` method will return the probability that most probable state sequence generates given symbols in given order.\n* **Most probable state sequence**: Given an array of symbols, `optimalStateSequence` will return the most probable state sequence as an array.\n\n```javascript\nvar hmm = require( './hmm.js' );\nvar milk = new hmm();\nvar something = [ 'white', 'bottle' ];\nmilk.initialize( [ something ], 2 );\nconsole.log( 'The probability that something white in a bottle is milk is ' +  ( milk.generationProbability( something ) * 100 ) + '%.' );\n```\n\n## Printing the model\n\nYou can check internal details of the model with `print` method, which will print details on console:\n\n```bash\n\u003e milk.print();\nA\t1\t2\tF\n1\t0\t1\t0\n2\t0\t0\t1\nF\t0\t0\t0\n\nB\twhite\tbottle\n1\t1\t0\n2\t0\t1\n\nInitial:\n1:\t1\n2:\t0\nF:\t0\n\nFinal: F\n```\n\n# Development\n\nYou'll need to install development dependencies:\n\n```bash\nnpm install --only=dev\n```\n\n## Generating documentation\n\nDocumentation can be generated running:\n\n```bash\nnpm run-script doc\n```\n\nHTML documentation will be available in `doc` folder.\n\n## Building from Coffeescript source\n\nAlthough this module is shipped already built you can build it again from CoffeeScript sources running:\n\n```bash\nnpm run-script prepublish\n```\n\n## Running tests\n\nYou can also run the tests and get coverage information. To run the tests on CoffeeScript source just run:\n\n```bash\nnpm test\n```\n\nIf you want to generate additional coverage information run:\n\n```bash\nnpm run-script test-cov\n```\n\nAnd then you'll find coverage information in `coverage` folder.\n\n[npm-image]: https://img.shields.io/npm/v/HiddenMarkovModel.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/HiddenMarkovModel\n[travis-image]: https://img.shields.io/travis/Sumolari/hmm.svg?style=flat-square\n[travis-url]: https://travis-ci.org/Sumolari/hmm\n[coveralls-image]: https://img.shields.io/coveralls/Sumolari/hmm.svg?style=flat-square\n[coveralls-url]: https://coveralls.io/r/Sumolari/hmm\n[license-image]: http://img.shields.io/npm/l/HiddenMarkovModel.svg?style=flat-square\n[license-url]: https://opensource.org/licenses/MIT\n[downloads-image]: http://img.shields.io/npm/dm/HiddenMarkovModel.svg?style=flat-square\n[downloads-url]: https://npmjs.org/package/HiddenMarkovModel","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsumolari%2Fhmm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsumolari%2Fhmm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsumolari%2Fhmm/lists"}