{"id":29091190,"url":"https://github.com/oldcrow/libhmm","last_synced_at":"2026-04-23T05:01:13.340Z","repository":{"id":300482967,"uuid":"1006280421","full_name":"OldCrow/libhmm","owner":"OldCrow","description":"Modern C++17 Hidden Markov Model library with smart pointer memory management, comprehensive training algorithms, and critical bug fixes. Features Viterbi training, multiple probability distributions, and memory-safe implementation.","archived":false,"fork":false,"pushed_at":"2026-04-19T02:36:47.000Z","size":8033,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-19T04:18:38.482Z","etag":null,"topics":["baum-welch","baum-welch-algorithm","cmake","cpp","cpp17","hidden-markov-models","machine-learning","probability","smart-pointers","statistics","viterbi-algorithm"],"latest_commit_sha":null,"homepage":"","language":"C++","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/OldCrow.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-06-21T22:38:28.000Z","updated_at":"2025-07-02T22:46:01.000Z","dependencies_parsed_at":"2025-06-22T00:35:40.638Z","dependency_job_id":null,"html_url":"https://github.com/OldCrow/libhmm","commit_stats":null,"previous_names":["oldcrow/libhmm"],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/OldCrow/libhmm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OldCrow%2Flibhmm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OldCrow%2Flibhmm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OldCrow%2Flibhmm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OldCrow%2Flibhmm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OldCrow","download_url":"https://codeload.github.com/OldCrow/libhmm/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OldCrow%2Flibhmm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32166660,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-23T02:19:40.750Z","status":"ssl_error","status_checked_at":"2026-04-23T02:17:55.737Z","response_time":53,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["baum-welch","baum-welch-algorithm","cmake","cpp","cpp17","hidden-markov-models","machine-learning","probability","smart-pointers","statistics","viterbi-algorithm"],"created_at":"2025-06-28T06:05:47.527Z","updated_at":"2026-04-23T05:01:13.334Z","avatar_url":"https://github.com/OldCrow.png","language":"C++","readme":"# libhmm — Modern C++20 Hidden Markov Model Library\n\n[![C++20](https://img.shields.io/badge/C%2B%2B-20-blue.svg)](https://isocpp.org/std/the-standard)\n[![CMake](https://img.shields.io/badge/CMake-3.20%2B-blue.svg)](https://cmake.org/)\n[![License](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)\n[![Version](https://img.shields.io/badge/Version-3.0.0-brightgreen.svg)](https://github.com/OldCrow/libhmm/releases)\n[![Tests](https://img.shields.io/badge/Tests-36%2F36_Passing-success.svg)](tests/)\n[![SIMD](https://img.shields.io/badge/SIMD-AVX--512%2FAVX2%2FSSE2%2FNEON-blue.svg)](src/distributions/)\n[![CI](https://github.com/OldCrow/libhmm/actions/workflows/ci.yml/badge.svg)](https://github.com/OldCrow/libhmm/actions)\n\nA modern, high-performance C++20 implementation of Hidden Markov Models with 15 emission distributions,\ncanonical log-space algorithms, and compile-time SIMD acceleration.\n\n**Zero external dependencies** — C++20 standard library only.\n\n## Features\n\n### Training Algorithms\n\n- **Baum-Welch** — canonical log-space EM; works with any `EmissionDistribution` via weighted `fit()`\n- **Viterbi Training** — hard-assignment with `TrainingConfig` presets (`fast`, `balanced`, `precise`)\n- **Segmental K-Means** — for discrete HMMs; useful as initialiser before EM\n\n### Inference\n\n- **ForwardBackward** — canonical log-space calculator; returns `probability()` and `getLogProbability()`\n- **Viterbi** — canonical log-space decoder; returns the MAP state sequence\n\nBoth calculators call `getBatchLogProbabilities()` per state per time step, enabling\nSIMD acceleration directly at the distribution layer.\n\n### Probability Distributions (15)\n\n**Discrete:** `DiscreteDistribution`, `BinomialDistribution`, `NegativeBinomialDistribution`, `PoissonDistribution`\n\n**Continuous:** `GaussianDistribution`, `ExponentialDistribution`, `GammaDistribution`, `LogNormalDistribution`,\n`BetaDistribution`, `UniformDistribution`, `WeibullDistribution`, `ParetoDistribution`,\n`RayleighDistribution`, `StudentTDistribution`, `ChiSquaredDistribution`\n\nAll distributions implement `getBatchLogProbabilities()` for SIMD-accelerated batch evaluation.\n`GaussianDistribution` and `ExponentialDistribution` have explicit AVX-512/AVX2/SSE2/NEON intrinsics (tier 2);\nthe remaining 13 use concrete non-virtual loops that the compiler auto-vectorizes under `-march=native`.\n\n### Performance\n\n- **Compile-time SIMD dispatch**: each machine builds for its own CPU\n  - GCC/Clang: `-march=native` (AVX-512 on capable x86, NEON on AArch64)\n  - MSVC: `/arch:AVX512`, `/arch:AVX2`, or `/arch:AVX` (CPU-verified at configure time)\n- **Log-space throughout**: no numerical underflow on long sequences\n- **Pre-computed log transition matrices**: amortised once per `compute()` call\n\n## Quick Start\n\n### Build\n\n```bash\ngit clone https://github.com/OldCrow/libhmm.git\ncd libhmm\ncmake -B build\ncmake --build build --config Release\nctest --test-dir build\n```\n\nOn Windows with Visual Studio:\n```powershell\ncmake -B build -G \"Visual Studio 17 2022\" -A x64\ncmake --build build --config Release --parallel 4\nctest --test-dir build -C Release --parallel 4\n```\n\n### Basic Usage\n\n```cpp\n#include \"libhmm/libhmm.h\"\nusing namespace libhmm;\n\n// Create a 2-state HMM with Gaussian emissions\nHmm hmm(2);\n\nMatrix trans(2, 2);\ntrans(0, 0) = 0.9; trans(0, 1) = 0.1;\ntrans(1, 0) = 0.2; trans(1, 1) = 0.8;\nhmm.setTrans(trans);\n\nVector pi(2); pi(0) = 0.6; pi(1) = 0.4;\nhmm.setPi(pi);\n\nhmm.setDistribution(0, std::make_unique\u003cGaussianDistribution\u003e(0.0, 1.0));\nhmm.setDistribution(1, std::make_unique\u003cGaussianDistribution\u003e(5.0, 1.5));\n\n// Train with Baum-Welch (works with any EmissionDistribution)\nObservationLists obs = { /* your sequences */ };\nBaumWelchTrainer trainer(\u0026hmm, obs);\ntrainer.train();\n\n// Evaluate\nForwardBackwardCalculator fbc(hmm, obs[0]);\ndouble log_p = fbc.getLogProbability();\n\n// Decode\nViterbiCalculator vc(hmm, obs[0]);\nStateSequence path = vc.decode();\n```\n\n### ViterbiTrainer Presets\n\n```cpp\n// Fast convergence for interactive use\nViterbiTrainer fast_trainer(\u0026hmm, obs, training_presets::fast());\nfast_trainer.train();\n\n// Precise convergence for final models\nViterbiTrainer precise_trainer(\u0026hmm, obs, training_presets::precise());\nprecise_trainer.train();\nstd::cout \u003c\u003c \"Converged: \" \u003c\u003c precise_trainer.hasConverged() \u003c\u003c \"\\n\";\n```\n\n## Project Structure\n\n```\nlibhmm/\n├── include/libhmm/    # Public headers (layered architecture)\n│   ├── platform/      # Layer 0: SIMD detection\n│   ├── math/          # Layer 1: constants, log-space, numerics\n│   ├── linalg/        # Layer 2: Matrix, Vector types\n│   ├── distributions/ # Layer 3: 15 distributions + base\n│   ├── hmm.h          # Core HMM class\n│   ├── calculators/   # Layer 4: ForwardBackward, Viterbi\n│   └── training/      # Layer 4: BaumWelch, Viterbi, SegmentalKMeans\n├── src/               # Implementation (mirrors include/)\n├── tests/             # 36-test GTest suite (7 architectural levels)\n├── examples/          # 12 usage demonstrations\n├── tools/             # simd_inspection, batch_performance, hmm_validator\n├── benchmarks/        # Comparative benchmarks (requires external libraries)\n├── docs/              # Documentation and checklists\n└── CMakeLists.txt\n```\n\n## Examples\n\nSee [examples/](examples/) for demonstrations:\n\n| Example | Distribution(s) | Trainer |\n|---|---|---|\n| `basic_hmm_example` | Discrete, Gaussian | Viterbi |\n| `baum_welch_example` | Gaussian | BaumWelch (with EM convergence table) |\n| `viterbi_trainer_example` | Gaussian | Viterbi (preset comparison) |\n| `student_t_hmm_example` | StudentT | BaumWelch |\n| `poisson_hmm_example` | Poisson | Viterbi |\n| `financial_hmm_example` | Beta, LogNormal | Viterbi |\n| `reliability_hmm_example` | Weibull, Exponential | Viterbi |\n| `quality_control_hmm_example` | Binomial, Uniform | Viterbi |\n| `economics_hmm_example` | NegBinomial, Pareto | Viterbi |\n| `queuing_theory_hmm_example` | Poisson, Exponential, Gamma | Viterbi |\n| `statistical_process_control_hmm_example` | ChiSquared | Viterbi |\n| `swarm_coordination_example` | Discrete (243 symbols) | — |\n\n## Requirements\n\n- **C++20** compiler: GCC 11+, Clang 14+, MSVC 2019 16.11+\n- **CMake 3.20+**\n\nNo external dependencies. GTest is fetched automatically via CMake `FetchContent` for the test suite.\n\n## Documentation\n\n- [WARP.md](WARP.md) — session guide for Warp AI agent\n- [docs/GOLD_STANDARD_CHECKLIST.md](docs/GOLD_STANDARD_CHECKLIST.md) — distribution implementation requirements\n- [docs/STYLE_GUIDE.md](docs/STYLE_GUIDE.md) — coding conventions\n\n## License\n\nMIT License — see [LICENSE](LICENSE) for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foldcrow%2Flibhmm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foldcrow%2Flibhmm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foldcrow%2Flibhmm/lists"}