Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

AntroPy: entropy and complexity of (EEG) time-series in Python

License

NotificationsYou must be signed in to change notification settings

raphaelvallat/antropy

Repository files navigation



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

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

Installation

AntroPy can be installed with pip

pip install antropy

or conda

conda config --add channels conda-forgeconda config --set channel_priority strictconda install antropy

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

cd antropypip install".[test]"# install the packagepip install -e".[test]"# or editable installpytest

Dependencies

Functions

Entropy

importnumpyasnpimportantropyasantnp.random.seed(1234567)x=np.random.normal(size=3000)# Permutation entropyprint(ant.perm_entropy(x,normalize=True))# Spectral entropyprint(ant.spectral_entropy(x,sf=100,method='welch',normalize=True))# Singular value decomposition entropyprint(ant.svd_entropy(x,normalize=True))# Approximate entropyprint(ant.app_entropy(x))# Sample entropyprint(ant.sample_entropy(x))# Hjorth mobility and complexityprint(ant.hjorth_params(x))# Number of zero-crossingsprint(ant.num_zerocross(x))# Lempel-Ziv complexityprint(ant.lziv_complexity('01111000011001',normalize=True))
0.99953716942908710.99408828254224310.99991109783160782.0152213185285642.198595813245399(1.4313385010057378, 1.215335712274099)15311.3597696150205727

Fractal dimension

# Petrosian fractal dimensionprint(ant.petrosian_fd(x))# Katz fractal dimensionprint(ant.katz_fd(x))# Higuchi fractal dimensionprint(ant.higuchi_fd(x))# Detrended fluctuation analysisprint(ant.detrended_fluctuation(x))
1.03106433857536085.9542721566659262.0050406322582510.47903505674073327

Execution time

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

importnumpyasnpimportantropyasantnp.random.seed(1234567)x=np.random.rand(1000)# Entropy%timeitant.perm_entropy(x)%timeitant.spectral_entropy(x,sf=100)%timeitant.svd_entropy(x)%timeitant.app_entropy(x)# Slow%timeitant.sample_entropy(x)# Numba# Fractal dimension%timeitant.petrosian_fd(x)%timeitant.katz_fd(x)%timeitant.higuchi_fd(x)# Numba%timeitant.detrended_fluctuation(x)# Numba
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 byRaphael Vallat. 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 theGitHub repository.

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

Acknowledgement

Several functions of AntroPy were adapted from:

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


[8]ページ先頭

©2009-2025 Movatter.jp