{"id":22852974,"url":"https://github.com/vgherard/viterbi","last_synced_at":"2025-03-31T07:12:44.125Z","repository":{"id":159807784,"uuid":"328642123","full_name":"vgherard/viterbi","owner":"vgherard","description":"Viterbi algorithm for optimal paths in Hidden Markov Models","archived":false,"fork":false,"pushed_at":"2021-01-12T11:00:17.000Z","size":12,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-06T11:53:03.973Z","etag":null,"topics":["algorithm","dynamic-programming","hidden-markov-model","natural-language-processing","part-of-speech-tagging"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vgherard.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-11T11:28:33.000Z","updated_at":"2024-03-20T07:49:23.000Z","dependencies_parsed_at":null,"dependency_job_id":"30f84dfe-8a6e-4779-9f2d-aac2bd00bd7b","html_url":"https://github.com/vgherard/viterbi","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgherard%2Fviterbi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgherard%2Fviterbi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgherard%2Fviterbi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgherard%2Fviterbi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vgherard","download_url":"https://codeload.github.com/vgherard/viterbi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246429493,"owners_count":20775808,"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":["algorithm","dynamic-programming","hidden-markov-model","natural-language-processing","part-of-speech-tagging"],"created_at":"2024-12-13T06:10:08.584Z","updated_at":"2025-03-31T07:12:44.119Z","avatar_url":"https://github.com/vgherard.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# viterbi\nThe [Viterbi algorithm](https://en.wikipedia.org/wiki/Viterbi_algorithm) is a dynamic programming algorithm to find optimal paths in the hidden space of an hidden Markov model. \nIt has wide applications, including for Natural Language Processing tasks such as Part-of-Speech tagging.\nProblem and algorithm descriptions are given below.\n\n#### Example\nCompile and link `example.cpp` and `viterbi.cpp`, e.g.:\n\n```\n$ g++ example.cpp viterbi.cpp -o example\n$ ./example\n```\n\nYou will be prompted to insert the data defining the model, and the input path in observable space.\n\n#### Problem\nLet \u003cimg src=\"https://render.githubusercontent.com/render/math?math=\\mathscr M = (\\mathscr H, \\mathscr O, T, E, \\pi)\"\u003e be an hidden Markov model, where:\n  - \u003cimg src=\"https://render.githubusercontent.com/render/math?math=\\mathscr H = \\{h_1, h_2, \\cdots, h_{p}\\}\"\u003e: hidden space of finite cardinality \u003cimg src=\"https://render.githubusercontent.com/render/math?math=p\"\u003e\n  - \u003cimg src=\"https://render.githubusercontent.com/render/math?math=\\mathscr O = \\{o_1, o_2, \\cdots, o_{q}\\}\"\u003e: observable space of finite cardinality \u003cimg src=\"https://render.githubusercontent.com/render/math?math=q\"\u003e\n  - \u003cimg src=\"https://render.githubusercontent.com/render/math?math=T_{ij} = \\text{Prob}(h_i \\leftarrow h_j)\"\u003e: transition matrix\n  - \u003cimg src=\"https://render.githubusercontent.com/render/math?math=E_{ij} = \\text{Prob}(o_i \\leftarrow h_j)\"\u003e: emission matrix\n  - \u003cimg src=\"https://render.githubusercontent.com/render/math?math=\\pi_{i} = \\text{Prob}(h_i \\leftarrow \\emptyset)\"\u003e: start probabilities\n\nGiven a path \n\u003cimg src=\"https://render.githubusercontent.com/render/math?math=Y=y_1y_2\\cdots y_L\"\u003e in observable space, \nfind a corresponding path \n\u003cimg src=\"https://render.githubusercontent.com/render/math?math=X=x_1x_2\\cdots x_L\"\u003e in hidden space\nmaximizing the conditional probability \u003cimg src=\"https://render.githubusercontent.com/render/math?math=\\text{Prob(X | Y)}\"\u003e\nor, equivalently, the joint probability \u003cimg src=\"https://render.githubusercontent.com/render/math?math=\\text{Prob(X,Y)}\"\u003e\n\n#### Algorithm\nThe Viterbi algorithm is a dynamic programming procedure to solve the problem above. It is based on the optimization subproblems:\n\n\u003cimg src=\"https://render.githubusercontent.com/render/math?math=\\mathscr{P}_{il}=\\max_{x_{1}x_{2}\\cdots x_{l-1}}\\text{Prob}(x_{1}x_{2}\\cdots x_{l-1}x_{l},\\,y_{1}y_{2}\\cdots y_{l-1}y_{l})\"\u003e\n\n\u003cimg src=\"https://render.githubusercontent.com/render/math?math=\\mathscr{X}_{il}=\\arg\\max_{x_{l-1}}\\max_{x_{1}x_{2}\\cdots x_{l-2}}\\text{Prob}(x_{1}x_{2}\\cdots x_{l-1}x_{l},\\,y_{1}y_{2}\\cdots y_{l-1}y_{l})\"\u003e\n\nwhich can be solved recursively. For more info and pseudocode, c.f. the [Wikipedia article](https://en.wikipedia.org/wiki/Viterbi_algorithm).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvgherard%2Fviterbi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvgherard%2Fviterbi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvgherard%2Fviterbi/lists"}