Variable-Length Markov Chains for Python
vlmc fits variable-length Markov chains to discrete sequences. It provides one
Python model class with three context-tree selection methods:
| Method | Purpose | Main control |
|---|---|---|
bct |
Exact Bayesian context-tree MAP estimator; the default | beta |
bic |
Penalized maximum-likelihood / MDL baseline | penalty |
peres_shield |
Peres–Shields maximal-fluctuation estimator | sample size |
The implementation is written in Rust and exposed through Python bindings.
Installation
Published wheels can be installed with:
pip install vlmc
To build this checkout, install Rust and Maturin, activate a Python environment, and run:
pip install maturin
maturin develop --release
Quick start
import vlmc
rows = [
[0, 1, 0, 1, 0, 1],
[1, 0, 1, 0, 1, 0],
]
model = vlmc.VLMC(
alphabet_size=2,
max_depth=2,
method="bct", # default
)
model.fit(rows)
contexts = model.get_contexts()
context = model.get_suffix([1, 0, 1])
model.get_counts(context) # observations following this context
model.get_transition_counts(context) # raw next-symbol counts
model.get_distribution(context) # Jeffreys-smoothed probabilities
model.predict_proba([1, 0, 1]) # suffix lookup + probabilities
Symbols must be integers in 0 <= symbol < alphabet_size. Invalid symbols raise a
ValueError instead of panicking.
Constructor
vlmc.VLMC(
alphabet_size,
max_depth=10,
method="bct",
beta=None,
penalty=None,
boundary="condition",
)
alphabet_sizemust be at least two.max_depthis the largest candidate history length.methodis"bct","bic", or"peres_shield".betais BCT-only and must satisfy0.5 <= beta < 1, the range in which the algorithm identifies the exact MAP tree. When omitted it is1 - 2 ** (-(alphabet_size - 1)), the value recommended by the BCT paper.penaltyis BIC-only and multiplies the standard BIC penalty. It defaults to 1.boundary="condition"treats every row as an independent realization. For a depthD, its firstDsymbols form the conditioned initial history and only later symbols are fitted. Rows are never concatenated. A row of length at mostDtherefore contributes no fitted outcomes.
The fitted sample_size property reports the exact number of outcomes used by every
node comparison. node_count and context_count report the retained model size.
effective_max_depth equals max_depth for BCT/BIC and the data-dependent
ln(ln(sample_size)) cap for Peres–Shields.
Selection methods
BCT (default)
BCT selects a maximum a posteriori context tree using a Dirichlet-1/2 (Jeffreys) prior for transition probabilities. It is the recommended general-purpose default.
BIC
BIC maximizes
log maximum likelihood - penalty * leaves * (alphabet_size - 1) / 2 * log(sample_size)
This is useful when a conventional penalized maximum-likelihood model is preferred.
Peres–Shields
For an extension v and suffix w, this method uses the paper's raw-count
fluctuation
max_a |N(va) - N(wa) * N(v) / N(w)|
and the asymptotic threshold sample_size ** (3/4). Eligible extensions have
absolute depth at most min(max_depth, floor(ln(ln(sample_size)))). Because this is
an asymptotic criterion, it can be conservative for moderate samples.
Probability and context semantics
get_contexts() returns selected predictive contexts, ordered by length and then
lexically. BCT and BIC return leaves of a proper context tree. Peres–Shields may also
return an internal sparse fallback context together with deeper exceptional contexts,
as allowed by its prediction suffix tree construction.
get_distribution(context) always returns probabilities, using Jeffreys smoothing:
P(a | context) = (N(context, a) + 1/2) /
(N(context) + alphabet_size / 2)
Use get_transition_counts(context) when raw next-symbol counts are required.
get_counts(context) returns N(context), the number of usable outcomes following
that context.
References
- Kontoyiannis et al., Bayesian Context Trees: modelling and exact inference for discrete time series.
- Csiszár and Talata, Context tree estimation for not necessarily finite memory processes, via BIC and MDL.
- Dalevi and Dubhashi, The Peres–Shields Order Estimator for Fixed and Variable Length Markov Models.
Metadata
Release files for vlmc 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| vlmc-0.3.0.tar.gz | 19.2 kB | Without provenance | Details for vlmc-0.3.0.tar.gz |
Built distributions (wheels)
Total release size: 2.8 MB
Release files / vlmc-0.3.0.tar.gz
| Download URL | vlmc-0.3.0.tar.gz |
|---|---|
| Size | 19.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
10918ab2ba5177d9a674e15cc91e4739f6d3f6a8617589d881eb8e62aa599763
|
|
BLAKE2b-256 checksum How to use checksums |
df7eecc53624a128bd611c820a9340486218df0caa1e88c5ac8ea8723655d88f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / vlmc-0.3.0-cp310-abi3-win_amd64.whl
| Download URL | vlmc-0.3.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 157.3 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
02eb3cec9c9c850ee076141f93dd4d8110fe2285c8550759f03403bbfb386b98
|
|
BLAKE2b-256 checksum How to use checksums |
0d964ff1f0324e8a9e49ed0cdcbc93b084f8d5d8e032fbca96c792fd54def27b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / vlmc-0.3.0-cp310-abi3-win32.whl
| Download URL | vlmc-0.3.0-cp310-abi3-win32.whl |
|---|---|
| Size | 148.4 kB |
| Tags | CPython 3.10 Windows x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
4c5b80cab6a47761013f8d87f6d427d79cf70e3c42204f1194d0ea4edd37e7da
|
|
BLAKE2b-256 checksum How to use checksums |
997e2e367d0ba77fe54e4c74e97a585ba59a218bb12f4e7503109f9eef18e646
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / vlmc-0.3.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | vlmc-0.3.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 295.1 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
ab57eb38637725ce24978b40792ac1e69a9befe319ce1ef127b753a2810dbdbd
|
|
BLAKE2b-256 checksum How to use checksums |
c3ba66b140b0da1271e41a2eedc82fa5b4de438d0f45b0cae01ced0179d121ca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / vlmc-0.3.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
| Download URL | vlmc-0.3.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl |
|---|---|
| Size | 323.5 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ IBM System/390x abi3 |
|
SHA-256 checksum How to use checksums |
056b248e9099338f4676094a9d0f77c957c62b9213b504a547e4b5be81746469
|
|
BLAKE2b-256 checksum How to use checksums |
a024aaa4b117198da346c4a8629c68d8c5adbf1b1f4474bc758a1501fe2a410d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / vlmc-0.3.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
| Download URL | vlmc-0.3.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl |
|---|---|
| Size | 408.1 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ PowerPC 64-le abi3 |
|
SHA-256 checksum How to use checksums |
ad40298bb91f7f149939ffb62ce1f2ecd8a0d64d2ef0eb3b51f90f00601773ce
|
|
BLAKE2b-256 checksum How to use checksums |
aa26a30bbe045a7b68d9a1ff72bd1814fa420ffccd84bb287f8f5b75e5a6f58c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / vlmc-0.3.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
| Download URL | vlmc-0.3.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl |
|---|---|
| Size | 298.0 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
d638bde009f917a6843922806d7f330ca1b3bbc79ac39307ab99adb681ae3c84
|
|
BLAKE2b-256 checksum How to use checksums |
ff9097704ef6690fe558864b4ebe8be2b76ffd8b0677d448eb382add2bb88a31
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / vlmc-0.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | vlmc-0.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 292.2 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
0d9fe10160069a0f013b8f002c650eaf5fe918f5b2f50cd2c281829560081cec
|
|
BLAKE2b-256 checksum How to use checksums |
691dc46a1a058cab14706a30ac46ced8d2d8958685f963a3bf12576cdd8b45d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / vlmc-0.3.0-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl
| Download URL | vlmc-0.3.0-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl |
|---|---|
| Size | 318.0 kB |
| Tags | CPython 3.10 Linux glibc 2.5+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
9057cd13b5a4c9734c03bdc7e45e3f1f4b4bac58153f985d985c417e0e2edc5f
|
|
BLAKE2b-256 checksum How to use checksums |
093f3293efc59abede03e64db13daeeeca27b947c89ec399619b8c336d35fa8b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / vlmc-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | vlmc-0.3.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 254.5 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
16473137d34a50f11056f9706587b3e4e9ae088a96d5f81819f81bb7dc2283c4
|
|
BLAKE2b-256 checksum How to use checksums |
33b1f48f9015db158c53b2054479603989a74eb1f24d4ec202fc44a406efd440
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / vlmc-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | vlmc-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 256.8 kB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
4a62c551c9462b5190285f40a025c5fb31850f665d56594f7ebfe571413180d4
|
|
BLAKE2b-256 checksum How to use checksums |
ecdfdee74536c9f2fb11793ae9a38dfe2e57c3b3f7fea2ccf742c293812216ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for vlmc 0.3.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.