Skip to main content

lzcomplexity: an entropy measures library

MIT python C++

lzcomplexity

lzcomplexity is a high-performance C++ library developed for complexity analysis using entropic metrics such as entropy density, effective measure complexity, and informational distance. The algorithms used to estimate the metrics employing Lempel-Ziv factorization (LZ76) [1]. The library provides efficient implementations for analyzing time series data, with applications in information theory, signal processing, and neuroscience.

Overview

The Lempel-Ziv complexity is a non-parametric measure of algorithmic complexity that quantifies the rate at which new patterns appear in a sequence. Unlike Shannon entropy, which assumes statistical stationarity and independence, LZ complexity captures the sequential structure and can estimate the entropy rate of ergodic sources asymptotically [2].

Key Features

  • LZ76 Factorization: Efficient computation of Lempel-Ziv complexity using the CaPS (Cache-friendly Parallel Suffix array) algorithm [3]
  • Entropy Density: Normalized entropy rate estimation based on LZ factorization
  • Effective Complexity: Effective measure complexity measures quantifying statistical dependencies between sequence halves
  • Information Distance: Normalized LZ factorization, conditional entropy based distance.
  • Parallel Processing: Multi-threaded computation with support for multiple backends (OpenMP, Intel TBB, Cilk, or sequential fallback)

Theoretical Background

The LZ76 complexity c(S) of a sequence S of length n is defined as the minimum number of factors in a factorization where each factor is either:

  1. A symbol not previously seen, or
  2. The longest substring that has appeared earlier in the sequence

For a random sequence over an alphabet of size k, the expected complexity grows as n / log_k(n). The normalized entropy density h is estimated as:

h ≈ c(S) · log_k(n) / n

which converges to the true entropy rate for ergodic sources as $n → \infty$ [2].

Prerequisites

  • CMake version >= 3.5
  • C++20 compatible compiler:
    • apple-clang >= 14
    • clang >= 17
    • GNU >= 9.4
  • At least one parallel backend (optional but recommended):
    • OpenMP (default, widely available)
    • Intel oneTBB (bundled or system installation)
    • OpenCilk or Intel Cilk Plus
    • Falls back to sequential execution if none available

Prepare the Local Workspace

The project uses external submodules:

  • oneTBB: Intel's Threading Building Blocks for parallel computation (optional)
  • nanobind: Small binding library for C++/Python interoperability for the Python bindings
  1. Initialize the submodules:
git submodule init
  1. Clone the submodules into your local directory:
git submodule update --recursive
  1. Apply the oneTBB patch:
patch external/tbb/CMakeLists.txt patches/tbb.patch 

Build and Install

  1. Create a build directory and navigate to it:
mkdir build && cd build
  1. Configure the build process using CMake:
cmake -DCMAKE_BUILD_TYPE=Release ..
  1. Build and install the library:
make install

Documentation

After installation, access the command-line documentation via man pages:

man lzcomplexity
man lzdistance

To disable man page installation, use -DLZ_INSTALL_MAN=OFF during CMake configuration.

CMake Options

Build Configuration

Option Default Description
LZ_SHARE ON Build as shared library (.so/.dylib)
LZ_ONLY_LIBS OFF Build only libraries (lzcore, lzapp, lzdist) without executables
LZ_ONLY_CORE OFF Build only the core library
LZ_APP ON Build the lzcomplexity standalone application
LZ_DISTANCE ON Build the lzdistance standalone application
LZ_INSTALL_MAN ON Install man pages for command-line tools
BUILD_PYTHON OFF Enable Python bindings via nanobind

Parallel Backend Configuration

The library supports multiple parallel computing backends. By default, it auto-detects the best available backend.

Option Default Description
LZ_PARALLEL_BACKEND AUTO Parallel backend selection: AUTO, OPENMP, TBB, CILK, THREADS
LZ_PARALLEL_FORCE OFF Force the selected backend (fail if not found)
BUILTIN_TBB OFF Use bundled oneTBB instead of system installation

Backend Priority (AUTO mode):

  1. OpenMP - Default choice, widely available on most systems
  2. TBB - Intel Threading Building Blocks, excellent for fine-grained parallelism
  3. Cilk - OpenCilk or Intel Cilk Plus, good for divide-and-conquer algorithms
  4. Threads - Sequential fallback using std::thread utilities only

Examples:

# Auto-detect best available backend (default)
cmake -B build

# Force OpenMP backend
cmake -B build -DLZ_PARALLEL_BACKEND=OPENMP

# Force TBB with bundled version
cmake -B build -DLZ_PARALLEL_BACKEND=TBB -DBUILTIN_TBB=ON

# Force Cilk backend (requires OpenCilk compiler)
cmake -B build -DLZ_PARALLEL_BACKEND=CILK

# Sequential only (no parallelism)
cmake -B build -DLZ_PARALLEL_BACKEND=THREADS

macOS Note: For OpenMP on macOS, install libomp via Homebrew:

brew install libomp

Debug and Sanitizer Options

Option Default Description
ASAN OFF Enable sanitizers for debugging (Clang only)
ENABLE_ADDRESS_SANITIZER OFF Detect memory errors (buffer overflows, use-after-free)
ENABLE_MEMORY_SANITIZER OFF Detect uninitialized memory reads
ENABLE_UNDEFINED_SANITIZER OFF Detect undefined behavior

Example Usage

C++ Example

#include <lz/lempelziv.h>
#include <iostream>

int main() {
    // Create a symbolic sequence
    lz::sequence seq = "ABRACADABRA";
    
    // Compute LZ76 complexity (number of factors)
    auto complexity = lz::lz76Factorization(seq);
    
    // Compute normalized entropy density
    auto entropy = lz::lz76EntropyDensity(seq);
    
    // Compute effective complexity (excess entropy)
    auto effective = lz::lz76EffectiveComplexity(seq);
    
    std::cout << "LZ76 Complexity: " << complexity << std::endl;
    std::cout << "Entropy density: " << entropy << std::endl;
    std::cout << "Effective complexity: " << effective << std::endl;
    
    return 0;
}

Python Example

import lzcomplexity as lz

# Analyze a symbolic sequence
seq = "ABRACADABRA"
complexity, h, _, (emc, _, _) = lz.lz76(seq)

print(f"LZ76 Complexity: {complexity}")
print(f"Entropy density: {h}")
print(f"Effective complexity: {emc}")

References

  1. Lempel, A., & Ziv, J. (1976). On the complexity of finite sequences. IEEE Transactions on Information Theory, 22(1), 75-81.

  2. Kontoyiannis, I., Algoet, P. H., Suhov, Y. M., & Wyner, A. J. (1998). Nonparametric entropy estimation for stationary processes and random fields, with applications to English text. IEEE Transactions on Information Theory, 44(3), 1319-1327.

  3. Khan, J., Rubel, T., Dhulipala, L., Molloy, E., & Patro, R. (2023). Fast, Parallel, and Cache-Friendly Suffix Array Construction. arXiv preprint arXiv:2305.07024.

Citation

If you use this library in your research, please cite:

@software{lzcomplexity_2025, 
  title={lzcomplexity: an entropy measurement library},
  author={Efren Aragon-Perez},
  url={https://github.com/pleros-ai/lzcomplexity}, 
  year={2025} 
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.

Metadata

Release files for lzcomplexity 0.10.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for lzcomplexity 0.10.2
File
lzcomplexity-0.10.2-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details
lzcomplexity-0.10.2-cp314-cp314-macosx_14_0_arm64.whl CPython 3.14 CPython 3.14 macOS 14.0+ ARM64 Details
lzcomplexity-0.10.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details
lzcomplexity-0.10.2-cp313-cp313-macosx_14_0_arm64.whl CPython 3.13 CPython 3.13 macOS 14.0+ ARM64 Details
lzcomplexity-0.10.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details
lzcomplexity-0.10.2-cp312-cp312-macosx_14_0_arm64.whl CPython 3.12 CPython 3.12 macOS 14.0+ ARM64 Details
lzcomplexity-0.10.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details
lzcomplexity-0.10.2-cp311-cp311-macosx_14_0_arm64.whl CPython 3.11 CPython 3.11 macOS 14.0+ ARM64 Details
lzcomplexity-0.10.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details
lzcomplexity-0.10.2-cp310-cp310-macosx_14_0_arm64.whl CPython 3.10 CPython 3.10 macOS 14.0+ ARM64 Details
lzcomplexity-0.10.2-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details
lzcomplexity-0.10.2-cp39-cp39-macosx_14_0_arm64.whl CPython 3.9 CPython 3.9 macOS 14.0+ ARM64 Details

Total release size: 14.8 MB

Release files / lzcomplexity-0.10.2-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL lzcomplexity-0.10.2-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 1.2 MB
Tags CPython 3.14 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
11016f618eeef4e1a1c336e3db0541b269a6ef0656e621594eb9957481fcefb9
BLAKE2b-256 checksum
How to use checksums
a06ba6f259470d2abd65f2c664abce579f6235b6ca7a3acfa5faafd3c6e3f270
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 7, 2026.

Transparency log

Release files / lzcomplexity-0.10.2-cp314-cp314-macosx_14_0_arm64.whl

Download URL lzcomplexity-0.10.2-cp314-cp314-macosx_14_0_arm64.whl
Size 1.2 MB
Tags CPython 3.14 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
de8486686e11b3bc741b41aa0eaa34f41ae1479ab050a9c213775b0b7142eab2
BLAKE2b-256 checksum
How to use checksums
031c1d36f041f74828a393a642d24173ed2a3f8cea9facfb2669f40816fb8e7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 7, 2026.

Transparency log

Release files / lzcomplexity-0.10.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL lzcomplexity-0.10.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 1.2 MB
Tags CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
39cdf29487283db9fe390dea5c696203ce51202c6bf6ad4746764b60c4228314
BLAKE2b-256 checksum
How to use checksums
cd274c69d7ae3e313b561d31676d393bae1045555091facca11d59fd667fad85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 7, 2026.

Transparency log

Release files / lzcomplexity-0.10.2-cp313-cp313-macosx_14_0_arm64.whl

Download URL lzcomplexity-0.10.2-cp313-cp313-macosx_14_0_arm64.whl
Size 1.2 MB
Tags CPython 3.13 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
241737d32f808da2cd5172a86849b7b26089912926d415f1b176066d13a82957
BLAKE2b-256 checksum
How to use checksums
ae58ad475921aeee9e1eb39e7d7e9f6b8979010f0e567ca06cffa4d9ae42dafd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 7, 2026.

Transparency log

Release files / lzcomplexity-0.10.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL lzcomplexity-0.10.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 1.2 MB
Tags CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
e6cc20e7599d02e37095f17659c6f002ee1591c4542b0b0ec8c1424ca46d4818
BLAKE2b-256 checksum
How to use checksums
212aaf591d92b253a84a510aa2a9771a61c45afd76da80bd5abe2d1e18c6cf9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 7, 2026.

Transparency log

Release files / lzcomplexity-0.10.2-cp312-cp312-macosx_14_0_arm64.whl

Download URL lzcomplexity-0.10.2-cp312-cp312-macosx_14_0_arm64.whl
Size 1.2 MB
Tags CPython 3.12 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
7606f3fe787c3165478ae286f2368906662ad1ba48912a1d7b6f6c8d02dc2907
BLAKE2b-256 checksum
How to use checksums
c3ba842c550da331e5e706e1a498f33a0db1ecdc264ef0d9c1f2c993053b0b9d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 7, 2026.

Transparency log

Release files / lzcomplexity-0.10.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL lzcomplexity-0.10.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 1.2 MB
Tags CPython 3.11 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
9383de52cd7b7e64528c35d393fe5a4bc735c307016b9efcce1403f065a3a7ba
BLAKE2b-256 checksum
How to use checksums
ba19cb09a4cd53d1fc29b733022421c46b625e32d00f80d6a21371f956884a03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 7, 2026.

Transparency log

Release files / lzcomplexity-0.10.2-cp311-cp311-macosx_14_0_arm64.whl

Download URL lzcomplexity-0.10.2-cp311-cp311-macosx_14_0_arm64.whl
Size 1.2 MB
Tags CPython 3.11 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
9af92141f88a263138c6a13a2b914f87835009adc76471b55ee36d3a33a0e767
BLAKE2b-256 checksum
How to use checksums
891f773331f37816ca03a468d18c665eb7bfedee9bd067494ac52c51b6afab16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 7, 2026.

Transparency log

Release files / lzcomplexity-0.10.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL lzcomplexity-0.10.2-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 1.2 MB
Tags CPython 3.10 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
d4d59938615dc43704aab13c107c2b6e92aab5d1b139a767916b06edb24b3579
BLAKE2b-256 checksum
How to use checksums
bd57756df59ce0094a7de92b63a2f20e2c09327c1ecf62026638a476849b1c6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 7, 2026.

Transparency log

Release files / lzcomplexity-0.10.2-cp310-cp310-macosx_14_0_arm64.whl

Download URL lzcomplexity-0.10.2-cp310-cp310-macosx_14_0_arm64.whl
Size 1.2 MB
Tags CPython 3.10 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
7a96160239aa145fd4262bfeceb7b6438eec37be8ae42cc5185bcf433620f90d
BLAKE2b-256 checksum
How to use checksums
b3e4b14df0a942b95d934be10aa3c930af28cda6dba17d4fb47c35a34e6e8a21
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 7, 2026.

Transparency log

Release files / lzcomplexity-0.10.2-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL lzcomplexity-0.10.2-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 1.2 MB
Tags CPython 3.9 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
35250a6e9d469587aee16cfab70109fefc52a6cbd7a916f582668463ea1d3378
BLAKE2b-256 checksum
How to use checksums
fe7304ffac2c98c20c80c6927ba169adced504719c193cd81f7991b67ef4e7bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 7, 2026.

Transparency log

Release files / lzcomplexity-0.10.2-cp39-cp39-macosx_14_0_arm64.whl

Download URL lzcomplexity-0.10.2-cp39-cp39-macosx_14_0_arm64.whl
Size 1.2 MB
Tags CPython 3.9 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
73f4d0b9e0f1ad873736f7e397d73d52c74d194e8ead851de1de05f0bec6899c
BLAKE2b-256 checksum
How to use checksums
ef73f3abf5873b58656d32615f801b543bbab59c8b871c4a64633d1e20aabcd1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 7, 2026.

Transparency log

Release history Release notifications | RSS feed

2.0.0

6 release files

1.0.2

6 release files

1.0.1

6 release files

1.0.0

6 release files

0.13.0

6 release files

0.12.0

6 release files

0.11.0

6 release files

This release

0.10.2 This release

12 release 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