antropy 0.2.1__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- antropy-0.2.2/PKG-INFO +314 -0
- antropy-0.2.2/README.rst +287 -0
- {antropy-0.2.1 → antropy-0.2.2}/pyproject.toml +4 -3
- {antropy-0.2.1 → antropy-0.2.2}/src/antropy/__init__.py +1 -1
- {antropy-0.2.1 → antropy-0.2.2}/src/antropy/entropy.py +199 -51
- antropy-0.2.2/src/antropy.egg-info/PKG-INFO +314 -0
- {antropy-0.2.1 → antropy-0.2.2}/tests/test_entropy.py +139 -1
- antropy-0.2.1/PKG-INFO +0 -227
- antropy-0.2.1/README.rst +0 -200
- antropy-0.2.1/src/antropy.egg-info/PKG-INFO +0 -227
- {antropy-0.2.1 → antropy-0.2.2}/LICENSE +0 -0
- {antropy-0.2.1 → antropy-0.2.2}/MANIFEST.in +0 -0
- {antropy-0.2.1 → antropy-0.2.2}/setup.cfg +0 -0
- {antropy-0.2.1 → antropy-0.2.2}/src/antropy/fractal.py +0 -0
- {antropy-0.2.1 → antropy-0.2.2}/src/antropy/utils.py +0 -0
- {antropy-0.2.1 → antropy-0.2.2}/src/antropy.egg-info/SOURCES.txt +0 -0
- {antropy-0.2.1 → antropy-0.2.2}/src/antropy.egg-info/dependency_links.txt +0 -0
- {antropy-0.2.1 → antropy-0.2.2}/src/antropy.egg-info/requires.txt +0 -0
- {antropy-0.2.1 → antropy-0.2.2}/src/antropy.egg-info/top_level.txt +0 -0
- {antropy-0.2.1 → antropy-0.2.2}/tests/test_fractal.py +0 -0
- {antropy-0.2.1 → antropy-0.2.2}/tests/test_utils.py +0 -0
antropy-0.2.2/PKG-INFO
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: antropy
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Summary: AntroPy: entropy and complexity of time-series in Python
|
|
5
|
+
Author-email: Raphael Vallat <raphaelvallat9@gmail.com>
|
|
6
|
+
Maintainer-email: Raphael Vallat <raphaelvallat9@gmail.com>
|
|
7
|
+
License: BSD (3-clause)
|
|
8
|
+
Project-URL: Homepage, https://github.com/raphaelvallat/antropy/
|
|
9
|
+
Project-URL: Downloads, https://github.com/raphaelvallat/antropy/
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Operating System :: MacOS
|
|
12
|
+
Classifier: Operating System :: POSIX
|
|
13
|
+
Classifier: Operating System :: Unix
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/x-rst
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: numpy>=1.22.4
|
|
23
|
+
Requires-Dist: scipy>=1.8.0
|
|
24
|
+
Requires-Dist: scikit-learn>=1.2.0
|
|
25
|
+
Requires-Dist: numba>=0.57
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
.. -*- mode: rst -*-
|
|
29
|
+
|
|
30
|
+
|
|
|
31
|
+
|
|
32
|
+
.. image:: https://badge.fury.io/py/antropy.svg
|
|
33
|
+
:target: https://badge.fury.io/py/antropy
|
|
34
|
+
|
|
35
|
+
.. image:: https://img.shields.io/conda/vn/conda-forge/antropy.svg
|
|
36
|
+
:target: https://anaconda.org/conda-forge/antropy
|
|
37
|
+
|
|
38
|
+
.. image:: https://img.shields.io/github/license/raphaelvallat/antropy.svg
|
|
39
|
+
:target: https://github.com/raphaelvallat/antropy/blob/master/LICENSE
|
|
40
|
+
|
|
41
|
+
.. image:: https://github.com/raphaelvallat/antropy/actions/workflows/python_tests.yml/badge.svg
|
|
42
|
+
:target: https://github.com/raphaelvallat/antropy/actions/workflows/python_tests.yml
|
|
43
|
+
|
|
44
|
+
.. image:: https://codecov.io/gh/raphaelvallat/antropy/branch/master/graph/badge.svg
|
|
45
|
+
:target: https://codecov.io/gh/raphaelvallat/antropy
|
|
46
|
+
|
|
47
|
+
.. image:: https://static.pepy.tech/badge/antropy
|
|
48
|
+
:target: https://pepy.tech/projects/antropy
|
|
49
|
+
|
|
50
|
+
.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
|
|
51
|
+
:target: https://github.com/astral-sh/ruff
|
|
52
|
+
:alt: Ruff
|
|
53
|
+
|
|
54
|
+
----------------
|
|
55
|
+
|
|
56
|
+
.. figure:: https://raw.githubusercontent.com/raphaelvallat/antropy/master/docs/pictures/logo.png
|
|
57
|
+
:align: center
|
|
58
|
+
|
|
59
|
+
**AntroPy** is a Python package for computing entropy and fractal dimension measures of
|
|
60
|
+
time-series. It is designed for speed (Numba JIT compilation) and ease of use, and works on
|
|
61
|
+
both 1-D and N-D arrays. Typical use cases include feature extraction from physiological signals
|
|
62
|
+
(e.g. EEG, ECG, EMG), and signal processing research.
|
|
63
|
+
|
|
64
|
+
- `Documentation <https://raphaelvallat.com/antropy/>`_
|
|
65
|
+
- `Changelog <https://raphaelvallat.com/antropy/changelog.html>`_
|
|
66
|
+
- `GitHub <https://github.com/raphaelvallat/antropy>`_
|
|
67
|
+
|
|
68
|
+
----------------
|
|
69
|
+
|
|
70
|
+
Functions
|
|
71
|
+
=========
|
|
72
|
+
|
|
73
|
+
Entropy
|
|
74
|
+
-------
|
|
75
|
+
|
|
76
|
+
.. list-table::
|
|
77
|
+
:widths: 35 65
|
|
78
|
+
:header-rows: 1
|
|
79
|
+
|
|
80
|
+
* - Function
|
|
81
|
+
- Description
|
|
82
|
+
* - ``ant.perm_entropy``
|
|
83
|
+
- Permutation entropy — captures ordinal patterns in the signal.
|
|
84
|
+
* - ``ant.spectral_entropy``
|
|
85
|
+
- Spectral (power-spectrum) entropy via FFT or Welch method.
|
|
86
|
+
* - ``ant.svd_entropy``
|
|
87
|
+
- Singular value decomposition entropy of the time-delay embedding matrix.
|
|
88
|
+
* - ``ant.app_entropy``
|
|
89
|
+
- Approximate entropy (ApEn) — regularity measure sensitive to the length of the signal.
|
|
90
|
+
* - ``ant.sample_entropy``
|
|
91
|
+
- Sample entropy (SampEn) — less biased alternative to ApEn.
|
|
92
|
+
* - ``ant.lziv_complexity``
|
|
93
|
+
- Lempel-Ziv complexity for symbolic / binary sequences.
|
|
94
|
+
* - ``ant.num_zerocross``
|
|
95
|
+
- Number of zero-crossings.
|
|
96
|
+
* - ``ant.hjorth_params``
|
|
97
|
+
- Hjorth mobility and complexity parameters.
|
|
98
|
+
|
|
99
|
+
Fractal dimension
|
|
100
|
+
-----------------
|
|
101
|
+
|
|
102
|
+
.. list-table::
|
|
103
|
+
:widths: 35 65
|
|
104
|
+
:header-rows: 1
|
|
105
|
+
|
|
106
|
+
* - Function
|
|
107
|
+
- Description
|
|
108
|
+
* - ``ant.petrosian_fd``
|
|
109
|
+
- Petrosian fractal dimension.
|
|
110
|
+
* - ``ant.katz_fd``
|
|
111
|
+
- Katz fractal dimension.
|
|
112
|
+
* - ``ant.higuchi_fd``
|
|
113
|
+
- Higuchi fractal dimension — slope of log curve-length vs log interval.
|
|
114
|
+
* - ``ant.detrended_fluctuation``
|
|
115
|
+
- Detrended fluctuation analysis (DFA) — estimates the Hurst / scaling exponent.
|
|
116
|
+
|
|
117
|
+
----------------
|
|
118
|
+
|
|
119
|
+
Installation
|
|
120
|
+
============
|
|
121
|
+
|
|
122
|
+
AntroPy requires Python 3.10+ and depends on NumPy (≥ 1.22.4), SciPy (≥ 1.8.0),
|
|
123
|
+
scikit-learn (≥ 1.2.0), and Numba (≥ 0.57).
|
|
124
|
+
|
|
125
|
+
.. code-block:: shell
|
|
126
|
+
|
|
127
|
+
# pip
|
|
128
|
+
pip install antropy
|
|
129
|
+
|
|
130
|
+
# uv
|
|
131
|
+
uv pip install antropy
|
|
132
|
+
|
|
133
|
+
# conda
|
|
134
|
+
conda install -c conda-forge antropy
|
|
135
|
+
|
|
136
|
+
Development installation
|
|
137
|
+
------------------------
|
|
138
|
+
|
|
139
|
+
.. code-block:: shell
|
|
140
|
+
|
|
141
|
+
git clone https://github.com/raphaelvallat/antropy.git
|
|
142
|
+
cd antropy
|
|
143
|
+
uv pip install --group=test --editable .
|
|
144
|
+
pytest --verbose
|
|
145
|
+
|
|
146
|
+
----------------
|
|
147
|
+
|
|
148
|
+
Quick start
|
|
149
|
+
===========
|
|
150
|
+
|
|
151
|
+
Entropy measures
|
|
152
|
+
----------------
|
|
153
|
+
|
|
154
|
+
.. code-block:: python
|
|
155
|
+
|
|
156
|
+
import numpy as np
|
|
157
|
+
import antropy as ant
|
|
158
|
+
|
|
159
|
+
np.random.seed(1234567)
|
|
160
|
+
x = np.random.normal(size=3000)
|
|
161
|
+
|
|
162
|
+
print(ant.perm_entropy(x, normalize=True))
|
|
163
|
+
print(ant.spectral_entropy(x, sf=100, method='welch', normalize=True))
|
|
164
|
+
print(ant.svd_entropy(x, normalize=True))
|
|
165
|
+
print(ant.app_entropy(x))
|
|
166
|
+
print(ant.sample_entropy(x))
|
|
167
|
+
print(ant.hjorth_params(x)) # mobility in samples⁻¹
|
|
168
|
+
print(ant.hjorth_params(x, sf=100)) # mobility in Hz
|
|
169
|
+
print(ant.num_zerocross(x))
|
|
170
|
+
print(ant.lziv_complexity('01111000011001', normalize=True))
|
|
171
|
+
|
|
172
|
+
.. parsed-literal::
|
|
173
|
+
|
|
174
|
+
0.9995 # perm_entropy (0 = regular, 1 = random)
|
|
175
|
+
0.9941 # spectral_entropy (0 = pure tone, 1 = white noise)
|
|
176
|
+
0.9999 # svd_entropy
|
|
177
|
+
2.0152 # app_entropy
|
|
178
|
+
2.1986 # sample_entropy
|
|
179
|
+
(1.4313, 1.2153) # hjorth (mobility, complexity)
|
|
180
|
+
(143.1339, 1.2153) # hjorth with sf=100 Hz
|
|
181
|
+
1531 # num_zerocross
|
|
182
|
+
1.3598 # lziv_complexity (normalized)
|
|
183
|
+
|
|
184
|
+
Fractal dimension
|
|
185
|
+
-----------------
|
|
186
|
+
|
|
187
|
+
.. code-block:: python
|
|
188
|
+
|
|
189
|
+
print(ant.petrosian_fd(x))
|
|
190
|
+
print(ant.katz_fd(x))
|
|
191
|
+
print(ant.higuchi_fd(x))
|
|
192
|
+
print(ant.detrended_fluctuation(x))
|
|
193
|
+
|
|
194
|
+
.. parsed-literal::
|
|
195
|
+
|
|
196
|
+
1.0311 # petrosian_fd
|
|
197
|
+
5.9543 # katz_fd
|
|
198
|
+
2.0037 # higuchi_fd (≈ 2 for white noise)
|
|
199
|
+
0.4790 # DFA alpha (≈ 0.5 for white noise)
|
|
200
|
+
|
|
201
|
+
N-D arrays
|
|
202
|
+
----------
|
|
203
|
+
|
|
204
|
+
Some functions accept N-D arrays and an ``axis`` argument, making it easy to process
|
|
205
|
+
multi-channel data in a single call:
|
|
206
|
+
|
|
207
|
+
.. code-block:: python
|
|
208
|
+
|
|
209
|
+
import numpy as np
|
|
210
|
+
import antropy as ant
|
|
211
|
+
|
|
212
|
+
# 4 channels × 3000 samples
|
|
213
|
+
X = np.random.normal(size=(4, 3000))
|
|
214
|
+
|
|
215
|
+
pe = ant.perm_entropy(X, normalize=True, axis=-1) # shape (4,)
|
|
216
|
+
mob, com = ant.hjorth_params(X, sf=256, axis=-1) # shape (4,) each
|
|
217
|
+
nzc = ant.num_zerocross(X, normalize=True, axis=-1) # shape (4,)
|
|
218
|
+
se = ant.spectral_entropy(X, sf=256, normalize=True) # shape (4,)
|
|
219
|
+
|
|
220
|
+
----------------
|
|
221
|
+
|
|
222
|
+
Performance
|
|
223
|
+
===========
|
|
224
|
+
|
|
225
|
+
Benchmarks on a MacBook Pro M1 Max (2021):
|
|
226
|
+
|
|
227
|
+
.. list-table::
|
|
228
|
+
:widths: 32 20 20 28
|
|
229
|
+
:header-rows: 1
|
|
230
|
+
|
|
231
|
+
* - Function
|
|
232
|
+
- 1 000 samples
|
|
233
|
+
- 10 000 samples
|
|
234
|
+
- Complexity
|
|
235
|
+
* - ``ant.perm_entropy``
|
|
236
|
+
- 24 µs
|
|
237
|
+
- 87 µs
|
|
238
|
+
- O(n) ¹
|
|
239
|
+
* - ``ant.spectral_entropy``
|
|
240
|
+
- 141 µs
|
|
241
|
+
- 863 µs
|
|
242
|
+
- O(n log n) ⁴
|
|
243
|
+
* - ``ant.svd_entropy``
|
|
244
|
+
- 35 µs
|
|
245
|
+
- 140 µs
|
|
246
|
+
- O(n·m²) ²
|
|
247
|
+
* - ``ant.app_entropy``
|
|
248
|
+
- 1.5 ms
|
|
249
|
+
- 45.9 ms
|
|
250
|
+
- O(n²) worst ⁵
|
|
251
|
+
* - ``ant.sample_entropy``
|
|
252
|
+
- 917 µs
|
|
253
|
+
- 46.0 ms
|
|
254
|
+
- O(n²) worst ⁵
|
|
255
|
+
* - ``ant.lziv_complexity``
|
|
256
|
+
- 241 µs
|
|
257
|
+
- 25.2 ms
|
|
258
|
+
- O(n²/log n)
|
|
259
|
+
* - ``ant.num_zerocross``
|
|
260
|
+
- 2.5 µs
|
|
261
|
+
- 6 µs
|
|
262
|
+
- O(n)
|
|
263
|
+
* - ``ant.hjorth_params``
|
|
264
|
+
- 19 µs
|
|
265
|
+
- 44 µs
|
|
266
|
+
- O(n)
|
|
267
|
+
* - ``ant.petrosian_fd``
|
|
268
|
+
- 6 µs
|
|
269
|
+
- 14 µs
|
|
270
|
+
- O(n)
|
|
271
|
+
* - ``ant.katz_fd``
|
|
272
|
+
- 9 µs
|
|
273
|
+
- 22 µs
|
|
274
|
+
- O(n)
|
|
275
|
+
* - ``ant.higuchi_fd``
|
|
276
|
+
- 7 µs
|
|
277
|
+
- 92 µs
|
|
278
|
+
- O(n·kmax) ³
|
|
279
|
+
* - ``ant.detrended_fluctuation``
|
|
280
|
+
- 99 µs
|
|
281
|
+
- 1.4 ms
|
|
282
|
+
- O(n log n)
|
|
283
|
+
|
|
284
|
+
¹ ``perm_entropy``: O(n) for ``order`` ∈ {3, 4} (default), O(n·m·log m) for ``order`` > 4.
|
|
285
|
+
² ``svd_entropy``: m = ``order`` (default 3).
|
|
286
|
+
³ ``higuchi_fd``: ``kmax`` = max interval (default 10).
|
|
287
|
+
⁴ ``spectral_entropy``: O(n log n) for FFT method, O(n) for Welch with fixed ``nperseg`` (default).
|
|
288
|
+
⁵ ``app_entropy`` / ``sample_entropy``: O(n²) worst case, empirically ~O(n^1.5) via KDTree average case.
|
|
289
|
+
|
|
290
|
+
Numba functions (``sample_entropy``, ``higuchi_fd``, ``detrended_fluctuation``) incur a one-time compilation cost on the first call.
|
|
291
|
+
|
|
292
|
+
----------------
|
|
293
|
+
|
|
294
|
+
Contributing
|
|
295
|
+
============
|
|
296
|
+
|
|
297
|
+
AntroPy was created and is maintained by `Raphael Vallat <https://raphaelvallat.com>`_.
|
|
298
|
+
Contributions are welcome — feel free to open an issue or submit a pull request on
|
|
299
|
+
`GitHub <https://github.com/raphaelvallat/antropy>`_.
|
|
300
|
+
|
|
301
|
+
**Note:** this program is provided with **NO WARRANTY OF ANY KIND**. Always validate
|
|
302
|
+
results against known references.
|
|
303
|
+
|
|
304
|
+
----------------
|
|
305
|
+
|
|
306
|
+
Acknowledgements
|
|
307
|
+
================
|
|
308
|
+
|
|
309
|
+
Several functions in AntroPy were adapted from:
|
|
310
|
+
|
|
311
|
+
- `MNE-features <https://github.com/mne-tools/mne-features>`_ — Jean-Baptiste Schiratti & Alexandre Gramfort
|
|
312
|
+
- `pyEntropy <https://github.com/nikdon/pyEntropy>`_ — Nikolay Donets
|
|
313
|
+
- `pyrem <https://github.com/gilestrolab/pyrem>`_ — Quentin Geissmann
|
|
314
|
+
- `nolds <https://github.com/CSchoel/nolds>`_ — Christopher Scholzel
|
antropy-0.2.2/README.rst
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
.. -*- mode: rst -*-
|
|
2
|
+
|
|
3
|
+
|
|
|
4
|
+
|
|
5
|
+
.. image:: https://badge.fury.io/py/antropy.svg
|
|
6
|
+
:target: https://badge.fury.io/py/antropy
|
|
7
|
+
|
|
8
|
+
.. image:: https://img.shields.io/conda/vn/conda-forge/antropy.svg
|
|
9
|
+
:target: https://anaconda.org/conda-forge/antropy
|
|
10
|
+
|
|
11
|
+
.. image:: https://img.shields.io/github/license/raphaelvallat/antropy.svg
|
|
12
|
+
:target: https://github.com/raphaelvallat/antropy/blob/master/LICENSE
|
|
13
|
+
|
|
14
|
+
.. image:: https://github.com/raphaelvallat/antropy/actions/workflows/python_tests.yml/badge.svg
|
|
15
|
+
:target: https://github.com/raphaelvallat/antropy/actions/workflows/python_tests.yml
|
|
16
|
+
|
|
17
|
+
.. image:: https://codecov.io/gh/raphaelvallat/antropy/branch/master/graph/badge.svg
|
|
18
|
+
:target: https://codecov.io/gh/raphaelvallat/antropy
|
|
19
|
+
|
|
20
|
+
.. image:: https://static.pepy.tech/badge/antropy
|
|
21
|
+
:target: https://pepy.tech/projects/antropy
|
|
22
|
+
|
|
23
|
+
.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json
|
|
24
|
+
:target: https://github.com/astral-sh/ruff
|
|
25
|
+
:alt: Ruff
|
|
26
|
+
|
|
27
|
+
----------------
|
|
28
|
+
|
|
29
|
+
.. figure:: https://raw.githubusercontent.com/raphaelvallat/antropy/master/docs/pictures/logo.png
|
|
30
|
+
:align: center
|
|
31
|
+
|
|
32
|
+
**AntroPy** is a Python package for computing entropy and fractal dimension measures of
|
|
33
|
+
time-series. It is designed for speed (Numba JIT compilation) and ease of use, and works on
|
|
34
|
+
both 1-D and N-D arrays. Typical use cases include feature extraction from physiological signals
|
|
35
|
+
(e.g. EEG, ECG, EMG), and signal processing research.
|
|
36
|
+
|
|
37
|
+
- `Documentation <https://raphaelvallat.com/antropy/>`_
|
|
38
|
+
- `Changelog <https://raphaelvallat.com/antropy/changelog.html>`_
|
|
39
|
+
- `GitHub <https://github.com/raphaelvallat/antropy>`_
|
|
40
|
+
|
|
41
|
+
----------------
|
|
42
|
+
|
|
43
|
+
Functions
|
|
44
|
+
=========
|
|
45
|
+
|
|
46
|
+
Entropy
|
|
47
|
+
-------
|
|
48
|
+
|
|
49
|
+
.. list-table::
|
|
50
|
+
:widths: 35 65
|
|
51
|
+
:header-rows: 1
|
|
52
|
+
|
|
53
|
+
* - Function
|
|
54
|
+
- Description
|
|
55
|
+
* - ``ant.perm_entropy``
|
|
56
|
+
- Permutation entropy — captures ordinal patterns in the signal.
|
|
57
|
+
* - ``ant.spectral_entropy``
|
|
58
|
+
- Spectral (power-spectrum) entropy via FFT or Welch method.
|
|
59
|
+
* - ``ant.svd_entropy``
|
|
60
|
+
- Singular value decomposition entropy of the time-delay embedding matrix.
|
|
61
|
+
* - ``ant.app_entropy``
|
|
62
|
+
- Approximate entropy (ApEn) — regularity measure sensitive to the length of the signal.
|
|
63
|
+
* - ``ant.sample_entropy``
|
|
64
|
+
- Sample entropy (SampEn) — less biased alternative to ApEn.
|
|
65
|
+
* - ``ant.lziv_complexity``
|
|
66
|
+
- Lempel-Ziv complexity for symbolic / binary sequences.
|
|
67
|
+
* - ``ant.num_zerocross``
|
|
68
|
+
- Number of zero-crossings.
|
|
69
|
+
* - ``ant.hjorth_params``
|
|
70
|
+
- Hjorth mobility and complexity parameters.
|
|
71
|
+
|
|
72
|
+
Fractal dimension
|
|
73
|
+
-----------------
|
|
74
|
+
|
|
75
|
+
.. list-table::
|
|
76
|
+
:widths: 35 65
|
|
77
|
+
:header-rows: 1
|
|
78
|
+
|
|
79
|
+
* - Function
|
|
80
|
+
- Description
|
|
81
|
+
* - ``ant.petrosian_fd``
|
|
82
|
+
- Petrosian fractal dimension.
|
|
83
|
+
* - ``ant.katz_fd``
|
|
84
|
+
- Katz fractal dimension.
|
|
85
|
+
* - ``ant.higuchi_fd``
|
|
86
|
+
- Higuchi fractal dimension — slope of log curve-length vs log interval.
|
|
87
|
+
* - ``ant.detrended_fluctuation``
|
|
88
|
+
- Detrended fluctuation analysis (DFA) — estimates the Hurst / scaling exponent.
|
|
89
|
+
|
|
90
|
+
----------------
|
|
91
|
+
|
|
92
|
+
Installation
|
|
93
|
+
============
|
|
94
|
+
|
|
95
|
+
AntroPy requires Python 3.10+ and depends on NumPy (≥ 1.22.4), SciPy (≥ 1.8.0),
|
|
96
|
+
scikit-learn (≥ 1.2.0), and Numba (≥ 0.57).
|
|
97
|
+
|
|
98
|
+
.. code-block:: shell
|
|
99
|
+
|
|
100
|
+
# pip
|
|
101
|
+
pip install antropy
|
|
102
|
+
|
|
103
|
+
# uv
|
|
104
|
+
uv pip install antropy
|
|
105
|
+
|
|
106
|
+
# conda
|
|
107
|
+
conda install -c conda-forge antropy
|
|
108
|
+
|
|
109
|
+
Development installation
|
|
110
|
+
------------------------
|
|
111
|
+
|
|
112
|
+
.. code-block:: shell
|
|
113
|
+
|
|
114
|
+
git clone https://github.com/raphaelvallat/antropy.git
|
|
115
|
+
cd antropy
|
|
116
|
+
uv pip install --group=test --editable .
|
|
117
|
+
pytest --verbose
|
|
118
|
+
|
|
119
|
+
----------------
|
|
120
|
+
|
|
121
|
+
Quick start
|
|
122
|
+
===========
|
|
123
|
+
|
|
124
|
+
Entropy measures
|
|
125
|
+
----------------
|
|
126
|
+
|
|
127
|
+
.. code-block:: python
|
|
128
|
+
|
|
129
|
+
import numpy as np
|
|
130
|
+
import antropy as ant
|
|
131
|
+
|
|
132
|
+
np.random.seed(1234567)
|
|
133
|
+
x = np.random.normal(size=3000)
|
|
134
|
+
|
|
135
|
+
print(ant.perm_entropy(x, normalize=True))
|
|
136
|
+
print(ant.spectral_entropy(x, sf=100, method='welch', normalize=True))
|
|
137
|
+
print(ant.svd_entropy(x, normalize=True))
|
|
138
|
+
print(ant.app_entropy(x))
|
|
139
|
+
print(ant.sample_entropy(x))
|
|
140
|
+
print(ant.hjorth_params(x)) # mobility in samples⁻¹
|
|
141
|
+
print(ant.hjorth_params(x, sf=100)) # mobility in Hz
|
|
142
|
+
print(ant.num_zerocross(x))
|
|
143
|
+
print(ant.lziv_complexity('01111000011001', normalize=True))
|
|
144
|
+
|
|
145
|
+
.. parsed-literal::
|
|
146
|
+
|
|
147
|
+
0.9995 # perm_entropy (0 = regular, 1 = random)
|
|
148
|
+
0.9941 # spectral_entropy (0 = pure tone, 1 = white noise)
|
|
149
|
+
0.9999 # svd_entropy
|
|
150
|
+
2.0152 # app_entropy
|
|
151
|
+
2.1986 # sample_entropy
|
|
152
|
+
(1.4313, 1.2153) # hjorth (mobility, complexity)
|
|
153
|
+
(143.1339, 1.2153) # hjorth with sf=100 Hz
|
|
154
|
+
1531 # num_zerocross
|
|
155
|
+
1.3598 # lziv_complexity (normalized)
|
|
156
|
+
|
|
157
|
+
Fractal dimension
|
|
158
|
+
-----------------
|
|
159
|
+
|
|
160
|
+
.. code-block:: python
|
|
161
|
+
|
|
162
|
+
print(ant.petrosian_fd(x))
|
|
163
|
+
print(ant.katz_fd(x))
|
|
164
|
+
print(ant.higuchi_fd(x))
|
|
165
|
+
print(ant.detrended_fluctuation(x))
|
|
166
|
+
|
|
167
|
+
.. parsed-literal::
|
|
168
|
+
|
|
169
|
+
1.0311 # petrosian_fd
|
|
170
|
+
5.9543 # katz_fd
|
|
171
|
+
2.0037 # higuchi_fd (≈ 2 for white noise)
|
|
172
|
+
0.4790 # DFA alpha (≈ 0.5 for white noise)
|
|
173
|
+
|
|
174
|
+
N-D arrays
|
|
175
|
+
----------
|
|
176
|
+
|
|
177
|
+
Some functions accept N-D arrays and an ``axis`` argument, making it easy to process
|
|
178
|
+
multi-channel data in a single call:
|
|
179
|
+
|
|
180
|
+
.. code-block:: python
|
|
181
|
+
|
|
182
|
+
import numpy as np
|
|
183
|
+
import antropy as ant
|
|
184
|
+
|
|
185
|
+
# 4 channels × 3000 samples
|
|
186
|
+
X = np.random.normal(size=(4, 3000))
|
|
187
|
+
|
|
188
|
+
pe = ant.perm_entropy(X, normalize=True, axis=-1) # shape (4,)
|
|
189
|
+
mob, com = ant.hjorth_params(X, sf=256, axis=-1) # shape (4,) each
|
|
190
|
+
nzc = ant.num_zerocross(X, normalize=True, axis=-1) # shape (4,)
|
|
191
|
+
se = ant.spectral_entropy(X, sf=256, normalize=True) # shape (4,)
|
|
192
|
+
|
|
193
|
+
----------------
|
|
194
|
+
|
|
195
|
+
Performance
|
|
196
|
+
===========
|
|
197
|
+
|
|
198
|
+
Benchmarks on a MacBook Pro M1 Max (2021):
|
|
199
|
+
|
|
200
|
+
.. list-table::
|
|
201
|
+
:widths: 32 20 20 28
|
|
202
|
+
:header-rows: 1
|
|
203
|
+
|
|
204
|
+
* - Function
|
|
205
|
+
- 1 000 samples
|
|
206
|
+
- 10 000 samples
|
|
207
|
+
- Complexity
|
|
208
|
+
* - ``ant.perm_entropy``
|
|
209
|
+
- 24 µs
|
|
210
|
+
- 87 µs
|
|
211
|
+
- O(n) ¹
|
|
212
|
+
* - ``ant.spectral_entropy``
|
|
213
|
+
- 141 µs
|
|
214
|
+
- 863 µs
|
|
215
|
+
- O(n log n) ⁴
|
|
216
|
+
* - ``ant.svd_entropy``
|
|
217
|
+
- 35 µs
|
|
218
|
+
- 140 µs
|
|
219
|
+
- O(n·m²) ²
|
|
220
|
+
* - ``ant.app_entropy``
|
|
221
|
+
- 1.5 ms
|
|
222
|
+
- 45.9 ms
|
|
223
|
+
- O(n²) worst ⁵
|
|
224
|
+
* - ``ant.sample_entropy``
|
|
225
|
+
- 917 µs
|
|
226
|
+
- 46.0 ms
|
|
227
|
+
- O(n²) worst ⁵
|
|
228
|
+
* - ``ant.lziv_complexity``
|
|
229
|
+
- 241 µs
|
|
230
|
+
- 25.2 ms
|
|
231
|
+
- O(n²/log n)
|
|
232
|
+
* - ``ant.num_zerocross``
|
|
233
|
+
- 2.5 µs
|
|
234
|
+
- 6 µs
|
|
235
|
+
- O(n)
|
|
236
|
+
* - ``ant.hjorth_params``
|
|
237
|
+
- 19 µs
|
|
238
|
+
- 44 µs
|
|
239
|
+
- O(n)
|
|
240
|
+
* - ``ant.petrosian_fd``
|
|
241
|
+
- 6 µs
|
|
242
|
+
- 14 µs
|
|
243
|
+
- O(n)
|
|
244
|
+
* - ``ant.katz_fd``
|
|
245
|
+
- 9 µs
|
|
246
|
+
- 22 µs
|
|
247
|
+
- O(n)
|
|
248
|
+
* - ``ant.higuchi_fd``
|
|
249
|
+
- 7 µs
|
|
250
|
+
- 92 µs
|
|
251
|
+
- O(n·kmax) ³
|
|
252
|
+
* - ``ant.detrended_fluctuation``
|
|
253
|
+
- 99 µs
|
|
254
|
+
- 1.4 ms
|
|
255
|
+
- O(n log n)
|
|
256
|
+
|
|
257
|
+
¹ ``perm_entropy``: O(n) for ``order`` ∈ {3, 4} (default), O(n·m·log m) for ``order`` > 4.
|
|
258
|
+
² ``svd_entropy``: m = ``order`` (default 3).
|
|
259
|
+
³ ``higuchi_fd``: ``kmax`` = max interval (default 10).
|
|
260
|
+
⁴ ``spectral_entropy``: O(n log n) for FFT method, O(n) for Welch with fixed ``nperseg`` (default).
|
|
261
|
+
⁵ ``app_entropy`` / ``sample_entropy``: O(n²) worst case, empirically ~O(n^1.5) via KDTree average case.
|
|
262
|
+
|
|
263
|
+
Numba functions (``sample_entropy``, ``higuchi_fd``, ``detrended_fluctuation``) incur a one-time compilation cost on the first call.
|
|
264
|
+
|
|
265
|
+
----------------
|
|
266
|
+
|
|
267
|
+
Contributing
|
|
268
|
+
============
|
|
269
|
+
|
|
270
|
+
AntroPy was created and is maintained by `Raphael Vallat <https://raphaelvallat.com>`_.
|
|
271
|
+
Contributions are welcome — feel free to open an issue or submit a pull request on
|
|
272
|
+
`GitHub <https://github.com/raphaelvallat/antropy>`_.
|
|
273
|
+
|
|
274
|
+
**Note:** this program is provided with **NO WARRANTY OF ANY KIND**. Always validate
|
|
275
|
+
results against known references.
|
|
276
|
+
|
|
277
|
+
----------------
|
|
278
|
+
|
|
279
|
+
Acknowledgements
|
|
280
|
+
================
|
|
281
|
+
|
|
282
|
+
Several functions in AntroPy were adapted from:
|
|
283
|
+
|
|
284
|
+
- `MNE-features <https://github.com/mne-tools/mne-features>`_ — Jean-Baptiste Schiratti & Alexandre Gramfort
|
|
285
|
+
- `pyEntropy <https://github.com/nikdon/pyEntropy>`_ — Nikolay Donets
|
|
286
|
+
- `pyrem <https://github.com/gilestrolab/pyrem>`_ — Quentin Geissmann
|
|
287
|
+
- `nolds <https://github.com/CSchoel/nolds>`_ — Christopher Scholzel
|
|
@@ -36,7 +36,7 @@ dependencies = [
|
|
|
36
36
|
[dependency-groups]
|
|
37
37
|
dev = ["ruff>=0.9"]
|
|
38
38
|
test = [
|
|
39
|
-
"pytest>=
|
|
39
|
+
"pytest>=7.0",
|
|
40
40
|
"pytest-cov",
|
|
41
41
|
# Ensure coverage is new enough for `source_pkgs`.
|
|
42
42
|
"coverage[toml]>=5.3",
|
|
@@ -54,7 +54,6 @@ Homepage = "https://github.com/raphaelvallat/antropy/"
|
|
|
54
54
|
Downloads = "https://github.com/raphaelvallat/antropy/"
|
|
55
55
|
|
|
56
56
|
[tool.setuptools]
|
|
57
|
-
py-modules = ["antropy"]
|
|
58
57
|
include-package-data = false
|
|
59
58
|
|
|
60
59
|
[tool.setuptools.packages.find]
|
|
@@ -65,8 +64,10 @@ where = ["src"]
|
|
|
65
64
|
version = {attr = "antropy.__version__"}
|
|
66
65
|
|
|
67
66
|
[tool.pytest.ini_options]
|
|
68
|
-
minversion = "
|
|
67
|
+
minversion = "7.0"
|
|
69
68
|
addopts = "--showlocals --durations=10" # --cov
|
|
69
|
+
testpaths = ["tests"]
|
|
70
|
+
pythonpath = ["tests"]
|
|
70
71
|
doctest_optionflags= ["NORMALIZE_WHITESPACE", "IGNORE_EXCEPTION_DETAIL"]
|
|
71
72
|
filterwarnings = [
|
|
72
73
|
"ignore::UserWarning",
|