This sub-module provides routines for computing features on univariate time series. Many functions are improved version of PyEEG [PYEEG] functions. Be careful, some functions will give different results compared to PyEEG as the maths have been changed to match original definitions. Have a look at the documentation notes/ source code to know more.
Here a list of the functions that were reimplemented:
[PET95] | (1, 2) 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, 1995, pp. 212-217. |
[PYEEG] | (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) F. S. Bao, X. Liu, and C. Zhang, PyEEG: An Open Source Python Module for EEG/MEG Feature Extraction, Computational Intelligence and Neuroscience, vol. 2011, p. e406391, Mar. 2011. |
[HJO70] | (1, 2) B. Hjorth, EEG analysis based on time domain properties, Electroencephalography and Clinical Neurophysiology, vol. 29, no. 3, pp. 306-310, Sep. 1970. |
[COS05] |
|
[RIC00] | (1, 2, 3) J. S. Richman and J. R. Moorman, “Physiological time-series analysis using approximate entropy and sample entropy,” American Journal of Physiology - Heart and Circulatory Physiology, vol. 278, no. 6, pp. H2039-H2049, Jun. 2000. |
[HIG88] | (1, 2, 3)
|
Compute the approximate entropy of a signal with embedding dimension “de” and delay “tau” [PYEEG]. Vectorised version of the PyEEG function. Faster than PyEEG, but still critically slow.
Parameters: | |
---|---|
Returns: | the approximate entropy, a scalar |
Return type: | float |
WIP on this function. It is basically copied and pasted from [PYEEG], without verification of the maths or unittests.
Compute the Fisher information of a signal with embedding dimension “de” and delay “tau” [PYEEG]. Vectorised (i.e. faster) version of the eponymous PyEEG function.
Parameters: | |
---|---|
Returns: | the Fisher information, a scalar |
Return type: | float |
Compute Higuchi Fractal Dimension of a time series. Vectorised version of the eponymous [PYEEG] function.
Note
Difference with PyEEG:
Results is different from [PYEEG] which appears to have implemented an erroneous formulae. [HIG88] defines the normalisation factor as:
[PYEEG] implementation uses:
The latter does not give the expected fractal dimension of approximately 1.50 for brownian motion (see example bellow).
Parameters: | |
---|---|
Returns: | Higuchi’s fractal dimension; a scalar |
Return type: | float |
Example from [HIG88]. This should produce a result close to 1.50:
>>> import numpy as np
>>> import pyrem as pr
>>> i = np.arange(2 ** 15) +1001
>>> z = np.random.normal(size=int(2 ** 15) + 1001)
>>> y = np.array([np.sum(z[1:j]) for j in i])
>>> pr.univariate.hfd(y,2**8)
Compute Hjorth parameters [HJO70].
Where:
\(\sigma_{x}^2\) is the mean power of a signal \(x\). That is, its variance, if it’s mean is zero.
\(a\), \(d\) and \(dd\) represent the original signal, its first and second derivatives, respectively.
Note
Difference with PyEEG:
Results is different from [PYEEG] which appear to uses a non normalised (by the length of the signal) definition of the activity:
As opposed to
Parameters: | a (ndarray or Signal) – a one dimensional floating-point array representing a time series. |
---|---|
Returns: | activity, complexity and morbidity |
Return type: | tuple(float, float, float) |
Example:
>>> import pyrem as pr
>>> import numpy as np
>>> # generate white noise:
>>> noise = np.random.normal(size=int(1e4))
>>> activity, complexity, morbidity = pr.univariate.hjorth(noise)
Experimental/untested implementation taken from: http://drtomstarke.com/index.php/calculation-of-the-hurst-exponent-to-test-for-trend-and-mean-reversion/
Use at your own risks.
Compute Petrosian Fractal Dimension of a time series [PET95].
It is defined by:
Note
Difference with PyEEG:
Results is different from [PYEEG] which implemented an apparently erroneous formulae:
Where:
\(N\) is the length of the time series, and
\(N_{\delta}\) is the number of sign changes.
Parameters: | a (ndarray or Signal) – a one dimensional floating-point array representing a time series. |
---|---|
Returns: | the Petrosian Fractal Dimension; a scalar. |
Return type: | float |
Example:
>>> import pyrem as pr
>>> import numpy as np
>>> # generate white noise:
>>> noise = np.random.normal(size=int(1e4))
>>> pr.univariate.pdf(noise)
Compute the sample entropy [RIC00] of a signal with embedding dimension de and delay tau [PYEEG]. Vectorised version of the eponymous PyEEG function. In addition, this function can also be used to vary tau and therefore compute Multi-Scale Entropy(MSE) [COS05] by coarse grainning the time series (see example bellow). By default, r is expressed as relatively to the standard deviation of the signal.
Parameters: |
|
---|---|
Returns: | the approximate entropy, a scalar |
Return type: | float |
Example:
>>> import pyrem as pr
>>> import numpy as np
>>> # generate white noise:
>>> noise = np.random.normal(size=int(1e4))
>>> pr.univariate.samp_entropy(noise, m=2, r=1.5)
>>> # now we can do that for multiple scales (MSE):
>>> [pr.univariate.samp_entropy(noise, m=2, r=1.5, tau=tau) for tau in range(1, 5)]
Compute spectral entropy of a signal with respect to frequency bands. The power spectrum is computed through fft. Then, it is normalised and assimilated to a probability density function. The entropy of the signal \(x\) can be expressed by:
Where:
\(PSD\) is the normalised power spectrum (Power Spectrum Density), and
\(f_s\) is the sampling frequency
Parameters: | |
---|---|
Returns: | the spectral entropy; a scalar |
Compute the Singular Value Decomposition entropy of a signal with embedding dimension “de” and delay “tau” [PYEEG].
Note
Difference with PyEEG:
The result differs from PyEEG implementation because \(log_2\) is used (as opposed to natural logarithm in PyEEG code), according to the definition in their paper [PYEEG] (eq. 9):
Parameters: | |
---|---|
Returns: | the SVD entropy, a scalar |
Return type: | float |