Approximate entropy

From HandWiki

In statistics, an approximate entropy (ApEn) is a technique used to quantify the amount of regularity and the unpredictability of fluctuations over time-series data.[1] For example, consider two series of data:

Series A: (0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, ...), which alternates 0 and 1.
Series B: (0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, ...), which has either a value of 0 or 1, chosen randomly, each with probability 1/2.

Moment statistics, such as mean and variance, will not distinguish between these two series. Nor will rank order statistics distinguish between these series. Yet series A is perfectly regular: knowing a term has the value of 1 enables one to predict with certainty that the next term will have the value of 0. In contrast, series B is randomly valued: knowing a term has the value of 1 gives no insight into what value the next term will have.

Regularity was originally measured by exact regularity statistics, which has mainly centered on various entropy measures.[1] However, accurate entropy calculation requires vast amounts of data, and the results will be greatly influenced by system noise,[2] therefore it is not practical to apply these methods to experimental data. ApEn was developed by Steve M. Pincus to handle these limitations by modifying an exact regularity statistic, Kolmogorov–Sinai entropy. ApEn was initially developed to analyze medical data, such as heart rate,[1] and later spread its applications in finance,[3] physiology,[4] human factors engineering,[5] and climate sciences.[6]

Algorithm

A comprehensive step-by-step tutorial with an explanation of the theoretical foundations of Approximate Entropy is available.[7] The algorithm is:

Step 1
Assume a time series of data [math]\displaystyle{ u(1), u(2),\ldots, u(N) }[/math]. These are [math]\displaystyle{ N }[/math] raw data values from measurements equally spaced in time.
Step 2
Let [math]\displaystyle{ m \in \mathbb{Z}^+ }[/math] be a positive integer, with [math]\displaystyle{ m \leq N }[/math], which represents the length of a run of data (essentially a window).
Let [math]\displaystyle{ r \in \mathbb{R}^+ }[/math] be a positive real number, which specifies a filtering level.
Let [math]\displaystyle{ n=N-m+1 }[/math].
Step 3
Define [math]\displaystyle{ \mathbf{x}(i) = \big[u(i),u(i+1),\ldots,u(i+m-1)\big] }[/math] for each [math]\displaystyle{ i }[/math] where [math]\displaystyle{ 1 \leq i \leq n }[/math]. In other words, [math]\displaystyle{ \mathbf{x}(i) }[/math] is an [math]\displaystyle{ m }[/math]-dimensional vector that contains the run of data starting with [math]\displaystyle{ u(i) }[/math].
Define the distance between two vectors [math]\displaystyle{ \mathbf{x}(i) }[/math] and [math]\displaystyle{ \mathbf{x}(j) }[/math] as the maximum of the distances between their respective components, given by
[math]\displaystyle{ \begin{align} d[\mathbf{x}(i),\mathbf{x}(j) ] & = \max_k \big(|\mathbf{x}(i)_k - \mathbf{x}(j)_k| \big) \\ & = \max_k \big(|u(i+k-1) - u(j+k-1)| \big) \\ \end{align} }[/math]
for [math]\displaystyle{ 1 \leq k \leq m }[/math].
Step 4
Define a count [math]\displaystyle{ C^m_i }[/math] as
[math]\displaystyle{ C_i^m (r)={(\text{number of } j \text { such that } d[\mathbf{x}(i),\mathbf{x}(j)] \leq r) \over n} }[/math]
for each [math]\displaystyle{ i }[/math] where [math]\displaystyle{ 1 \leq i,j \leq n }[/math]. Note that since [math]\displaystyle{ j }[/math] takes on all values between 1 and [math]\displaystyle{ n }[/math], the match will be counted when [math]\displaystyle{ j=i }[/math] (i.e. when the test subsequence, [math]\displaystyle{ \mathbf{x}(j) }[/math], is matched against itself, [math]\displaystyle{ \mathbf{x}(i) }[/math]).
Step 5
Define
[math]\displaystyle{ \phi ^m (r) = {1 \over n} \sum_{i=1}^{n}\log (C_i^m (r)) }[/math]
where [math]\displaystyle{ \log }[/math] is the natural logarithm, and for a fixed [math]\displaystyle{ m }[/math], [math]\displaystyle{ r }[/math], and [math]\displaystyle{ n }[/math] as set in Step 2.
Step 6
Define approximate entropy ([math]\displaystyle{ \mathrm{ApEn} }[/math]) as
[math]\displaystyle{ \mathrm{ApEn}(m,r,N)(u) = \phi ^m (r) - \phi^{m+1} (r) }[/math]
Parameter selection
Typically, choose [math]\displaystyle{ m=2 }[/math] or [math]\displaystyle{ m=3 }[/math], whereas [math]\displaystyle{ r }[/math] depends greatly on the application.

An implementation on Physionet,[8] which is based on Pincus,[2] use [math]\displaystyle{ d[\mathbf{x}(i), \mathbf{x}(j)] \lt r }[/math] instead of [math]\displaystyle{ d[\mathbf{x}(i), \mathbf{x}(j)] \le r }[/math] in Step 4. While a concern for artificially constructed examples, it is usually not a concern in practice.

Example

Illustration of the Heart Rate Sequence

Consider a sequence of [math]\displaystyle{ N=51 }[/math] samples of heart rate equally spaced in time:

[math]\displaystyle{ \ S_N = \{85, 80, 89, 85, 80, 89, \ldots\} }[/math]

Note the sequence is periodic with a period of 3. Let's choose [math]\displaystyle{ m=2 }[/math] and [math]\displaystyle{ r=3 }[/math] (the values of [math]\displaystyle{ m }[/math] and [math]\displaystyle{ r }[/math] can be varied without affecting the result).

Form a sequence of vectors:

[math]\displaystyle{ \begin{align} \mathbf{ x}(1) & = [u(1) \ u(2)]=[85 \ 80]\\ \mathbf{ x}(2) & = [u(2) \ u(3)]=[80 \ 89]\\ \mathbf{ x}(3) & = [u(3) \ u(4)]=[89 \ 85]\\ \mathbf{ x}(4) & = [u(4) \ u(5)]=[85 \ 80]\\ & \ \ \vdots \end{align} }[/math]

Distance is calculated repeatedly as follows. In the first calculation,

[math]\displaystyle{ \ d[\mathbf{x}(1), \mathbf{x}(1)]=\max_k |\mathbf{x}(1)_k - \mathbf{x}(1)_k|=0 }[/math] which is less than [math]\displaystyle{ r }[/math].

In the second calculation, note that [math]\displaystyle{ |u(2)-u(3)| \gt |u(1)-u(2)| }[/math], so

[math]\displaystyle{ \ d[\mathbf{x}(1), \mathbf{x}(2)]=\max_k |\mathbf{x}(1)_k-\mathbf{x}(2)_k|=|u(2)-u(3)|=9 }[/math] which is greater than [math]\displaystyle{ r }[/math].

Similarly,

[math]\displaystyle{ \begin{align} d[\mathbf{x}(1) &, \mathbf{x}(3)] = |u(2)-u(4)| = 5\gt r\\ d[\mathbf{x}(1) &, \mathbf{x}(4)] = |u(1)-u(4)| = |u(2)-u(5)| = 0\lt r\\ & \vdots \\ d[\mathbf{x}(1) &, \mathbf{x}(j)] = \cdots \\ & \vdots \\ \end{align} }[/math]

The result is a total of 17 terms [math]\displaystyle{ \mathbf{ x}(j) }[/math] such that [math]\displaystyle{ d[\mathbf{x}(1), \mathbf{x}(j)]\le r }[/math]. These include [math]\displaystyle{ \mathbf{x}(1), \mathbf{x}(4), \mathbf{x}(7),\ldots,\mathbf{x}(49) }[/math]. In these cases, [math]\displaystyle{ C^m_i(r) }[/math] is

[math]\displaystyle{ \ C_1^2 (3)=\frac{17}{50} }[/math]
[math]\displaystyle{ \ C_2^2 (3)=\frac{17}{50} }[/math]
[math]\displaystyle{ \ C_3^2 (3)=\frac{16}{50} }[/math]
[math]\displaystyle{ \ C_4^2 (3)=\frac{17}{50}\ \cdots }[/math]

Note in Step 4, [math]\displaystyle{ 1 \leq i \leq n }[/math] for [math]\displaystyle{ \mathbf{x}(i) }[/math]. So the terms [math]\displaystyle{ \mathbf{x}(j) }[/math] such that [math]\displaystyle{ d[\mathbf{x}(3), \mathbf{x}(j)] \leq r }[/math] include [math]\displaystyle{ \mathbf{x}(3), \mathbf{x}(6), \mathbf{x}(9),\ldots,\mathbf{x}(48) }[/math], and the total number is 16.

At the end of these calculations, we have

[math]\displaystyle{ \phi^2 (3) = {1 \over 50} \sum_{i=1}^{50}\log(C_i^2(3))\approx-1.0982 }[/math]

Then we repeat the above steps for [math]\displaystyle{ m=3 }[/math]. First form a sequence of vectors:

[math]\displaystyle{ \begin{align} \mathbf{x}(1) & = [u(1) \ u(2) \ u(3)]=[85 \ 80 \ 89]\\ \mathbf{x}(2) & = [u(2) \ u(3) \ u(4)]=[80 \ 89 \ 85]\\ \mathbf{x}(3) & = [u(3) \ u(4) \ u(5)]=[89 \ 85 \ 80]\\ \mathbf{x}(4) & = [u(4) \ u(5) \ u(6)]=[85 \ 80 \ 89]\\ &\ \ \vdots \end{align} }[/math]

By calculating distances between vector [math]\displaystyle{ \mathbf{x}(i), \mathbf{x}(j), 1 \le i \le 49 }[/math], we find the vectors satisfying the filtering level have the following characteristic:

[math]\displaystyle{ d[\mathbf{x}(i), \mathbf{x}(i+3)]=0\lt r }[/math]

Therefore,

[math]\displaystyle{ \ C_1^3 (3)=\frac{17}{49} }[/math]
[math]\displaystyle{ \ C_2^3 (3)=\frac{16}{49} }[/math]
[math]\displaystyle{ \ C_3^3 (3)=\frac{16}{49} }[/math]
[math]\displaystyle{ \ C_4^3 (3)=\frac{17}{49}\ \cdots }[/math]

At the end of these calculations, we have

[math]\displaystyle{ \phi^3 (3)={1 \over 49} \sum_{i=1}^{49}\log(C_i^3(3))\approx-1.0982 }[/math]

Finally,

[math]\displaystyle{ \mathrm{ ApEn}=\phi^2 (3)-\phi^3 (3)\approx0.000010997 }[/math]

The value is very small, so it implies the sequence is regular and predictable, which is consistent with the observation.

Python implementation

import numpy as np


def ApEn(U, m, r) -> float:
    """Approximate_entropy."""

    def _maxdist(x_i, x_j):
        return max([abs(ua - va) for ua, va in zip(x_i, x_j)])

    def _phi(m):
        x = [[U[j] for j in range(i, i + m - 1 + 1)] for i in range(N - m + 1)]
        C = [
            len([1 for x_j in x if _maxdist(x_i, x_j) <= r]) / (N - m + 1.0)
            for x_i in x
        ]
        return (N - m + 1.0) ** (-1) * sum(np.log(C))

    N = len(U)

    return abs(_phi(m + 1) - _phi(m))

Usage example:

>>> U = np.array([85, 80, 89] * 17)
>>> print(ApEn(U, 2, 3))
1.0996541105257052e-05
>>> randU = np.random.choice([85, 80, 89], size=17*3)
>>> print(ApEn(randU, 2, 3))
0.8626664154888908

MATLAB implementation

Interpretation

The presence of repetitive patterns of fluctuation in a time series renders it more predictable than a time series in which such patterns are absent. ApEn reflects the likelihood that similar patterns of observations will not be followed by additional similar observations.[9] A time series containing many repetitive patterns has a relatively small ApEn; a less predictable process has a higher ApEn.

Advantages

The advantages of ApEn include:[2]

  • Lower computational demand. ApEn can be designed to work for small data samples ([math]\displaystyle{ N \lt 50 }[/math] points) and can be applied in real time.
  • Less effect from noise. If data is noisy, the ApEn measure can be compared to the noise level in the data to determine what quality of true information may be present in the data.

Limitations

The ApEn algorithm counts each sequence as matching itself to avoid the occurrence of [math]\displaystyle{ \log(0) }[/math] in the calculations. This step might introduce bias in ApEn, which causes ApEn to have two poor properties in practice:[10]

  1. ApEn is heavily dependent on the record length and is uniformly lower than expected for short records.
  2. It lacks relative consistency. That is, if ApEn of one data set is higher than that of another, it should, but does not, remain higher for all conditions tested.

Applications

ApEn has been applied to classify electroencephalography (EEG) in psychiatric diseases, such as schizophrenia,[11] epilepsy,[12] and addiction.[13]

See also

References

  1. 1.0 1.1 1.2 Pincus, S. M.; Gladstone, I. M.; Ehrenkranz, R. A. (1991). "A regularity statistic for medical data analysis". Journal of Clinical Monitoring and Computing 7 (4): 335–345. doi:10.1007/BF01619355. PMID 1744678. 
  2. 2.0 2.1 2.2 Pincus, S. M. (1991). "Approximate entropy as a measure of system complexity". Proceedings of the National Academy of Sciences 88 (6): 2297–2301. doi:10.1073/pnas.88.6.2297. PMID 11607165. Bibcode1991PNAS...88.2297P. 
  3. Pincus, S.M.; Kalman, E.K. (2004). "Irregularity, volatility, risk, and financial market time series". Proceedings of the National Academy of Sciences 101 (38): 13709–13714. doi:10.1073/pnas.0405168101. PMID 15358860. Bibcode2004PNAS..10113709P. 
  4. Pincus, S.M.; Goldberger, A.L. (1994). "Physiological time-series analysis: what does regularity quantify?". The American Journal of Physiology 266 (4): 1643–1656. doi:10.1152/ajpheart.1994.266.4.H1643. PMID 8184944. 
  5. McKinley, R.A.; McIntire, L.K.; Schmidt, R; Repperger, D.W.; Caldwell, J.A. (2011). "Evaluation of Eye Metrics as a Detector of Fatigue". Human Factors 53 (4): 403–414. doi:10.1177/0018720811411297. PMID 21901937. 
  6. Delgado-Bonal, Alfonso; Marshak, Alexander; Yang, Yuekui; Holdaway, Daniel (2020-01-22). "Analyzing changes in the complexity of climate in the last four decades using MERRA-2 radiation data". Scientific Reports 10 (1): 922. doi:10.1038/s41598-020-57917-8. ISSN 2045-2322. PMID 31969616. Bibcode2020NatSR..10..922D. 
  7. Delgado-Bonal, Alfonso; Marshak, Alexander (June 2019). "Approximate Entropy and Sample Entropy: A Comprehensive Tutorial" (in en). Entropy 21 (6): 541. doi:10.3390/e21060541. PMID 33267255. Bibcode2019Entrp..21..541D. 
  8. "PhysioNet". http://physionet.org/physiotools/ApEn/. 
  9. Ho, K. K.; Moody, G. B.; Peng, C.K.; Mietus, J. E.; Larson, M. G.; levy, D; Goldberger, A. L. (1997). "Predicting survival in heart failure case and control subjects by use of fully automated methods for deriving nonlinear and conventional indices of heart rate dynamics". Circulation 96 (3): 842–848. doi:10.1161/01.cir.96.3.842. PMID 9264491. 
  10. 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): 2039–2049. doi:10.1152/ajpheart.2000.278.6.H2039. PMID 10843903. 
  11. Sabeti, Malihe (2009). "Entropy and complexity measures for EEG signal classification of schizophrenic and control participants". Artificial Intelligence in Medicine 47 (3): 263–274. doi:10.1016/j.artmed.2009.03.003. PMID 19403281. 
  12. Yuan, Qi (2011). "Epileptic EEG classification based on extreme learning machine and nonlinear features". Epilepsy Research 96 (1–2): 29–38. doi:10.1016/j.eplepsyres.2011.04.013. PMID 21616643. 
  13. Yun, Kyongsik (2012). "Decreased cortical complexity in methamphetamine abusers". Psychiatry Research: Neuroimaging 201 (3): 226–32. doi:10.1016/j.pscychresns.2011.07.009. PMID 22445216.