entropy.petrosian_fd

entropy.petrosian_fd(x, axis=- 1)[source]

Petrosian fractal dimension.

Parameters
xlist or np.array

1D or N-D data.

axisint

The axis along which the FD is calculated. Default is -1 (last).

Returns
pfdfloat

Petrosian fractal dimension.

Notes

The Petrosian fractal dimension of a time-series \(x\) is defined by:

\[P = \frac{\log_{10}(N)}{\log_{10}(N) + \log_{10}(\frac{N}{N+0.4N_{\delta}})}\]

where \(N\) is the length of the time series, and \(N_{\delta}\) is the number of sign changes in the signal derivative.

Original code from the pyrem package by Quentin Geissmann.

References

  • A. Petrosian, Kolmogorov complexity of finite sequences and recognition of different preictal EEG patterns, in , Proceedings of the Eighth IEEE Symposium on Computer-Based Medical Systems, 1995, pp. 212-217.

  • Goh, Cindy, et al. “Comparison of fractal dimension algorithms for the computation of EEG biomarkers for dementia.” 2nd International Conference on Computational Intelligence in Medicine and Healthcare (CIMED2005). 2005.

Examples

>>> import numpy as np
>>> import entropy as ent
>>> 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"{ent.petrosian_fd(x):.4f}")
1.0264

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"{ent.petrosian_fd(x):.4f}")
1.0235

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"{ent.petrosian_fd(x):.4f}")
1.0283

Random

>>> rng = np.random.default_rng(seed=42)
>>> print(f"{ent.petrosian_fd(rng.random(1000)):.4f}")
1.0350

Pure sine wave

>>> x = np.sin(2 * np.pi * 1 * np.arange(3000) / 100)
>>> print(f"{ent.petrosian_fd(x):.4f}")
1.0010

Linearly-increasing time-series (should be 1)

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