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.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.11.0
File Size Uploaded Provenance Actions
pylibhmm-0.11.0.tar.gz 66.7 kB With provenance Details for pylibhmm-0.11.0.tar.gz

Built distributions (wheels)

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

Total release size: 23.5 MB

Release files / pylibhmm-0.11.0.tar.gz

Download URL pylibhmm-0.11.0.tar.gz
Size 66.7 kB
Tags Source
SHA-256 checksum
How to use checksums
140d51edba550851ad4c22a2afabeae8b879cc9ba17fea63598a120caa811c74
BLAKE2b-256 checksum
How to use checksums
4af91072e9ca2c72442237728940f419e38f1d7fa56f135b473e4493e2d9aaa4
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 23, 2026.

Transparency log

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

Download URL pylibhmm-0.11.0-cp314-cp314t-win_amd64.whl
Size 4.1 MB
Tags CPython 3.14 CPython 3.14 free-threading Windows x86-64
SHA-256 checksum
How to use checksums
a3cb151ffd3c34c7ed3715a71bc4f4992c4ace875297bf9a3f25fa42124c4caf
BLAKE2b-256 checksum
How to use checksums
166c73027082e9f2531aade9b2610412721850a387e32346cf08b93a9b65547b
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 23, 2026.

Transparency log

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

Download URL pylibhmm-0.11.0-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
c6d1c655925eae5343640bad29e8723ea6b38b6e2394bb3eb9e3a9ad10eb680f
BLAKE2b-256 checksum
How to use checksums
6a136e6a3cc358c122253ddba26bc8401c14e7f15f36713db6aadca3dd7d8be1
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 23, 2026.

Transparency log

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

Download URL pylibhmm-0.11.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
2f930861d2ff2bf0d62e55412ce587aff471ebbfa4ad23e542e975fa79c1d1f8
BLAKE2b-256 checksum
How to use checksums
658819e8be84447c93c9c1f70ee9d7c2cb4a800ab9bb7548938ec09120e19486
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 23, 2026.

Transparency log

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

Download URL pylibhmm-0.11.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
5e6f0895f0496dc018300ba8e7e369f13a1afa8b74bf60c15999d9de9dd1e84a
BLAKE2b-256 checksum
How to use checksums
e22eafea31da0ee8089cd6e6a29046ef6cfb7c0aaa4fbb914ac2f1882fcae6bd
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 23, 2026.

Transparency log

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

Download URL pylibhmm-0.11.0-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
5b6ffc273691b4fc14ada799f28934d5fc7cf33736dc72661a4e696c4ef28eb1
BLAKE2b-256 checksum
How to use checksums
d622655ed27795e9946ca0b598ac128d4032954be7f56eaee5493c0054404eee
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 23, 2026.

Transparency log

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

Download URL pylibhmm-0.11.0-cp312-abi3-win_amd64.whl
Size 4.1 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
5cad12fd088477c01a63c5193f6c635bfad6919a70db75e28c8cf254cad47280
BLAKE2b-256 checksum
How to use checksums
01ae2a41f1363643a91966d60ee365c1d788f402374877c1ac4760a7f801125a
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 23, 2026.

Transparency log

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

Download URL pylibhmm-0.11.0-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
4f73848abfeac659f68891027447666f35558e1c51e2fae3ac41af49feeda3d9
BLAKE2b-256 checksum
How to use checksums
a64c1f2093270dc17abe121be6851f802eff380051442d94ffdb4fece07ad74e
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 23, 2026.

Transparency log

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

Download URL pylibhmm-0.11.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
3539e3d8393a449f0ebe585bb4026d34c13ad774b63fd4bdbb3d40287a219981
BLAKE2b-256 checksum
How to use checksums
4cb336ee9b7fed446b7ee0cd2984a75bb98617d0967ab445f96d6ac7b8bed247
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 23, 2026.

Transparency log

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

Download URL pylibhmm-0.11.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
e641a7df8c2e5da0ac0f931e06fd831462022cd4b4543a0096de7699c79862b3
BLAKE2b-256 checksum
How to use checksums
70e9d2c81a14d2329a6b2701e2bdf6b3a08ce11c21675513c919f18ebcba5909
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 23, 2026.

Transparency log

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

Download URL pylibhmm-0.11.0-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
6d38b94f3ffcb2ba35702df1d28a57bcaed064d7f86eba1e67980a4a142a4100
BLAKE2b-256 checksum
How to use checksums
323069b23f83cefe2588c4e4d737e96c8b57cd6b4a2dc586e4de1ba0a8207d10
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 23, 2026.

Transparency log

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