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.12.1

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.12.1
File Size Uploaded Provenance Actions
pylibhmm-0.12.1.tar.gz 494.5 kB With provenance Details for pylibhmm-0.12.1.tar.gz

Built distributions (wheels)

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

Total release size: 24.2 MB

Release files / pylibhmm-0.12.1.tar.gz

Download URL pylibhmm-0.12.1.tar.gz
Size 494.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3476baa781cfe58a6dcd577ffb3f830b86e2a2d01c590ed50f8f3399dd2e0dd8
BLAKE2b-256 checksum
How to use checksums
1c91a54d289a985912bd1ce5ece3390898bea7dd3aa5fd323024488eab8e74df
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 Sep 19, 2026.

Transparency log

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

Download URL pylibhmm-0.12.1-cp314-cp314t-win_amd64.whl
Size 4.2 MB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
b132df3b55e733327d8fa59784186cf54378770d895cfac58a730530b08b5ee2
BLAKE2b-256 checksum
How to use checksums
20521b77b4667e587cc6742f5fe94d74a9d9b6f7f6de683f8dff411af36a48c1
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 Sep 19, 2026.

Transparency log

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

Download URL pylibhmm-0.12.1-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 2.5 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
3e7b42d46baee01e88af550611eb94980d096650a9575751a51e244636299233
BLAKE2b-256 checksum
How to use checksums
db5af7e9ffa139ee91d52a850ce0b5bac0b1120344099e4cbd6fc2d7c4b08326
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 Sep 19, 2026.

Transparency log

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

Download URL pylibhmm-0.12.1-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Size 2.2 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
83468d954b5048b276d2c0de5cf63336f1ff010e0ca2b140358df399ae515c29
BLAKE2b-256 checksum
How to use checksums
3641391e8149082d15258ca2f5897e0331477f36b2f42700d0865fb160799b63
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 Sep 19, 2026.

Transparency log

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

Download URL pylibhmm-0.12.1-cp314-cp314t-macosx_13_0_x86_64.whl
Size 1.7 MB
Tags CPython 3.14 CPython 3.14 free-threading macOS 13.0+ x86-64
SHA-256 checksum
How to use checksums
a6fceb77076b3845c76bf623cb76775c1608dc4fe21cc658002a2d41d1f4c63b
BLAKE2b-256 checksum
How to use checksums
3bfe6b06d45ceaaefdd31af744942ca4392792aeb6ce769b5b41c97ecc3eeb0a
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 Sep 19, 2026.

Transparency log

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

Download URL pylibhmm-0.12.1-cp314-cp314t-macosx_13_0_arm64.whl
Size 1.4 MB
Tags CPython 3.14 CPython 3.14 free-threading macOS 13.0+ ARM64
SHA-256 checksum
How to use checksums
09586dea281c972761b407bb0d16084ad6822241c7376c29b0128b7bba9b103b
BLAKE2b-256 checksum
How to use checksums
e59dbc580ca5841b077249714f3a1812f6d514c5a3a426ba14c77516f6aaf1fb
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 Sep 19, 2026.

Transparency log

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

Download URL pylibhmm-0.12.1-cp312-abi3-win_amd64.whl
Size 4.1 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
fb2ff2c03209b075cdaab1bdebb9fb1f8efe51890d352917e45f180e5bd29093
BLAKE2b-256 checksum
How to use checksums
bd82d836389a73dd5cdf324528e3762e872ad300f9c36b13315ece8bb5398a99
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 Sep 19, 2026.

Transparency log

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

Download URL pylibhmm-0.12.1-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 2.5 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
00f7b1e025c5b25e8be952e7e5f0059aa291afa334a3890e5d3e2885680adbbd
BLAKE2b-256 checksum
How to use checksums
03514d2dfce55b085222e4d34644916a3065b5a79bc852adcc5f32a579844f73
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 Sep 19, 2026.

Transparency log

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

Download URL pylibhmm-0.12.1-cp312-abi3-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Size 2.2 MB
Tags CPython 3.12 Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
a4c0e610a781b18cf6f6bb922e89229c78129a8800bf2cce5ece478e57095cf7
BLAKE2b-256 checksum
How to use checksums
40256e2b29c5881b9f2b183cea82634a3daf53749988f90898fadfc9f3d03a5b
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 Sep 19, 2026.

Transparency log

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

Download URL pylibhmm-0.12.1-cp312-abi3-macosx_13_0_x86_64.whl
Size 1.7 MB
Tags CPython 3.12 abi3 macOS 13.0+ x86-64
SHA-256 checksum
How to use checksums
ee7b57ef0d4ce2bc743fb222abbfaa9a7e4668a497ba6d6a4efecac0e14a2e3b
BLAKE2b-256 checksum
How to use checksums
bce7f4eb6cc17db6e5cd16fd508b5e44948ccd35e0c4f0c1c537393f7144307e
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 Sep 19, 2026.

Transparency log

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

Download URL pylibhmm-0.12.1-cp312-abi3-macosx_13_0_arm64.whl
Size 1.4 MB
Tags CPython 3.12 abi3 macOS 13.0+ ARM64
SHA-256 checksum
How to use checksums
cea17dc535eb3964db03394eb79db6539fdf437ed3c7686900ffac19b1e19ce2
BLAKE2b-256 checksum
How to use checksums
3a369f4fc0e7eed1901602eb8300b53f30b42dc4cf2220b46363d0ac97ee876e
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 Sep 19, 2026.

Transparency log

Security for pylibhmm 0.12.1

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.12.1.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 Sep 19, 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