Concept in statistics
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. 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.
However, accurate entropy calculation requires vast amounts of data, and the results will be greatly influenced by system noise, therefore it is not practical to apply these methods to experimental data. ApEn was first proposed (under a different name) by A. Cohen and I. Procaccia,
as an approximate algorithm to compute an exact regularity statistic, Kolmogorov–Sinai entropy, and later popularized by Steve M. Pincus. ApEn was initially used to analyze chaotic dynamics and medical data, such as heart rate, and later spread its applications in finance, physiology, human factors engineering, and climate sciences.
Algorithm.
A comprehensive step-by-step tutorial with an explanation of the theoretical foundations of Approximate Entropy is available. The algorithm is:
 formula_15
 for formula_16.
 formula_18
 for each formula_8 where formula_20. Note that since formula_21 takes on all values between 1 and formula_22, the match will be counted when formula_23 (i.e. when the test subsequence, formula_24, is matched against itself, formula_10).
 formula_26
 where formula_27 is the natural logarithm, and for a fixed formula_28, formula_29, and formula_30 as set in Step 2.
formula_32
An implementation on Physionet, which is based on Pincus, use formula_36 instead of formula_37 in Step 4. While a concern for artificially constructed examples, it is usually not a concern in practice.
Example.
Consider a sequence of formula_38 samples of heart rate equally spaced in time:
formula_39
Note the sequence is periodic with a period of 3. Let's choose formula_40 and formula_41 (the values of formula_42 and formula_43 can be varied without affecting the result).
Form a sequence of vectors: 
formula_44
Distance is calculated repeatedly as follows. In the first calculation,
formula_45 which is less than formula_43.
In the second calculation, note that formula_47, so
formula_48 which is greater than formula_43.
Similarly,
formula_50
The result is a total of 17 terms formula_51 such that formula_52. These include formula_53. In these cases, formula_54 is
formula_55
formula_56
formula_57
formula_58
Note in Step 4, formula_59 for formula_13. So the terms formula_24 such that formula_62 include formula_63, and the total number is 16.
At the end of these calculations, we have
formula_64
Then we repeat the above steps for formula_65. First form a sequence of vectors: 
formula_66
By calculating distances between vector formula_67, we find the vectors satisfying the filtering level have the following characteristic:
formula_68
Therefore, 
formula_69
formula_70
formula_71
formula_72
At the end of these calculations, we have
formula_73
Finally,
formula_74
The value is very small, so it implies the sequence is regular and predictable, which is consistent with the observation.
Python implementation.
import math
def approx_entropy(time_series, run_length, filter_level) - ; float:
 Approximate entropy
 » ; import random
 » ; regularly = [85, 80, 89] * 17
 » ; print(f"{approx_entropy(regularly, 2, 3):e}")
 1.099654e-05
 » ; randomly = [random.choice([85, 80, 89]) for _ in range(17*3)]
 » ; 0.8 ; approx_entropy(randomly, 2, 3) ; 1
 True
 def _maxdist(x_i, x_j):
 return max(abs(ua - va) for ua, va in zip(x_i, x_j))
 def _phi(m):
 n = time_series_length - m + 1
 x = [
 [time_series[j] for j in range(i, i + m - 1 + 1)]
 for i in range(time_series_length - m + 1)
 counts = [
 sum(1 for x_j in x if _maxdist(x_i, x_j) ;= filter_level) / n for x_i in x
 return sum(math.log(c) for c in counts) / n
 time_series_length = len(time_series)
 return abs(_phi(run_length + 1) - _phi(run_length))
if __name__ == "__main__":
 import doctest
 doctest.testmod()
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. 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:
Limitations.
The ApEn algorithm counts each sequence as matching itself to avoid the occurrence of formula_76 in the calculations. This step might introduce bias in ApEn, which causes ApEn to have two poor properties in practice: 
Applications.
ApEn has been applied to classify electroencephalography (EEG) in psychiatric diseases, such as schizophrenia, epilepsy, and addiction.
References.
 ;templatestyles src="Reflist/styles.css" / ;