pysdkit.entropy#

Created on 2025/02/12 11:36:44 @author: Whenxuan Wang @email: wwhenxuan@gmail.com

pysdkit.entropy._permutation_entropy

Created on 2025/02/12 11:38:53 @author: Whenxuan Wang @email: wwhenxuan@gmail.com

pysdkit.entropy._sample_entropy

Created on 2025/02/12 11:38:13 @author: Whenxuan Wang @email: wwhenxuan@gmail.com

entropy.permutation_entropy#

Created on 2025/02/12 11:38:53 @author: Whenxuan Wang @email: wwhenxuan@gmail.com

pysdkit.entropy._permutation_entropy.multiscale_permutation_entropy(X: ndarray, m: int | None, t: int | None, scale: int | None) ndarray[source]#

Calculate the Multiscale Permutation Entropy (MPE) of input time series or signal.

Multiscale Permutation Entropy (MPE) is an extended method based on Permutation Entropy (PE). It captures the multi-scale characteristics of signals by calculating the permutation entropy of time series at different time scales, thereby providing a more comprehensive description of the complexity of the system.

In traditional permutation entropy, the complexity of the original time series is calculated. Multiscale permutation entropy can capture the complexity of the signal at different time scales by calculating it at multiple different time scales.

Multiscale permutation entropy (MPE) can provide the complexity characteristics of time series at different scales by calculating permutation entropy at multiple scales. It has a wide range of applications, especially in biomedicine, complex system analysis, financial markets and other fields, and can reveal the multi-level nonlinear dynamic characteristics of the system.

[1] G Ouyang, J Li, X Liu, X Li, Dynamic Characteristics of Absence EEG Recordings with Multiscale Permutation Entropy Analysis, Epilepsy Research, doi: 10.1016/j.eplepsyres.2012.11.003.

[2] X Li, G Ouyang, D Richards, Predictability analysis of absence seizures with permutation entropy, Epilepsy Research, Vol. 77pp. 70-74, 2007.

MATLAB code: https://ww2.mathworks.cn/matlabcentral/fileexchange/37288-multiscale-permutation-entropy-mpe?s_tid=FX_rc2_behav

Parameters:
  • X – The input 1D time series or signal of numpy ndarray.

  • m – The order of permutation entropy (pattern length).

  • t – The delay time of permutation entropy.

  • scale – the scale factor.

Returns:

MPE: multiscale permuation entropy

pysdkit.entropy._permutation_entropy.permutation_entropy(y: ndarray, m: int | None = 2, t: int | None = 1) Tuple[ndarray, ndarray] | Tuple[float, float][source]#

Calculate the permutation entropy of the input time series of signal.

Permutation entropy is essentially concerned with the complexity of local temporal structures (i.e., short-term dynamics). Permutation entropy is a method to measure the complexity of time series, which is often used to analyze nonlinear and chaotic systems. The core idea of permutation entropy is to measure the degree of chaos of time series through the permutation pattern (i.e. the order of data points).

[1] G Ouyang, J Li, X Liu, X Li, Dynamic Characteristics of Absence EEG Recordings with Multiscale Permutation Entropy Analysis, Epilepsy Research, doi: 10.1016/j.eplepsyres.2012.11.003.

[2] X Li, G Ouyang, D Richards, Predictability analysis of absence seizures with permutation entropy, Epilepsy Research, Vol. 77pp. 70-74, 2007.

MATLAB code: https://ww2.mathworks.cn/matlabcentral/fileexchange/37289-permutation-entropy?s_tid=FX_rc1_behav

Parameters:
  • y – The input 1D time series or signal of numpy ndarray.

  • m – The order of permutation entropy.

  • t – The delay time of permutation entropy.

Returns:

The permutation entropy of input and the histogram for the order distribution.

entropy.sample_entropy#

Created on 2025/02/12 11:38:13 @author: Whenxuan Wang @email: wwhenxuan@gmail.com

pysdkit.entropy._sample_entropy.multiscale_sample_entropy(x: ndarray, m: int | None = 2, r: float | None = 0.15, tau: int | None = 1) Tuple[float | Any, bool, bool][source]#

Multiscale Sample Entropy (MSE) computation.

Based on “Multiscale entropy analysis of biological signals” By Madalena Costa, Ary L. Goldberger, and C.-K. Peng Published on 18 February 2005 in Phys. Rev. E 71, 021906.

MATLAB code: https://ww2.mathworks.cn/matlabcentral/fileexchange/62706-multiscale-sample-entropy

Parameters:
  • x – (array): Input time series (1D array).

  • m – (int): Embedding dimension (default 2).

  • r – (float): Tolerance (default 0.15).

  • tau – (int): Time delay for coarse-graining (default 1).

Returns:

  • e (float): Multiscale Sample Entropy.

  • A (int): Number of matching (m+1)-element sequences.

  • B (int): Number of matching m-element sequences.

pysdkit.entropy._sample_entropy.sample_entropy(y: ndarray, m: int | None, r: float | None, dist_type='chebychev') ndarray | float[source]#

Computing the Sample Entropy of a given signal or time series of 1D numpy ndarray.

The Sample Entropy (SampEn) is a measure used to quantify the complexity or regularity of a time series. It is particularly useful in the context of physiological time-series analysis and can help in identifying the unpredictability and chaotic behaviors in the system from which the time series originates. SampEn is related to the Approximate Entropy (ApEn) but differs in that it does not include self-matches (a match with the same point itself), thus providing a more robust measure for assessing the regularity or randomness of data.

We have made some adjustments to the original result return. The original MATLAB code will return NaN value when A and B are both equal to 0. We have adjusted it to return -np.log(2 / ((N - m - 1) * (N - m))) when A and B are both 0

Richman,J.S.,& Moorman,J.R.(2000). Physiological time-series analysis using approximate entropy and sample entropy. American Journal of Physiology-Heart and Circulatory Physiology, 278(6), H2039-H2049.

MATLAB code: https://ww2.mathworks.cn/matlabcentral/fileexchange/69381-sample-entropy?s_tid=FX_rc3_behav

Parameters:
  • y – The input 1D signal or time series with numpy ndarray vector with dims. [1xN]

  • m – Embedding dimension (m < N) less than the length of the 1D inputs.

  • r – Tolerance (percentage applied to the SD).

  • dist_type – (Optional) Distance type, specified by a string. Default value: ‘chebychev’ (type help pdist for further information).

Returns:

SampEn value. Since SampEn is not defined whenever B = 0, the output value in that case is -np.log(2 / ((N - m - 1) * (N - m))).