antropy.katz_fd

antropy.katz_fd(x, axis=- 1)[source]

Katz 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
kfdfloat

Katz fractal dimension.

Notes

Katz’s method calculates the fractal dimension of a sample as follows: the sum and average of the Euclidean distances between the successive points of the sample (\(L\) and \(a\) , resp.) are calculated as well as the maximum distance between the first point and any other point of the sample (\(d\)). The fractal dimension of the sample (\(D\)) then becomes:

\[D = \frac{\log_{10}(L/a)}{\log_{10}(d/a)} = \frac{\log_{10}(n)}{\log_{10}(d/L)+\log_{10}(n)}\]

where \(n\) is \(L\) divided by \(a\).

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

References

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.katz_fd(x):.4f}")
6.4713

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.katz_fd(x):.4f}")
4.5720

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.katz_fd(x):.4f}")
7.6540

Random

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

Pure sine wave

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

Linearly-increasing time-series (should be 1)

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