Skip to main content

Fast implementation of the Lempel-Ziv complexity function

Project description

This repository contains a small, simple and efficient implement of the Lempel-Ziv complexity algorithm.

Examples

Simple usage

If the lempel_ziv_complexity.py file is accessible in your PATH or in Python’s path:

>>> from lempel_ziv_complexity import lempel_ziv_complexity
>>> s = '1001111011000010'
>>> lempel_ziv_complexity(s)  # 1 / 0 / 01 / 11 / 10 / 110 / 00 / 010
8

Documentation

See this file.

With the C extension

If the lempel_ziv_complexity.so file is accessible in your PATH or in Python’s path, the same can be used.

Small benchmark

There is also a Cython version, to have a faster implementation:

$ ipython
...
>>> s = '1001111011000010'
>>> %timeit lempel_ziv_complexity(s)
6.1 µs ± 33.6 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
>>> %timeit lempel_ziv_complexity_cython(s)
132 ns ± 2.55 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

The speedup is typically between x50 and x100. It is not shipped with the PyPi version, see directly on GitHub if needed.

Demo on a Jupyter notebook

See this notebook: on nbviewever.


Install and build

Manually ?

Easy!

Clone this repository, go in the folder, compile, test, and if it works, install it.

cd /tmp/
git clone https://GitHub.com/Naereen/Lempel-Ziv_Complexity
cd Lempel-Ziv_Complexity/src/
make build
make test     # should pass
make install  # mv the build/lib*/*.so files where you need them

Be sure to include the dynamic library when you need it, or in a folder accessible by your Python interpreter (somewhere in sys.path). The file is lempel_ziv_complexity_cython.so (for Python 2) or the lempel_ziv_complexity_cython.cpython-35m-x86_64-linux-gnu.so (for Python 3.5, or higher, adapt the name).

With pip ?

This project is hosted on the Pypi package repository.

sudo pip install lempel_ziv_complexity
python -c "from lempel_ziv_complexity import lempel_ziv_complexity; print(lempel_ziv_complexity('1001111011000010') == 6)"  # test

PyPI version

PyPI implementation

PyPI pyversions


About

Language?

Python v2.7+ or Python v3.1+.

  • Numba can be used to speed up the pure Python version.

  • Cython is needed to build the C extension (faster).

License ?

MIT Licensed (file LICENSE). © Lilian Besson, 2017. GitHub license

Maintenance Ask Me Anything ! Analytics

ForTheBadge uses-badges ForTheBadge uses-git

forthebadge made-with-python ForTheBadge built-with-science

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 Distribution

lempel_ziv_complexity-0.2.2-py2.py3-none-any.whl (5.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file lempel_ziv_complexity-0.2.2-py2.py3-none-any.whl.

File metadata

  • Download URL: lempel_ziv_complexity-0.2.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.5

File hashes

Hashes for lempel_ziv_complexity-0.2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ee21e73b4a1d24a2b2b31c29a8ed8df386f437b93ff9e1061cd338f9e2b4f670
MD5 9107c9ef6cd2d3fedcc19666de340267
BLAKE2b-256 aa3f1e224fbc9d2af426937c0cfcb14c244bd29230f8343d9974b8103c9f35c1

See more details on using hashes here.

Supported by

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