Skip to main content

VLMC logo

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_size must be at least two.
  • max_depth is the largest candidate history length.
  • method is "bct", "bic", or "peres_shield".
  • beta is BCT-only and must satisfy 0.5 <= beta < 1, the range in which the algorithm identifies the exact MAP tree. When omitted it is 1 - 2 ** (-(alphabet_size - 1)), the value recommended by the BCT paper.
  • penalty is BIC-only and multiplies the standard BIC penalty. It defaults to 1.
  • boundary="condition" treats every row as an independent realization. For a depth D, its first D symbols form the conditioned initial history and only later symbols are fitted. Rows are never concatenated. A row of length at most D therefore 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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vlmc-0.3.0.tar.gz (19.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

vlmc-0.3.0-cp310-abi3-win_amd64.whl (157.3 kB view details)

Uploaded CPython 3.10+Windows x86-64

vlmc-0.3.0-cp310-abi3-win32.whl (148.4 kB view details)

Uploaded CPython 3.10+Windows x86

vlmc-0.3.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (295.1 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

vlmc-0.3.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (323.5 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ s390x

vlmc-0.3.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (408.1 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ppc64le

vlmc-0.3.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (298.0 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARMv7l

vlmc-0.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (292.2 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

vlmc-0.3.0-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl (318.0 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.5+ i686

vlmc-0.3.0-cp310-abi3-macosx_11_0_arm64.whl (254.5 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

vlmc-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl (256.8 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file vlmc-0.3.0.tar.gz.

File metadata

  • Download URL: vlmc-0.3.0.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for vlmc-0.3.0.tar.gz
Algorithm Hash digest
SHA256 10918ab2ba5177d9a674e15cc91e4739f6d3f6a8617589d881eb8e62aa599763
MD5 a91c7703e7cc290b2d1129e8208f4ebf
BLAKE2b-256 df7eecc53624a128bd611c820a9340486218df0caa1e88c5ac8ea8723655d88f

See more details on using hashes here.

File details

Details for the file vlmc-0.3.0-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: vlmc-0.3.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 157.3 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using 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}

File hashes

Hashes for vlmc-0.3.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 02eb3cec9c9c850ee076141f93dd4d8110fe2285c8550759f03403bbfb386b98
MD5 e9b411b68741b45231498019b307be1e
BLAKE2b-256 0d964ff1f0324e8a9e49ed0cdcbc93b084f8d5d8e032fbca96c792fd54def27b

See more details on using hashes here.

File details

Details for the file vlmc-0.3.0-cp310-abi3-win32.whl.

File metadata

  • Download URL: vlmc-0.3.0-cp310-abi3-win32.whl
  • Upload date:
  • Size: 148.4 kB
  • Tags: CPython 3.10+, Windows x86
  • Uploaded using 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}

File hashes

Hashes for vlmc-0.3.0-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 4c5b80cab6a47761013f8d87f6d427d79cf70e3c42204f1194d0ea4edd37e7da
MD5 571fda153c01f7acf700e23152e2f06f
BLAKE2b-256 997e2e367d0ba77fe54e4c74e97a585ba59a218bb12f4e7503109f9eef18e646

See more details on using hashes here.

File details

Details for the file vlmc-0.3.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: vlmc-0.3.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 295.1 kB
  • Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
  • Uploaded using 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}

File hashes

Hashes for vlmc-0.3.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ab57eb38637725ce24978b40792ac1e69a9befe319ce1ef127b753a2810dbdbd
MD5 a18061e812b5ba85ec6269e05261019f
BLAKE2b-256 c3ba66b140b0da1271e41a2eedc82fa5b4de438d0f45b0cae01ced0179d121ca

See more details on using hashes here.

File details

Details for the file vlmc-0.3.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

  • Download URL: vlmc-0.3.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
  • Upload date:
  • Size: 323.5 kB
  • Tags: CPython 3.10+, manylinux: glibc 2.17+ s390x
  • Uploaded using 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}

File hashes

Hashes for vlmc-0.3.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 056b248e9099338f4676094a9d0f77c957c62b9213b504a547e4b5be81746469
MD5 269ac9fe2b490dbf20e9cc727a9e2ef3
BLAKE2b-256 a024aaa4b117198da346c4a8629c68d8c5adbf1b1f4474bc758a1501fe2a410d

See more details on using hashes here.

File details

Details for the file vlmc-0.3.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

  • Download URL: vlmc-0.3.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
  • Upload date:
  • Size: 408.1 kB
  • Tags: CPython 3.10+, manylinux: glibc 2.17+ ppc64le
  • Uploaded using 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}

File hashes

Hashes for vlmc-0.3.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 ad40298bb91f7f149939ffb62ce1f2ecd8a0d64d2ef0eb3b51f90f00601773ce
MD5 eee66db9fda5d3e0bf29de0773000e48
BLAKE2b-256 aa26a30bbe045a7b68d9a1ff72bd1814fa420ffccd84bb287f8f5b75e5a6f58c

See more details on using hashes here.

File details

Details for the file vlmc-0.3.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

  • Download URL: vlmc-0.3.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
  • Upload date:
  • Size: 298.0 kB
  • Tags: CPython 3.10+, manylinux: glibc 2.17+ ARMv7l
  • Uploaded using 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}

File hashes

Hashes for vlmc-0.3.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 d638bde009f917a6843922806d7f330ca1b3bbc79ac39307ab99adb681ae3c84
MD5 a4c76d089bde13d1005f7fa3a9bb7e12
BLAKE2b-256 ff9097704ef6690fe558864b4ebe8be2b76ffd8b0677d448eb382add2bb88a31

See more details on using hashes here.

File details

Details for the file vlmc-0.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

  • Download URL: vlmc-0.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
  • Upload date:
  • Size: 292.2 kB
  • Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64
  • Uploaded using 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}

File hashes

Hashes for vlmc-0.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0d9fe10160069a0f013b8f002c650eaf5fe918f5b2f50cd2c281829560081cec
MD5 42b44daec3d525d4f9aa0136a551e56e
BLAKE2b-256 691dc46a1a058cab14706a30ac46ced8d2d8958685f963a3bf12576cdd8b45d4

See more details on using hashes here.

File details

Details for the file vlmc-0.3.0-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl.

File metadata

  • Download URL: vlmc-0.3.0-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl
  • Upload date:
  • Size: 318.0 kB
  • Tags: CPython 3.10+, manylinux: glibc 2.5+ i686
  • Uploaded using 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}

File hashes

Hashes for vlmc-0.3.0-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 9057cd13b5a4c9734c03bdc7e45e3f1f4b4bac58153f985d985c417e0e2edc5f
MD5 04a290862daa07e66dd005aa96504682
BLAKE2b-256 093f3293efc59abede03e64db13daeeeca27b947c89ec399619b8c336d35fa8b

See more details on using hashes here.

File details

Details for the file vlmc-0.3.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

  • Download URL: vlmc-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 254.5 kB
  • Tags: CPython 3.10+, macOS 11.0+ ARM64
  • Uploaded using 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}

File hashes

Hashes for vlmc-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 16473137d34a50f11056f9706587b3e4e9ae088a96d5f81819f81bb7dc2283c4
MD5 01a5719541eb0855730c7ff7d3b65d05
BLAKE2b-256 33b1f48f9015db158c53b2054479603989a74eb1f24d4ec202fc44a406efd440

See more details on using hashes here.

File details

Details for the file vlmc-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

  • Download URL: vlmc-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl
  • Upload date:
  • Size: 256.8 kB
  • Tags: CPython 3.10+, macOS 10.12+ x86-64
  • Uploaded using 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}

File hashes

Hashes for vlmc-0.3.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4a62c551c9462b5190285f40a025c5fb31850f665d56594f7ebfe571413180d4
MD5 760c20915505d98cb6730a8b0fa116f4
BLAKE2b-256 ecdfdee74536c9f2fb11793ae9a38dfe2e57c3b3f7fea2ccf742c293812216ab

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.3.0 This release

11 files

0.2.0

11 files

0.1.5

11 files

0.1.2

2 files

0.1.1

1 file

0.1.0

2 files

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