sample entropy

Sample entropy (SampEn; more appropriately K_2 entropy or Takens-Grassberger-Procaccia correlation entropy ) is a modification of approximate entropy (ApEn; more appropriately "Procaccia-Cohen entropy"), used for assessing the complexity of physiological and other time-series signals, diagnosing e.g. diseased states.{{cite journal |pmid=10843903|doi=10.1152/ajpheart.2000.278.6.H2039 |year=2000 |last1=Richman |first1=JS |last2=Moorman |first2=JR |url=http://ajpheart.physiology.org/content/278/6/H2039.full|title=Physiological time-series analysis using approximate entropy and sample entropy |volume=278 |issue=6 |pages=H2039–49 |journal=American Journal of Physiology. Heart and Circulatory Physiology|url-access=subscription }} SampEn has two advantages over ApEn: data length independence and a relatively trouble-free implementation. Also, there is a small computational difference: In ApEn, the comparison between the template vector (see below) and the rest of the vectors also includes comparison with itself. This guarantees that probabilities C_{i}'^{m}(r) are never zero. Consequently, it is always possible to take a logarithm of probabilities. Because template comparisons with itself lower ApEn values, the signals are interpreted to be more regular than they actually are. These self-matches are not included in SampEn. However, since SampEn makes direct use of the correlation integrals, it is not a real measure of information but an approximation. The foundations and differences with ApEn, as well as a step-by-step tutorial for its application is available at.{{Cite journal|last1=Delgado-Bonal|first1=Alfonso|last2=Marshak|first2=Alexander|date=June 2019|title=Approximate Entropy and Sample Entropy: A Comprehensive Tutorial|journal=Entropy|language=en|volume=21|issue=6|pages=541|doi=10.3390/e21060541|pmid=33267255|pmc=7515030|bibcode=2019Entrp..21..541D|doi-access=free}}

SampEn is indeed identical to the "correlation entropy" K_2 of Grassberger & Procaccia,{{cite journal |doi=10.1103/PhysRevA.28.2591 | title=Estimation of the Kolmogorov entropy from a chaotic signal |year=1983 |last1=Grassberger|first1=Peter|last2=Procaccia|first2=Itamar | journal=Physical Review A |volume=28|issue=4| page=2591(R)

| bibcode=1983PhRvA..28.2591G }} except that it is suggested in the latter that certain limits should be taken in order to achieve a result invariant under changes of variables. No such limits and no invariance properties are considered in SampEn.

There is a multiscale version of SampEn as well, suggested by Costa and others.{{cite journal |doi=10.1103/PhysRevE.71.021906 |title=Multiscale entropy analysis of biological signals |year=2005 |last1=Costa |first1=Madalena |last2=Goldberger |first2=Ary |last3=Peng |first3=C.-K. |journal=Physical Review E |volume=71 |issue=2 |pmid=15783351 |page=021906|bibcode=2005PhRvE..71b1906C }} SampEn can be used in biomedical and biomechanical research, for example to evaluate postural control.{{Cite journal|last1=Błażkiewicz|first1=Michalina|last2=Kędziorek|first2=Justyna|last3=Hadamus|first3=Anna|date=March 2021|title=The Impact of Visual Input and Support Area Manipulation on Postural Control in Subjects after Osteoporotic Vertebral Fracture|journal=Entropy|language=en|volume=23|issue=3|pages=375|doi=10.3390/e23030375|pmid=33804770| pmc=8004071 |bibcode=2021Entrp..23..375B|doi-access=free}}{{Cite journal|last1=Hadamus|first1=Anna|last2=Białoszewski|first2=Dariusz|last3=Błażkiewicz|first3=Michalina|last4=Kowalska|first4=Aleksandra J.|last5=Urbaniak|first5=Edyta|last6=Wydra|first6=Kamil T.|last7=Wiaderna|first7=Karolina|last8=Boratyński|first8=Rafał|last9=Kobza|first9=Agnieszka|last10=Marczyński|first10=Wojciech|date=February 2021|title=Assessment of the Effectiveness of Rehabilitation after Total Knee Replacement Surgery Using Sample Entropy and Classical Measures of Body Balance|journal=Entropy|language=en|volume=23|issue=2|pages=164| pmid=33573057| doi=10.3390/e23020164 |pmc=7911395|bibcode=2021Entrp..23..164H|doi-access=free}}

Definition

Like approximate entropy (ApEn), Sample entropy (SampEn) is a measure of complexity. But it does not include self-similar patterns as ApEn does. For a given embedding dimension m , tolerance r and number of data points N , SampEn is the negative natural logarithm of the probability that if two sets of simultaneous data points of length m have distance < r then two sets of simultaneous data points of length m+1 also have distance < r . And we represent it by SampEn(m,r,N) (or by SampEn(m,r,\tau,N) including sampling time \tau).

Now assume we have a time-series data set of length N = { \{ x_1 , x_2 , x_3 , . . . , x_N \} } with a constant time interval \tau. We define a template vector of length m , such that X_m (i)={ \{ x_i , x_{i+1} , x_{i+2} , . . . , x_{i+m-1} \} } and the distance function d[X_m(i),X_m(j)] (i≠j) is to be the Chebyshev distance (but it could be any distance function, including Euclidean distance). We define the sample entropy to be

:

SampEn=-\ln {A \over B}

Where

A = number of template vector pairs having d[X_{m+1}(i),X_{m+1}(j)] < r

B = number of template vector pairs having d[X_m(i),X_m(j)] < r

It is clear from the definition that A will always have a value smaller or equal to B. Therefore, SampEn(m,r,\tau) will be always either be zero or positive value. A smaller value of SampEn also indicates more self-similarity in data set or less noise.

Generally we take the value of m to be 2 and the value of r to be 0.2 \times std.

Where std stands for standard deviation which should be taken over a very large dataset. For instance, the r value of 6 ms is appropriate for sample entropy calculations of heart rate intervals, since this corresponds to 0.2 \times std for a very large population.

Multiscale SampEn

The definition mentioned above is a special case of multi scale sampEn with \delta=1 , where \delta is called skipping parameter. In multiscale SampEn template vectors are defined with a certain interval between its elements, specified by the value of \delta . And modified template vector is defined as

X_{m,\delta}(i)={x_i,x_{i+\delta},x_{i+2\times\delta},...,x_{i+(m-1)\times\delta} }

and sampEn can be written as

SampEn \left ( m,r,\delta \right )=-\ln { A_\delta \over B_\delta }

And we calculate A_\delta and B_\delta like before.

Implementation

Sample entropy can be implemented easily in many different programming languages. Below lies an example written in Python.

from itertools import combinations

from math import log

def construct_templates(timeseries_data: list, m: int = 2):

num_windows = len(timeseries_data) - m + 1

return [timeseries_data[x : x + m] for x in range(0, num_windows)]

def get_matches(templates: list, r: float):

return len(

list(filter(lambda x: is_match(x[0], x[1], r), combinations(templates, 2)))

)

def is_match(template_1: list, template_2: list, r: float):

return all([abs(x - y) < r for (x, y) in zip(template_1, template_2)])

def sample_entropy(timeseries_data: list, window_size: int, r: float):

B = get_matches(construct_templates(timeseries_data, window_size), r)

A = get_matches(construct_templates(timeseries_data, window_size + 1), r)

return -log(A / B)

{{Excessive examples|date=July 2024}}

An equivalent example in numerical Python.

import numpy

def construct_templates(timeseries_data, m):

num_windows = len(timeseries_data) - m + 1

return numpy.array([timeseries_data[x : x + m] for x in range(0, num_windows)])

def get_matches(templates, r):

return len(

list(filter(lambda x: is_match(x[0], x[1], r), combinations(templates)))

)

def combinations(x):

idx = numpy.stack(numpy.triu_indices(len(x), k=1), axis=-1)

return x[idx]

def is_match(template_1, template_2, r):

return numpy.all([abs(x - y) < r for (x, y) in zip(template_1, template_2)])

def sample_entropy(timeseries_data, window_size, r):

B = get_matches(construct_templates(timeseries_data, window_size), r)

A = get_matches(construct_templates(timeseries_data, window_size + 1), r)

return -numpy.log(A / B)

An example written in other languages can be found:

  • [http://www.mathworks.com/matlabcentral/fileexchange/35784-sample-entropy Matlab]
  • [https://cran.r-project.org/web/packages/nonlinearTseries/ R].
  • [https://github.com/RyanDoesMath/sample_entropy Rust]

See also

References