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/efrenaragon96/LempelZiv}, 
  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.9.13-cp314-cp314-musllinux_1_2_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.14musllinux: musl 1.2+ x86-64

lzcomplexity-0.9.13-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

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

lzcomplexity-0.9.13-cp314-cp314-macosx_12_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.14macOS 12.0+ ARM64

lzcomplexity-0.9.13-cp313-cp313-musllinux_1_2_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

lzcomplexity-0.9.13-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

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

lzcomplexity-0.9.13-cp313-cp313-macosx_12_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.13macOS 12.0+ ARM64

lzcomplexity-0.9.13-cp312-cp312-musllinux_1_2_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

lzcomplexity-0.9.13-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

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

lzcomplexity-0.9.13-cp312-cp312-macosx_12_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.12macOS 12.0+ ARM64

lzcomplexity-0.9.13-cp311-cp311-musllinux_1_2_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

lzcomplexity-0.9.13-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

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

lzcomplexity-0.9.13-cp311-cp311-macosx_12_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.11macOS 12.0+ ARM64

lzcomplexity-0.9.13-cp310-cp310-musllinux_1_2_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

lzcomplexity-0.9.13-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

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

lzcomplexity-0.9.13-cp310-cp310-macosx_12_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.10macOS 12.0+ ARM64

lzcomplexity-0.9.13-cp39-cp39-musllinux_1_2_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.9musllinux: musl 1.2+ x86-64

lzcomplexity-0.9.13-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.3 MB view details)

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

lzcomplexity-0.9.13-cp39-cp39-macosx_12_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.9macOS 12.0+ ARM64

File details

Details for the file lzcomplexity-0.9.13-cp314-cp314-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.9.13-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 614dbd237f7f13713721b7d9753c1408330e208788e16e09982a233096ac2833
MD5 d4efed06d47865003ba63ca53855011f
BLAKE2b-256 963b0d9e95b0d6a36426cc45410d0b3db4ff788b64fd86f81f9f8645dc01f373

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.9.13-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.9.13-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 873be06e3c5382a05231dfe0f64879693074afd911de97b8ae9677f57a7d22a5
MD5 20212eb7c1353dec5f17d70e73705f01
BLAKE2b-256 f4c8c31bc275fabf76bbcc59db5012b4944174aa0fe3b51768cadcd88134592d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.13-cp314-cp314-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 ba5dee9f18d91f37728d8db150aae383cb6a81d2aef31c4479605f11bef47160
MD5 b2f9c72c3c74d88f42e032920ce50b4b
BLAKE2b-256 5e6166ea0f257fdc0bef21a0f3b4e51c4bd1d64271162907b110c49c06991178

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.9.13-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.9.13-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3fac1bc7778a4466dffbba6f3d1e408b07bab2a7b174e11a0ae114db82c7238d
MD5 578218d57a497a80b38669cf1668d758
BLAKE2b-256 cbbf89e6ae216d966f4addd9532e15416d25e4bc3dd7f389724c6384b2a0c826

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.9.13-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.9.13-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 67b246c630e84a48e82d0b3ff3bfcdac38369283e667a9563a71cb56602c897b
MD5 b44ce2229694c44c6d1e000be5f938a9
BLAKE2b-256 203d44d7b18ad940fbe5f325f95ce29b0d676731fe166c01834cebfbbeb9bb21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.13-cp313-cp313-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 a7d81b0e5fe71784d0075363365a5bee81bb2639179f723914e08d3e66a23bbd
MD5 8f6390fe0646aeefe3c046a8b778275b
BLAKE2b-256 e0d258920e5a461db7e25242cdfb912e8e5f5cabfc2b1ecd60475309daac7c64

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.9.13-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.9.13-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 bbd96f4f5bba14ed1b3b61185bb0ff87e9a8e77f4ce335ca58afc55ca5ffdabf
MD5 5528e61369bae93867c66adea81aa599
BLAKE2b-256 27f170c4c0c21d437769101bd1bba038a5ff7e993c25a11be5d718aeb1f759e5

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.9.13-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.9.13-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7820aca4be9e85da539a292aa73d677fdd005f85e4a4440b8f86698a478b5cb7
MD5 a0281c642ba62353c6dc679e9947cd50
BLAKE2b-256 fa969fba7f1fb320ab87a9750a19883bacd6946729ec80bb0c9c0b9f3ca23d0a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.13-cp312-cp312-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 74986caed8de9819bc8136f78e22b76b0300079dbddb3f783149af3705b54b4f
MD5 edf7123b52cbf2808c2a0fb8dcda58fb
BLAKE2b-256 b1ec62dc51793cf88d810df3804b55cf2c8ebee04f7c75f630c710463a1ed037

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.9.13-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.9.13-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4399125ed33e3f32cd49e7f2597137ecf15068b1e9fbb5830e91aaf419b39e5a
MD5 3e996506eb851d0e8ee8665bfa32f342
BLAKE2b-256 6689c5b58395240a87c23c7b3fe102d2953679160b65b967811294eaf4647798

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.9.13-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.9.13-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 319353521d939a235e60137dfa3625ffb746daa1adfde5abf0389c0fecec7e90
MD5 8f92baca9c95b30cdaae5e860aab3cf3
BLAKE2b-256 68eacdddaa076889f1b49b0ead834bd2f672ae9a92002522bbb2fcb7ac5acd60

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.13-cp311-cp311-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 6c040f1414934e689e9e8cec18a6b133d634a704cdb78c265226f399fa65f9fd
MD5 736e415e63e013b7939a181eb32e87e3
BLAKE2b-256 b334f22cfa9b0db5a4cdf75fdfa85ec93f01bf0fbd38e7111ed92d80722b4b7c

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.9.13-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.9.13-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 dd819fb74c18378e12e9f2b0a73c6d4fab40c1e928dba162d55d30ee0c7ad092
MD5 5ee7a51ac350d4702d52d92cef9287eb
BLAKE2b-256 515196183a20f018ceb48a8728f53d5b70e739887650384d9fb59eb0574d0c18

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.9.13-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.9.13-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8a80c938e86d141d7a7dcca5d63bcb4758d628999d3ffb648570d9056fff872a
MD5 0f95c8fd393bd6cacd50a24ccd0b6631
BLAKE2b-256 27cccf44415de7e5ec433247b9bafd9124e22ae765d78923097ec0a7e4e850e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.13-cp310-cp310-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 95e6a44cedf70581fa68cb41b7ddd2a6f1e7b6db57508e8e657ca92c42ebc927
MD5 09d4585f5c3c919b2ded985e37548dd9
BLAKE2b-256 cc4db94ec61661ca3bba42f8bc9256211682b410e82042091dbbc77e9d5da3c5

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.9.13-cp39-cp39-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.9.13-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 cbc610b60e238ff02f3f832167f4c370504cc4b04efbcda6f240b3dbffccc3ba
MD5 c9b55dc11cc645ab4a1e73584e34f827
BLAKE2b-256 cd21bb7ba66c6e132e283794735eb0d3322820e3aeae6fafe0ef00de850950dd

See more details on using hashes here.

File details

Details for the file lzcomplexity-0.9.13-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.9.13-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3e5a710ba6f4471ad6c417c84d3f74818340a6b2b00054ee72037f2649954fc0
MD5 a782ba7882bf69bc57fb09851eca95af
BLAKE2b-256 7ff0cb431d2b832c6fc9e1cd52c5d32f75b123d0f7de5cbbc8b85bad3eb7d51d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.13-cp39-cp39-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 95d5b883f78b071ff0e7b03ba5d993f50d069bf1417c697e92875db9c6cc8f1e
MD5 ac55b27bcb6588532ef1987076e34c68
BLAKE2b-256 8e1fc929dcb58d04b4a3e7e71cb38c91e639167a2d6df6ca1bd943e1c2fb3f38

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