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.11.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.11.1
File Size Uploaded Provenance Actions
pylibhmm-0.11.1.tar.gz 67.2 kB With provenance Details for pylibhmm-0.11.1.tar.gz

Built distributions (wheels)

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

Total release size: 23.6 MB

Release files / pylibhmm-0.11.1.tar.gz

Download URL pylibhmm-0.11.1.tar.gz
Size 67.2 kB
Tags Source
SHA-256 checksum
How to use checksums
42b2c1fb51cf1a448ae97524c6ad1bdc57594c081b0bfcc30d68e882c1c281fc
BLAKE2b-256 checksum
How to use checksums
24e526e0fb7bec81f2e9fe5b6e2287afc21c4fb61a2f7da1e40c170474391178
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 27, 2026.

Transparency log

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

Download URL pylibhmm-0.11.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
c2e970c15549ec1353cbfb83064ba2d7e7d1dcd86a4df81495d5c3e0cb227a48
BLAKE2b-256 checksum
How to use checksums
e344948949000017fc0b35c98b62d7d0605f8213be2fd741bdd0904ec11fca2f
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 27, 2026.

Transparency log

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

Download URL pylibhmm-0.11.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
4ab5d88dc862343a252432cce38402282f6ae70be944136d78d4a297ad1fcbd9
BLAKE2b-256 checksum
How to use checksums
7dda8d81d5e534ad798eef7ad0810d6b3837a2691ae5ce7489479f7ac19f282a
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 27, 2026.

Transparency log

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

Download URL pylibhmm-0.11.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
71de03d4d7cb14dd2c3b21717284958036b737a690a8a1b797cbb1d8e8432ad1
BLAKE2b-256 checksum
How to use checksums
9134306959882036557d7318ca56f98d1c990ef9697c5f662903cc74a3c42a88
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 27, 2026.

Transparency log

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

Download URL pylibhmm-0.11.1-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
35de5e163e016010917d536572d67b8ff5ec71d0b4a963d41a03b06dfe25241f
BLAKE2b-256 checksum
How to use checksums
b8fc565a762372c740acc37c1bd04c3d7e2a8704a83f8acb11d08445edc60808
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 27, 2026.

Transparency log

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

Download URL pylibhmm-0.11.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
e53d6f007f770a5f50c667fb55de2b453b33cb7c6a504bbc7e4eb191f3683b71
BLAKE2b-256 checksum
How to use checksums
c8101966db62b6e55378adebe832267095ea911e9be18d3c777873bab1fd4e47
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 27, 2026.

Transparency log

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

Download URL pylibhmm-0.11.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
684e4f279de56622ca23326f2aea03088d2fc988094db0cc629ed8cd1e2e2c70
BLAKE2b-256 checksum
How to use checksums
3929fac6ee372b2c9f184e95c3a7bbe6eb62b79a4b5389f12755bd660f578a1a
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 27, 2026.

Transparency log

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

Download URL pylibhmm-0.11.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
75605afbcf5a3b624aa679de3f8ca9ae8016aff70de0ed2ffae419891843b288
BLAKE2b-256 checksum
How to use checksums
b26ac3722ae5c1bcce368c613c9a1d939cb866d0d053a52342d4ce748a5ab7b8
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 27, 2026.

Transparency log

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

Download URL pylibhmm-0.11.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
a1ad2137a3f1e96b09b3356014354f882b89b9f9fc074da96e93b1c57e1fdfd2
BLAKE2b-256 checksum
How to use checksums
4ec7e88718d355b9378230c9e32e31354d13ecdc0dfa917a1a19434612fad05c
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 27, 2026.

Transparency log

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

Download URL pylibhmm-0.11.1-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
30b18a0c3c0a6f71da6c0b106caad264e2992c7c3969751b60cf3bf0577f1958
BLAKE2b-256 checksum
How to use checksums
0c600f4429989cf4bf544fc8602b6109126aac481249d01fe04ae5d1925275aa
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 27, 2026.

Transparency log

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

Download URL pylibhmm-0.11.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
e5cbe401ae4da1bd27b422966780b00309a40633c8e4a0b601befd7e4946002b
BLAKE2b-256 checksum
How to use checksums
25be8bd515747c30c8cd7b30ae4b89bfe933cccdd3e8dfa04e30e0194a948359
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 27, 2026.

Transparency log

Security for pylibhmm 0.11.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.11.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 Aug 27, 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