Antropy

raw JSON →
0.2.2 verified Mon Apr 27 auth: no python

AntroPy is a Python library for estimating entropy and complexity of time-series data, including sample entropy, approximate entropy, permutation entropy, spectral entropy, and fractal dimensions (Petrosian, Katz, Higuchi). Current version is 0.2.2, with regular releases on a roughly annual cadence. Requires Python >= 3.10.

pip install antropy
error ValueError: md must be an integer >=2
cause Passing a fractional or too small embedding dimension to sample_entropy or app_entropy.
fix
Ensure the 'dim' parameter (often 'm') is an integer >= 2, e.g., m=2.
error ValueError: tolerance (r) must be positive
cause Passing a non-positive tolerance to sample_entropy or app_entropy.
fix
Set r to a positive float, typically 0.2 * standard deviation of the signal.
error RuntimeError: Numba jit compilation failed. Falling back to pure Python.
cause Numba version incompatibility or missing LLVM. Antropy uses numba for acceleration, but falls back gracefully.
fix
Install compatible numba version: pip install 'numba>=0.57' or ignore if performance is acceptable.
error AttributeError: module 'antropy' has no attribute 'petrosian_fd'
cause Older version of antropy (<0.1.5) did not include petrosian_fd, or function was renamed.
fix
Upgrade to latest version: pip install --upgrade antropy
breaking Python 3.9 is no longer supported as of v0.2.0. Minimum required Python version is 3.10.
fix Upgrade Python to 3.10 or newer.
breaking Permutation entropy for order 3 and 4 now returns a 1-D array when input is 2-D, one value per row. Previous behavior returned a scalar or raised an error.
fix For 2D input, access individual row entropies via indexing. For 1D input, behavior unchanged.
gotcha Sample entropy uses a default tolerance (r) of 0.2 * std(x). For very short or noisy signals, this may be inappropriate and lead to undefined entropy (nan).
fix Explicitly set r parameter or check signal length is sufficient (typically > 10*(m+1) for embedding dimension m).
deprecated The optional dependency 'stochastic' was removed in v0.1.9. Any code using antropy with that package is unaffected, but imports of 'stochastic' directly will fail if not installed separately.
fix Install 'stochastic' separately if needed: pip install stochastic

Compute sample entropy, permutation entropy, and Higuchi fractal dimension on a random 1D array.

import numpy as np
from antropy import sample_entropy, perm_entropy, higuchi_fd

# Generate a random time series
np.random.seed(42)
x = np.random.rand(100)

# Sample entropy
se = sample_entropy(x)
print(f"Sample entropy: {se:.4f}")

# Permutation entropy with order 3
pe = perm_entropy(x, order=3)
print(f"Permutation entropy: {pe:.4f}")

# Higuchi fractal dimension
hfd = higuchi_fd(x)
print(f"Higuchi fractal dimension: {hfd:.4f}")