Skip to content

Sample Entropy Transform

The sample entropy transform computes the sample entropy of a window. When combined with the SlidingWindow abstraction, the sample entropy transform can be used to compute the sample entropy feature of a time series. Sample entropy is a measure of the complexity of the signal [1]. It is a modification of the approximate entropy (ApEn) algorithm which is implemented here. It is defined as:

\[ \text{Sample Entropy} = -\log\left(\frac{A}{B}\right) \]

where \(A\) is the number of matches for template vectors of length \(m\) and \(B\) is the number of matches for template vectors of length \(m + 1\). A match is defined as a template vector \(x_{m_i}\) that is close to another template vector \(x_{m_j}\) in the sense that the maximum absolute difference between their corresponding scalar elements is less than or equal to a threshold \(r\).

Bases: Transform

Compute the sample entropy of the signal.

References

Sample Entropy -https://en.wikipedia.org/wiki/Sample_entropy

__call__(signal_window, m, r, where=lambda : not np.isnan(x))

Compute the sample entropy of the values in x where where is True. It is a measure of the complexity of a signal.

Parameters:

Name Type Description Default
signal_window ndarray

The signal to find the sample entropy of.

required
m Union[int, int_]

The length of the template vector.

required
r Union[int, int_]

The tolerance.

required
where Callable[[Union[int, float, int_, float_]], Union[bool, bool_]]

A function that takes a value and returns True or False. Default is lambda x: not np.isnan(x) i.e. a measurement is valid if it is not a NaN value.

lambda : not numpy.isnan(x)

Returns:

Type Description
Union[float, float_]

The sample entropy of the values in x where where is True.

Examples

import numpy as np
import autonfeat as aft

# Random data
n_samples = 100
x = np.random.rand(n_samples)

# Create sliding window
ws = 10
ss = 10
window = aft.SlidingWindow(window_size=ws, step_size=ss)

# Create transform
tf = aft.SampleEntropyTransform()

# Get featurizer
featurizer = window.use(tf)

# Get features
features = featurizer(x, m=2, r=0.2)

# Print features
print(window)
print(tf)
print(features)

References

[1] https://en.wikipedia.org/wiki/Sample_entropy

If you enjoy using AutonFeat, please consider starring the repository ⭐️.