Skip to main content

LempelZiv-76 complexity engine

Project description

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 compression-based distance metrics for sequence comparison
  • 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"
result = lz.lz76(seq)

print(f"LZ76 Complexity: {result.complexity}")
print(f"Entropy density: {result.entropy}")
print(f"Effective complexity: {result.effective_complexity}")

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.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

lzcomplexity-0.10.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

lzcomplexity-0.10.1-cp314-cp314-macosx_12_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.14macOS 12.0+ ARM64

lzcomplexity-0.10.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

lzcomplexity-0.10.1-cp313-cp313-macosx_12_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.13macOS 12.0+ ARM64

lzcomplexity-0.10.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

lzcomplexity-0.10.1-cp312-cp312-macosx_12_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.12macOS 12.0+ ARM64

lzcomplexity-0.10.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

lzcomplexity-0.10.1-cp311-cp311-macosx_12_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.11macOS 12.0+ ARM64

lzcomplexity-0.10.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

lzcomplexity-0.10.1-cp310-cp310-macosx_12_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.10macOS 12.0+ ARM64

lzcomplexity-0.10.1-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

lzcomplexity-0.10.1-cp39-cp39-macosx_12_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.9macOS 12.0+ ARM64

File details

Details for the file lzcomplexity-0.10.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.10.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b5ba2f1dc14e1325856a6771ff9682df1ff7ce3dff2a591f37cfd4c3a81b87d4
MD5 445b0dffe09319aa0d7b6c9d78004efa
BLAKE2b-256 9adbf492f77eb865fd2694fb0cdf5102df7db4066188bbdb496b7a9f957b56dd

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.10.1-cp314-cp314-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.10.1-cp314-cp314-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 666b9bb1d8162af6f349f25912f41732df648cfd94c83829a6376e05f89cc5c9
MD5 78df1c173e6f4e7b1b1417ca74f59d2a
BLAKE2b-256 66ab31aca71d56c2f7e18438c36c43d4587f1f98c5c95530a26332170185ab8a

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.10.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.10.1-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f23318569b8dd4550e9babcbe16e5058379f464da9b3724ff1f1bb91db3577f4
MD5 bda75348bbc821a41d0b64d908d7c32d
BLAKE2b-256 f2936953049f5b683ba2a54fc5b5eb152bc5a8df3d3c4368f04a0f3e6fc2ee03

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.10.1-cp313-cp313-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.10.1-cp313-cp313-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 4da10dfe0fd7609302211c6adf66ead1823fb845c5ff3b85a4888c4907df0d08
MD5 50174675f925c840bb49e68e4f7b1087
BLAKE2b-256 0a22e0ccea90757badcde6942e58871095719930bb639601b405a39302e682f5

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.10.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.10.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9a78ecbfc65d206b0ed2871c6a12d1e4d2a8f5fb82b1cae9e582b13fc913e0ce
MD5 e5603a5aa62789257e154c80f341c87c
BLAKE2b-256 73e5a2d083101ea59b9963e81d3584ec8f41d1b8fe18d7ad69e2f345b9f65540

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.10.1-cp312-cp312-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.10.1-cp312-cp312-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 dd8efee83b7910f8bdfc5f83abc1f3631eb98741ea4a597ff0e75686dad1bfef
MD5 abf942895713b0050fe0dec230d62618
BLAKE2b-256 d531f6578ec7de5aba8ce45b40c9492078c5471af1290d82fb87ef0d02fde3a3

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.10.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.10.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5d2e17aa947cb40cbf05943c6eb4c2e71f745bb99edb6c6abca1621cb5c27468
MD5 669dc629fa2b92aa561e42c88f422f31
BLAKE2b-256 d6662a0194ad9e3839b10c5dd66b906c20da99144e54662a41ed470019039d52

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.10.1-cp311-cp311-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.10.1-cp311-cp311-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 1fbd07576d8e772caf64eb814dad543af72e1c8855fc16f38870b5431a2c30a7
MD5 7cffba53fefc58e6972ec19aaf572a78
BLAKE2b-256 674c6d4a6a375577b4bb220317f3a82e743a33ed1f01e982855eb4947ce9230f

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.10.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.10.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6d08e067982ef1a3a7e94225e9907c7ebc0d25e531f79d00d58e3503629a24ca
MD5 342100aa38bb91f67e40a216a048ecb7
BLAKE2b-256 60c0b54b71cf2c9f2e0057c3000eb439af7dbfdd73c5150c1671c00f890bb135

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.10.1-cp310-cp310-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.10.1-cp310-cp310-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 d5c55e4406a1d530788bf26263b27bf2391f449ae25f9184d0149002c13b90c1
MD5 5df2f2164c659304414b1b990fc11afe
BLAKE2b-256 8ebda74defc9ea44797c17785233aab594df6f79c0dd79eca780663c91eb3a57

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.10.1-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.10.1-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d947b2df81e7cd01ee7fd19416d3ab8f2efc345799c5bcb7d68ab755c3c8bf51
MD5 f8dc9f24df40b8fa9593f6d678b83786
BLAKE2b-256 28cac428b298aadb1023bd88babaa66c04889ef559a98fd9b93ac799b7894f03

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.10.1-cp39-cp39-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.10.1-cp39-cp39-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 779bdda1a068c2cf20034596d2dd1c8a6de92949911ff7c8c049b23df8dabc69
MD5 1ce1950a2928231ae9203764d0824bfd
BLAKE2b-256 33be1b3aaa6bb1138c151ea72c15f64517ad13b0aa8e3329ff2a2ad1f06f7850

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page