antropy.higuchi_fd#

antropy.higuchi_fd(x, kmax=10)[source]#

Higuchi Fractal Dimension.

Parameters:
xlist or np.array

One dimensional time series.

kmaxint

Maximum delay/offset (in number of samples).

Returns:
hfdfloat

Higuchi fractal dimension.

Notes

For each interval \(k\) from 1 to kmax, \(k\) sub-series are constructed from the signal \(x\) of length \(N\). Letting \(N_m = \lfloor (N-m)/k \rfloor\), the normalised length for each sub-series starting at \(m\) is:

\[L_m(k) = \frac{N-1}{k^2 \cdot N_m} \sum_{j=1}^{N_m} |x_{m+jk} - x_{m+(j-1)k}|\]

and the average length across all \(k\) sub-series is:

\[L(k) = \frac{1}{k} \sum_{m=1}^{k} L_m(k)\]

The fractal dimension is then estimated as the slope of the linear regression of \(\log L(k)\) against \(\log(1/k)\):

\[\text{FD} = \frac{d \log L(k)}{d \log(1/k)}\]

Original code from the mne-features package by Jean-Baptiste Schiratti and Alexandre Gramfort.

This function uses Numba to speed up the computation.

References

Higuchi, Tomoyuki. “Approach to an irregular time series on the basis of the fractal theory.” Physica D: Nonlinear Phenomena 31.2 (1988): 277-283.

Esteller, R. et al. (2001). A comparison of waveform fractal dimension algorithms. IEEE Transactions on Circuits and Systems I: Fundamental Theory and Applications, 48(2), 177-183.

Paivinen, N. et al. (2005). Epileptic seizure detection: A nonlinear viewpoint. Computer methods and programs in biomedicine, 79(2), 151-159.

Examples

>>> import numpy as np
>>> import antropy as ant
>>> import stochastic.processes.noise as sn
>>> rng = np.random.default_rng(seed=42)
>>> x = sn.FractionalGaussianNoise(hurst=0.5, rng=rng).sample(10000)
>>> print(f"{ant.higuchi_fd(x):.4f}")
1.9980

Fractional Gaussian noise with H = 0.9

>>> rng = np.random.default_rng(seed=42)
>>> x = sn.FractionalGaussianNoise(hurst=0.9, rng=rng).sample(10000)
>>> print(f"{ant.higuchi_fd(x):.4f}")
1.8512

Fractional Gaussian noise with H = 0.1

>>> rng = np.random.default_rng(seed=42)
>>> x = sn.FractionalGaussianNoise(hurst=0.1, rng=rng).sample(10000)
>>> print(f"{ant.higuchi_fd(x):.4f}")
2.0575

Random

>>> rng = np.random.default_rng(seed=42)
>>> print(f"{ant.higuchi_fd(rng.random(1000)):.4f}")
1.9975

Pure sine wave

>>> x = np.sin(2 * np.pi * 1 * np.arange(3000) / 100)
>>> print(f"{ant.higuchi_fd(x):.4f}")
1.0074

Linearly-increasing time-series

>>> x = np.arange(1000)
>>> print(f"{ant.higuchi_fd(x):.4f}")
1.0000