Sample entropy


Sample entropy is a modification of approximate entropy, used for assessing the complexity of physiological time-series signals, diagnosing diseased states. 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 and the rest of the vectors also includes comparison with itself. This guarantees that probabilities 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.
There is a multiscale version of SampEn as well, suggested by Costa and others.

Definition

Like approximate entropy, Sample entropy is a measure of complexity. But it does not include self-similar patterns as ApEn does. For a given embedding dimension, tolerance and number of data points, SampEn is the negative natural logarithm of the probability that if two sets of simultaneous data points of length have distance then two sets of simultaneous data points of length also have distance. And we represent it by .
Now assume we have a time-series data set of length with a constant time interval. We define a template vector of length, such that and the distance function is to be the Chebyshev distance. We define the sample entropy to be
Where
= number of template vector pairs having
= number of template vector pairs having
It is clear from the definition that will always have a value smaller or equal to. Therefore, will be always either be zero or positive value. A smaller value of also indicates more self-similarity in data set or less noise.
Generally we take the value of to be and the value of to be.
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 for a very large population.

Multiscale SampEn

The definition mentioned above is a special case of multi scale sampEn with,where is called skipping parameter. In multiscale SampEn template vectors are defined with a certain interval between its elements, specified by the value of. And modified template vector is defined as
and sampEn can be written as
And we calculate and like before.

Implementation

Sample entropy can be implemented easily in many different programming languages. Below lies a vectorized example written in python. An example written in Matlab can be found . An example written for R can be found .
Python

import numpy as np
def sampen:
N = len
B = 0.0
A = 0.0


# Split time series and save all templates of length m
xmi = np.array
xmj = np.array
# Save all matches minus the self-match, compute B
B = np.sum.max - 1 for xmii in xmi])
# Similar for computing A
m += 1
xm = np.array
A = np.sum.max - 1 for xmi in xm])
# Return SampEn
return -np.log