antropy


Nameantropy JSON
Version 0.1.8 PyPI version JSON
download
home_pageNone
SummaryAntroPy: entropy and complexity of time-series in Python
upload_time2024-12-21 12:58:14
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseBSD (3-clause)
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. -*- mode: rst -*-

|

.. image:: https://img.shields.io/github/license/raphaelvallat/antropy.svg
  :target: https://github.com/raphaelvallat/antropy/blob/master/LICENSE

.. image:: https://github.com/raphaelvallat/antropy/actions/workflows/python_tests.yml/badge.svg
  :target: https://github.com/raphaelvallat/antropy/actions/workflows/python_tests.yml

.. image:: https://codecov.io/gh/raphaelvallat/antropy/branch/master/graph/badge.svg
  :target: https://codecov.io/gh/raphaelvallat/antropy

----------------

.. figure::  https://github.com/raphaelvallat/antropy/blob/master/docs/pictures/logo.png?raw=true
   :align:   center

AntroPy is a Python 3 package providing several time-efficient algorithms for computing the complexity of time-series.
It can be used for example to extract features from EEG signals.

Documentation
=============

- `Link to documentation <https://raphaelvallat.com/antropy/build/html/index.html>`_

Installation
============

AntroPy can be installed with pip

.. code-block:: shell

  pip install antropy

or conda

.. code-block:: shell

  conda config --add channels conda-forge
  conda config --set channel_priority strict
  conda install antropy

To build and install from source, clone this repository or download the source archive and decompress the files

.. code-block:: shell

  cd antropy
  pip install ".[test]"     # install the package
  pip install -e ".[test]"  # or editable install
  pytest

**Dependencies**

- `numpy <https://numpy.org/>`_
- `scipy <https://www.scipy.org/>`_
- `scikit-learn <https://scikit-learn.org/>`_
- `numba <http://numba.pydata.org/>`_
- `stochastic <https://github.com/crflynn/stochastic>`_

Functions
=========

**Entropy**

.. code-block:: python

    import numpy as np
    import antropy as ant
    np.random.seed(1234567)
    x = np.random.normal(size=3000)
    # Permutation entropy
    print(ant.perm_entropy(x, normalize=True))
    # Spectral entropy
    print(ant.spectral_entropy(x, sf=100, method='welch', normalize=True))
    # Singular value decomposition entropy
    print(ant.svd_entropy(x, normalize=True))
    # Approximate entropy
    print(ant.app_entropy(x))
    # Sample entropy
    print(ant.sample_entropy(x))
    # Hjorth mobility and complexity
    print(ant.hjorth_params(x))
    # Number of zero-crossings
    print(ant.num_zerocross(x))
    # Lempel-Ziv complexity
    print(ant.lziv_complexity('01111000011001', normalize=True))

.. parsed-literal::

    0.9995371694290871
    0.9940882825422431
    0.9999110978316078
    2.015221318528564
    2.198595813245399
    (1.4313385010057378, 1.215335712274099)
    1531
    1.3597696150205727

**Fractal dimension**

.. code-block:: python

    # Petrosian fractal dimension
    print(ant.petrosian_fd(x))
    # Katz fractal dimension
    print(ant.katz_fd(x))
    # Higuchi fractal dimension
    print(ant.higuchi_fd(x))
    # Detrended fluctuation analysis
    print(ant.detrended_fluctuation(x))

.. parsed-literal::

    1.0310643385753608
    5.954272156665926
    2.005040632258251
    0.47903505674073327

Execution time
~~~~~~~~~~~~~~

Here are some benchmarks computed on a MacBook Pro (2020).

.. code-block:: python

    import numpy as np
    import antropy as ant
    np.random.seed(1234567)
    x = np.random.rand(1000)
    # Entropy
    %timeit ant.perm_entropy(x)
    %timeit ant.spectral_entropy(x, sf=100)
    %timeit ant.svd_entropy(x)
    %timeit ant.app_entropy(x)  # Slow
    %timeit ant.sample_entropy(x)  # Numba
    # Fractal dimension
    %timeit ant.petrosian_fd(x)
    %timeit ant.katz_fd(x)
    %timeit ant.higuchi_fd(x) # Numba
    %timeit ant.detrended_fluctuation(x) # Numba

.. parsed-literal::

    106 µs ± 5.49 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
    138 µs ± 3.53 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
    40.7 µs ± 303 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
    2.44 ms ± 134 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
    2.21 ms ± 35.4 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
    23.5 µs ± 695 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
    40.1 µs ± 2.09 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
    13.7 µs ± 251 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
    315 µs ± 10.7 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

Development
===========

AntroPy was created and is maintained by `Raphael Vallat <https://raphaelvallat.com>`_. Contributions are more than welcome so feel free to contact me, open an issue or submit a pull request!

To see the code or report a bug, please visit the `GitHub repository <https://github.com/raphaelvallat/antropy>`_.

Note that this program is provided with **NO WARRANTY OF ANY KIND**. Always double check the results.

Acknowledgement
===============

Several functions of AntroPy were adapted from:

- MNE-features: https://github.com/mne-tools/mne-features
- pyEntropy: https://github.com/nikdon/pyEntropy
- pyrem: https://github.com/gilestrolab/pyrem
- nolds: https://github.com/CSchoel/nolds

All the credit goes to the author of these excellent packages.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "antropy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "Raphael Vallat <raphaelvallat9@gmail.com>",
    "keywords": null,
    "author": null,
    "author_email": "Raphael Vallat <raphaelvallat9@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/8e/25/a6f731e9bf6481fca9d6f0c9cdf78372301cac8fc2afcd0d9588a8703134/antropy-0.1.8.tar.gz",
    "platform": null,
    "description": ".. -*- mode: rst -*-\n\n|\n\n.. image:: https://img.shields.io/github/license/raphaelvallat/antropy.svg\n  :target: https://github.com/raphaelvallat/antropy/blob/master/LICENSE\n\n.. image:: https://github.com/raphaelvallat/antropy/actions/workflows/python_tests.yml/badge.svg\n  :target: https://github.com/raphaelvallat/antropy/actions/workflows/python_tests.yml\n\n.. image:: https://codecov.io/gh/raphaelvallat/antropy/branch/master/graph/badge.svg\n  :target: https://codecov.io/gh/raphaelvallat/antropy\n\n----------------\n\n.. figure::  https://github.com/raphaelvallat/antropy/blob/master/docs/pictures/logo.png?raw=true\n   :align:   center\n\nAntroPy is a Python 3 package providing several time-efficient algorithms for computing the complexity of time-series.\nIt can be used for example to extract features from EEG signals.\n\nDocumentation\n=============\n\n- `Link to documentation <https://raphaelvallat.com/antropy/build/html/index.html>`_\n\nInstallation\n============\n\nAntroPy can be installed with pip\n\n.. code-block:: shell\n\n  pip install antropy\n\nor conda\n\n.. code-block:: shell\n\n  conda config --add channels conda-forge\n  conda config --set channel_priority strict\n  conda install antropy\n\nTo build and install from source, clone this repository or download the source archive and decompress the files\n\n.. code-block:: shell\n\n  cd antropy\n  pip install \".[test]\"     # install the package\n  pip install -e \".[test]\"  # or editable install\n  pytest\n\n**Dependencies**\n\n- `numpy <https://numpy.org/>`_\n- `scipy <https://www.scipy.org/>`_\n- `scikit-learn <https://scikit-learn.org/>`_\n- `numba <http://numba.pydata.org/>`_\n- `stochastic <https://github.com/crflynn/stochastic>`_\n\nFunctions\n=========\n\n**Entropy**\n\n.. code-block:: python\n\n    import numpy as np\n    import antropy as ant\n    np.random.seed(1234567)\n    x = np.random.normal(size=3000)\n    # Permutation entropy\n    print(ant.perm_entropy(x, normalize=True))\n    # Spectral entropy\n    print(ant.spectral_entropy(x, sf=100, method='welch', normalize=True))\n    # Singular value decomposition entropy\n    print(ant.svd_entropy(x, normalize=True))\n    # Approximate entropy\n    print(ant.app_entropy(x))\n    # Sample entropy\n    print(ant.sample_entropy(x))\n    # Hjorth mobility and complexity\n    print(ant.hjorth_params(x))\n    # Number of zero-crossings\n    print(ant.num_zerocross(x))\n    # Lempel-Ziv complexity\n    print(ant.lziv_complexity('01111000011001', normalize=True))\n\n.. parsed-literal::\n\n    0.9995371694290871\n    0.9940882825422431\n    0.9999110978316078\n    2.015221318528564\n    2.198595813245399\n    (1.4313385010057378, 1.215335712274099)\n    1531\n    1.3597696150205727\n\n**Fractal dimension**\n\n.. code-block:: python\n\n    # Petrosian fractal dimension\n    print(ant.petrosian_fd(x))\n    # Katz fractal dimension\n    print(ant.katz_fd(x))\n    # Higuchi fractal dimension\n    print(ant.higuchi_fd(x))\n    # Detrended fluctuation analysis\n    print(ant.detrended_fluctuation(x))\n\n.. parsed-literal::\n\n    1.0310643385753608\n    5.954272156665926\n    2.005040632258251\n    0.47903505674073327\n\nExecution time\n~~~~~~~~~~~~~~\n\nHere are some benchmarks computed on a MacBook Pro (2020).\n\n.. code-block:: python\n\n    import numpy as np\n    import antropy as ant\n    np.random.seed(1234567)\n    x = np.random.rand(1000)\n    # Entropy\n    %timeit ant.perm_entropy(x)\n    %timeit ant.spectral_entropy(x, sf=100)\n    %timeit ant.svd_entropy(x)\n    %timeit ant.app_entropy(x)  # Slow\n    %timeit ant.sample_entropy(x)  # Numba\n    # Fractal dimension\n    %timeit ant.petrosian_fd(x)\n    %timeit ant.katz_fd(x)\n    %timeit ant.higuchi_fd(x) # Numba\n    %timeit ant.detrended_fluctuation(x) # Numba\n\n.. parsed-literal::\n\n    106 \u00b5s \u00b1 5.49 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 10000 loops each)\n    138 \u00b5s \u00b1 3.53 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 10000 loops each)\n    40.7 \u00b5s \u00b1 303 ns per loop (mean \u00b1 std. dev. of 7 runs, 10000 loops each)\n    2.44 ms \u00b1 134 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 100 loops each)\n    2.21 ms \u00b1 35.4 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 100 loops each)\n    23.5 \u00b5s \u00b1 695 ns per loop (mean \u00b1 std. dev. of 7 runs, 10000 loops each)\n    40.1 \u00b5s \u00b1 2.09 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 10000 loops each)\n    13.7 \u00b5s \u00b1 251 ns per loop (mean \u00b1 std. dev. of 7 runs, 100000 loops each)\n    315 \u00b5s \u00b1 10.7 \u00b5s per loop (mean \u00b1 std. dev. of 7 runs, 1000 loops each)\n\nDevelopment\n===========\n\nAntroPy was created and is maintained by `Raphael Vallat <https://raphaelvallat.com>`_. Contributions are more than welcome so feel free to contact me, open an issue or submit a pull request!\n\nTo see the code or report a bug, please visit the `GitHub repository <https://github.com/raphaelvallat/antropy>`_.\n\nNote that this program is provided with **NO WARRANTY OF ANY KIND**. Always double check the results.\n\nAcknowledgement\n===============\n\nSeveral functions of AntroPy were adapted from:\n\n- MNE-features: https://github.com/mne-tools/mne-features\n- pyEntropy: https://github.com/nikdon/pyEntropy\n- pyrem: https://github.com/gilestrolab/pyrem\n- nolds: https://github.com/CSchoel/nolds\n\nAll the credit goes to the author of these excellent packages.\n",
    "bugtrack_url": null,
    "license": "BSD (3-clause)",
    "summary": "AntroPy: entropy and complexity of time-series in Python",
    "version": "0.1.8",
    "project_urls": {
        "Downloads": "https://github.com/raphaelvallat/antropy/",
        "Homepage": "https://github.com/raphaelvallat/antropy/"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fb1af99b9c553c7c16d1ef8c16c456dc08af1e9953d6890b009d7b5708d566b7",
                "md5": "6a49265559a7161bac15609b53670b5a",
                "sha256": "d3b882b172fcf9df2ec18c65020114e5adedf29095a5eb8e3342ce2ee8ca021d"
            },
            "downloads": -1,
            "filename": "antropy-0.1.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6a49265559a7161bac15609b53670b5a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 18934,
            "upload_time": "2024-12-21T12:58:11",
            "upload_time_iso_8601": "2024-12-21T12:58:11.882881Z",
            "url": "https://files.pythonhosted.org/packages/fb/1a/f99b9c553c7c16d1ef8c16c456dc08af1e9953d6890b009d7b5708d566b7/antropy-0.1.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8e25a6f731e9bf6481fca9d6f0c9cdf78372301cac8fc2afcd0d9588a8703134",
                "md5": "551926bb8e7782bbd1b53ea8240113fc",
                "sha256": "f7ec1762ff58047531cfa3a68ac65fe333089cc0da81cfb7d9be6afd0629fac4"
            },
            "downloads": -1,
            "filename": "antropy-0.1.8.tar.gz",
            "has_sig": false,
            "md5_digest": "551926bb8e7782bbd1b53ea8240113fc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 22814,
            "upload_time": "2024-12-21T12:58:14",
            "upload_time_iso_8601": "2024-12-21T12:58:14.204419Z",
            "url": "https://files.pythonhosted.org/packages/8e/25/a6f731e9bf6481fca9d6f0c9cdf78372301cac8fc2afcd0d9588a8703134/antropy-0.1.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-21 12:58:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "raphaelvallat",
    "github_project": "antropy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "antropy"
}
        
Elapsed time: 0.36564s