Skip to main content

pylibhmm

Python bindings for libhmm v4 — a modern C++20 Hidden Markov Model library with 16 scalar and 3 multivariate emission distributions, canonical log-space inference, and training algorithms.

Features

Scalar HMMs

  • All 16 emission distributions: Gaussian, StudentT, Gamma, LogNormal, Beta, Weibull, Exponential, Rayleigh, Pareto, Uniform, ChiSquared, VonMises, Discrete, Poisson, Binomial, NegativeBinomial
  • Hmm, ForwardBackwardCalculator, ViterbiCalculator, BaumWelchTrainer, MapBaumWelchTrainer, ViterbiTrainer, SegmentalKMeansTrainer
  • Posterior decoding (decode_posterior) and model selection (AIC / BIC / AICc)
  • JSON model I/O (save_json / load_json / to_json / from_json) — recommended
  • Legacy XML model I/O (save_hmm / load_hmm) — retained for existing files

Multivariate HMMs (v0.6.0 / libhmm v4)

  • DiagonalGaussian, FullCovGaussian, IndependentComponents distributions
  • HmmMV, MVForwardBackwardCalculator, MVBaumWelchTrainer
  • kmeans_init for k-means++ seeded initialisation
  • MV JSON I/O (save_json_mv / load_json_mv / to_json_mv / from_json_mv)
  • NumPy-friendly: observations as 2-D float64 arrays, sequences as lists of 2-D arrays

General

  • Python 3.11+ packaging via scikit-build-core + nanobind
  • Real-data examples: DAX regime detection, elk movement, earthquake counts, S&P 500, wind direction

Quick start

Scalar HMM:

import numpy as np
import pylibhmm

hmm = pylibhmm.Hmm(2)
hmm.set_pi(np.array([0.75, 0.25], dtype=np.float64))
hmm.set_trans(np.array([[0.9, 0.1], [0.8, 0.2]], dtype=np.float64))

fair = pylibhmm.Discrete(6)
for i in range(6):
    fair.set_probability(i, 1.0 / 6.0)

loaded = pylibhmm.Discrete(6)
for i in range(5):
    loaded.set_probability(i, 0.125)
loaded.set_probability(5, 0.375)

hmm.set_distribution(0, fair)
hmm.set_distribution(1, loaded)

obs = np.array([0, 1, 5, 4, 2], dtype=np.float64)
fb = pylibhmm.ForwardBackwardCalculator(hmm, obs)
print(fb.log_probability)

pylibhmm.save_json(hmm, "model.json")
hmm2 = pylibhmm.load_json("model.json")

Multivariate HMM:

import numpy as np
import pylibhmm

# 3-state, 2-feature diagonal-Gaussian HMM
hmm = pylibhmm.HmmMV(3)
hmm.set_pi(np.array([0.5, 0.3, 0.2]))
hmm.set_trans(np.array([[0.8, 0.1, 0.1],
                         [0.1, 0.8, 0.1],
                         [0.1, 0.1, 0.8]]))

for i, (mean, var) in enumerate([
    ([0.0, 0.0], [1.0, 1.0]),
    ([3.0, 3.0], [1.5, 1.5]),
    ([6.0, 6.0], [2.0, 2.0]),
]):
    hmm.set_distribution(i, pylibhmm.DiagonalGaussian(
        np.array(mean), np.array(var)))

# observations: 2-D float64 array, shape (T, D)
obs = np.random.randn(200, 2).astype(np.float64)

# Initialise with k-means++ then train
pylibhmm.kmeans_init(hmm, [obs])
trainer = pylibhmm.MVBaumWelchTrainer(hmm, [obs])
trainer.train()

fb = pylibhmm.MVForwardBackwardCalculator(hmm, obs)
print(fb.log_probability)

pylibhmm.save_json_mv(hmm, "model_mv.json")
hmm2 = pylibhmm.load_json_mv("model_mv.json")

Build and install

Prerequisites:

  • Python 3.11+
  • CMake 3.25+
  • C++20 compiler

Install locally:

pip install .

Run tests:

pip install ".[test]"
pytest

Dependency strategy

pylibhmm prefers a local sibling ../libhmm source tree if present. If not found, CMake falls back to FetchContent for libhmm tag v4.2.5.

Notes on wheel portability

libhmm defaults to machine-tuned SIMD flags (-march=native or CPU-selected MSVC /arch). That is ideal for local builds but requires extra care for portable binary wheels. See docs/COMPATIBILITY.md.

Documentation

  • docs/API.md — bound API surface
  • docs/DEVELOPMENT.md — contributor workflow
  • docs/COMPATIBILITY.md — platform/version/SIMD notes

License

MIT

Metadata

Release files for pylibhmm 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pylibhmm 0.10.0
File Size Uploaded Provenance Actions
pylibhmm-0.10.0.tar.gz 65.1 kB With provenance Details for pylibhmm-0.10.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pylibhmm 0.10.0
File Actions
pylibhmm-0.10.0-cp314-cp314t-win_amd64.whl CPython 3.14 CPython 3.14 free-threading Windows x86-64 Details for pylibhmm-0.10.0-cp314-cp314t-win_amd64.whl
pylibhmm-0.10.0-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details for pylibhmm-0.10.0-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
pylibhmm-0.10.0-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.26+ ARM64, Linux glibc 2.28+ ARM64 Details for pylibhmm-0.10.0-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
pylibhmm-0.10.0-cp314-cp314t-macosx_13_0_x86_64.whl CPython 3.14 CPython 3.14 free-threading macOS 13.0+ x86-64 Details for pylibhmm-0.10.0-cp314-cp314t-macosx_13_0_x86_64.whl
pylibhmm-0.10.0-cp314-cp314t-macosx_13_0_arm64.whl CPython 3.14 CPython 3.14 free-threading macOS 13.0+ ARM64 Details for pylibhmm-0.10.0-cp314-cp314t-macosx_13_0_arm64.whl
pylibhmm-0.10.0-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details for pylibhmm-0.10.0-cp312-abi3-win_amd64.whl
pylibhmm-0.10.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 abi3 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for pylibhmm-0.10.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
pylibhmm-0.10.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl CPython 3.12 abi3 Linux glibc 2.28+ ARM64, Linux glibc 2.26+ ARM64 Details for pylibhmm-0.10.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
pylibhmm-0.10.0-cp312-abi3-macosx_13_0_x86_64.whl CPython 3.12 abi3 macOS 13.0+ x86-64 Details for pylibhmm-0.10.0-cp312-abi3-macosx_13_0_x86_64.whl
pylibhmm-0.10.0-cp312-abi3-macosx_13_0_arm64.whl CPython 3.12 abi3 macOS 13.0+ ARM64 Details for pylibhmm-0.10.0-cp312-abi3-macosx_13_0_arm64.whl

Total release size: 22.7 MB

Release files / pylibhmm-0.10.0.tar.gz

Download URL pylibhmm-0.10.0.tar.gz
Size 65.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c093d01f1234ab88a97ee6fbe116b8a554648ebd3c92aa1c83d66187ebc4cc1a
BLAKE2b-256 checksum
How to use checksums
891d8ca3a66880005c0d0d4794400ec6a7f5168c00ef5017904d2f7ceb74c947
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

Release files / pylibhmm-0.10.0-cp314-cp314t-win_amd64.whl

Download URL pylibhmm-0.10.0-cp314-cp314t-win_amd64.whl
Size 4.0 MB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
435c7019c438dcec975674506f0b9995223856c1e9707ea6944c0fed4cd20427
BLAKE2b-256 checksum
How to use checksums
42af41d449657399b5f7e365096e3bb33f1f573e5a06e1d091acff0dce0debf8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

Release files / pylibhmm-0.10.0-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pylibhmm-0.10.0-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 2.4 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
6970be4c93b273e60304361a732ea381ee21ffc56bca70fad3389f0e521ad717
BLAKE2b-256 checksum
How to use checksums
725d2670d9095fbc61bb88fd7a30bbd81eee009c4a5bc1e90bddbd6b5423d245
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

Release files / pylibhmm-0.10.0-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl

Download URL pylibhmm-0.10.0-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Size 2.1 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
e82aaa0a7aa4213d4cf1c85be032c41a97a39d272e93ecde15598b8932431a3d
BLAKE2b-256 checksum
How to use checksums
e1431c9103653faf9778927f838b309ca1bef8625c4b959864db1d11d448bfc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

Release files / pylibhmm-0.10.0-cp314-cp314t-macosx_13_0_x86_64.whl

Download URL pylibhmm-0.10.0-cp314-cp314t-macosx_13_0_x86_64.whl
Size 1.6 MB
Tags CPython 3.14 CPython 3.14 free-threading macOS 13.0+ x86-64
SHA-256 checksum
How to use checksums
d2a9c7a47a28e2bd001630fe654e95e4a036f4cc52aa8851496ee8f3bf6db2d4
BLAKE2b-256 checksum
How to use checksums
a43974c2b41ee0b74af77b7d3dd9b6be24973f8f0b85900fe2098ddc8397b2d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

Release files / pylibhmm-0.10.0-cp314-cp314t-macosx_13_0_arm64.whl

Download URL pylibhmm-0.10.0-cp314-cp314t-macosx_13_0_arm64.whl
Size 1.3 MB
Tags CPython 3.14 CPython 3.14 free-threading macOS 13.0+ ARM64
SHA-256 checksum
How to use checksums
57a0b703455545ee27590c7a984ebecdc1e59f4836cf70a1e75088527eea606e
BLAKE2b-256 checksum
How to use checksums
69df28438e0490f956e0f66522d04bebbbdd601921aecead3fc6f374c5173fd5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

Release files / pylibhmm-0.10.0-cp312-abi3-win_amd64.whl

Download URL pylibhmm-0.10.0-cp312-abi3-win_amd64.whl
Size 3.9 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
7157be89b318fe38f3d92fef00b11ff42861f42f74fd62f287c2cb202781c134
BLAKE2b-256 checksum
How to use checksums
3509a776505a9d97334b1278491342765062340d3fb55ad759740e50c2d02fb7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

Release files / pylibhmm-0.10.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL pylibhmm-0.10.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 2.4 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
d2f44fb0931a6792f53c522dee3b8723320f7e1c10a92e322f26e319f5a8cd01
BLAKE2b-256 checksum
How to use checksums
55cc8fc86eb7d9361de4690a636647325caea5977a7129375d8587e242c653c2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

Release files / pylibhmm-0.10.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl

Download URL pylibhmm-0.10.0-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Size 2.1 MB
Tags CPython 3.12 Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
a41f3b85f2090ebde45826375ffb2dbc9e60b4e97b77b62bdb9f5cb3ded43ca8
BLAKE2b-256 checksum
How to use checksums
2a9d43376df1ed89a8043bf25f2853200432eb30bf36704b5f13384dcfb3cde4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

Release files / pylibhmm-0.10.0-cp312-abi3-macosx_13_0_x86_64.whl

Download URL pylibhmm-0.10.0-cp312-abi3-macosx_13_0_x86_64.whl
Size 1.6 MB
Tags CPython 3.12 abi3 macOS 13.0+ x86-64
SHA-256 checksum
How to use checksums
2a70bd8eb0d29e81aa4220c76edc6ff9bcc538919327137f1228843758954fdc
BLAKE2b-256 checksum
How to use checksums
cf01ba35e593a2353154f75d8276df38a6e7c699827322f8490319033848d199
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

Release files / pylibhmm-0.10.0-cp312-abi3-macosx_13_0_arm64.whl

Download URL pylibhmm-0.10.0-cp312-abi3-macosx_13_0_arm64.whl
Size 1.3 MB
Tags CPython 3.12 abi3 macOS 13.0+ ARM64
SHA-256 checksum
How to use checksums
fe211638193936f4e3c4a5f4db003ead0fbe0c68743313e41541045476cc960e
BLAKE2b-256 checksum
How to use checksums
ce9f4c10edb7d3bc594825273acfacd3a28a1cf0452620dc9f4ebc9f80eec500
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

Security for pylibhmm 0.10.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 11 files in this release have been uploaded with provenance metadata.

Select from 11 files

Attestation for pylibhmm-0.10.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page