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.9.14-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.14-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.14-cp314-cp314-macosx_12_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.14macOS 12.0+ ARM64

lzcomplexity-0.9.14-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.14-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.14-cp313-cp313-macosx_12_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.13macOS 12.0+ ARM64

lzcomplexity-0.9.14-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.14-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.14-cp312-cp312-macosx_12_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.12macOS 12.0+ ARM64

lzcomplexity-0.9.14-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.14-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.14-cp311-cp311-macosx_12_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.11macOS 12.0+ ARM64

lzcomplexity-0.9.14-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.14-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.14-cp310-cp310-macosx_12_0_arm64.whl (1.3 MB view details)

Uploaded CPython 3.10macOS 12.0+ ARM64

lzcomplexity-0.9.14-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.14-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.14-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.14-cp314-cp314-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for lzcomplexity-0.9.14-cp314-cp314-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 7e9b78bfb35afe45cbc0297c73b07498abf7899a1dbeb84ddac145101f906090
MD5 54fa4cfc4ff7b5169aa57904d0871f8f
BLAKE2b-256 c5bd3dd82252f592d83c4f664790d8de4397e99a0d331b667ddf88c5ff842da2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.14-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 619a993d309c80485ecab50ffe8c9754431285ad3d77fe0b75d0fd69e20a679e
MD5 960d37d71e0ccad744dee74ddd2d8066
BLAKE2b-256 49c9609185550fbfe646369e0efa2a5dcecd7a852d1aa5bb181589dfdd084d0b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.14-cp314-cp314-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 21916736874a33d16fb348052703dde098f78e6ed637c61c519b759eb46e0c11
MD5 e656307007819a014d8009e92480a062
BLAKE2b-256 395c242f8d8d04a0bd3a080303653a26399639bc7533bfec15fdaca25dcba4ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.14-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e0a6044d7a1dc3cf6b8ab027d079c0bf035eb11c0b2629250a9d0c70164159e0
MD5 5054659dee7802105d6ae30cb55f6478
BLAKE2b-256 a703dbd4dd29b60084df2c412a552244491ae6c328ada2666246b446c906263e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.14-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 557345e7a2fc571133c2483ace6166e85b58ac61280381d1ce0260aee20aec52
MD5 13b196b52b5e8edd695fe812a9247dbc
BLAKE2b-256 c703f6becb1e8f3b8df55634e7bc71e8bbf3bfbbe9018804c96da4782d8d7af2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.14-cp313-cp313-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 8d5f7883d384a2ebd67de906abbf63389ea0fb0500119b7c7251db0773e6fb77
MD5 23a9cb67c01eb9b71d41f1dee4d8f63b
BLAKE2b-256 f557c4b10266b73553b7704d58b3fd7f470c88984778b61ef314b9556f950d33

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.14-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2d64447416378977cad951275ce8375ddcdd7f96d06625847c1921de4ca7af82
MD5 8c425b594d007ae05d6a80dcfe7e6c2c
BLAKE2b-256 24e19867db7f44b383bc4c09d5105dcccf29b5f0ac338a503773903293e7e0c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.14-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a980f13c159adfb5d6a8a41fbc358a767fe7b0aea4c9c6b6f1a05711659a0759
MD5 0376e61c5daa15ef7e6b229181e23e5e
BLAKE2b-256 66a3edaf76cda219abb1a2f06a10d41a7df89ae6e7c01e751bb2e732c999926c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.14-cp312-cp312-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 67257bbe0a85f58515199c00fff5dfee3b44209e1cf6dcda24c399ce43a72e3c
MD5 4ebbe05de238fdeeb8c9ace3cf46df7c
BLAKE2b-256 3a362b9021c33bff792a6b48b1535c9ea1e55284ef2049a34f24eda3adc76080

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.14-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 829f4e2f5c3afb2722f78d6e481b73d00ba8b9ad8a7dd5ab4200041474c2ab8c
MD5 3f0b219adbcb2d1b0270ccc6fdb0f2aa
BLAKE2b-256 ab7584d4c05d5a9972f734ce438da26a4f0853eba5c0140392af96adaea124c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.14-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9020680ac007729d2b839d73bd26d857d06b294596fdcbc58c9a1d9e6fa2fae3
MD5 f6068f65bff31f7a348f9d76498bbe87
BLAKE2b-256 ab35f83dbaaa2633398d2e95651aa1f312a262b88409a9f60f566efbed31277c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.14-cp311-cp311-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 34e299c55d5688c0f89378a62d3cd504ae5834d827db3affc1d458c02fed6e58
MD5 0a09de03163d6d8dad52154fdf2eb4fa
BLAKE2b-256 74a5e8d33dd5af63b6d24facf9f880c55d40b7fd0f8bac10ff39eeeaf4f23e98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.14-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 35e1ff353e4efb38b62fd7c99feb4a3ba47195211ccac9370b870bdcf9d29f20
MD5 4e6d0544ab9d2616f93fb32036503ea8
BLAKE2b-256 7279984ff8d8da1a1b4dc8a008a18128882594df08b2b9044d23faec79c24afc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.14-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 04fb900a1d8ff17b84343d53b16c4c37152558b2d1a90f337d08dabb225d37be
MD5 918efbec6ca390a48223ff611ab8521d
BLAKE2b-256 a5ed7772e9c584df0767d7be3498fff4921923a05b433c9d751e943b772c021c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.14-cp310-cp310-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 2e5d2811ad255af016ec87d107708dd3a1cd5736d12f5ca390b56145d9a091a5
MD5 bef1919fa4f42bace32634b6cce92214
BLAKE2b-256 b93deacef41680550750b575b783ecd19f605eaf8b1a3e7f7188680351b577d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.14-cp39-cp39-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b4541d9e436a8f1aabfe2b99ce05b1b3cd07c9951e0ca1ca71a35e005fa5bc67
MD5 57622e77255b6ccf68e4185d8127cf48
BLAKE2b-256 0067e4803641d6ed5d1a974fbc6b7cb485bc4c9bcb502ed46ce5bdaf59b02dc3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.14-cp39-cp39-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0a48a323f9270aef869944dc21b7b089f67e37236bea8a58d4535257ce25c1de
MD5 655963ca8253ae98866c2a2b728eac7d
BLAKE2b-256 91777cef437dbfd9d80c1d2a715e410747bc79fe10e90aa93f2a12dbda3f5bed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for lzcomplexity-0.9.14-cp39-cp39-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 d08a3ebe7f92c9b15a369bf49768b99436246c002ffd19873784461b0164361d
MD5 07ed1851c47a83f1d049d6c5b300ee44
BLAKE2b-256 d35c67bcb2fc378cd88ad9728b72be782c50df09f6793684060e59e128369770

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