Skip to content

Approximate Entropy Transform

The approximate entropy transform computes the approximate entropy of a window. When combined with the SlidingWindow abstraction, the approximate entropy transform can be used to compute the approximate entropy feature of a time series. It is used to quantify the amount of regularity and the unpredictability signals. Approximate entropy measures the likelihood that similar patterns of observations will not be followed by these similar patterns, therefore a time-series signal that exhibits seasonality or other kinds of repetitive patterns will have a relatively small approximate entropy whereas signals without such a repetitive nature will exhibit a high value of approximate entropy [1]. It is defined as:

\[ ApEn(m, r) = \phi_{m}(r) - \phi_{m+1}(r) \]
\[ \phi_{m}(r) = \frac{1}{N-m+1} \sum_{i=1}^{N-m+1} \ln C_m^i(r) \]
\[ C_m^i(r) = \frac{1}{N-m+1} \sum_{j=1}^{N-m+1} \Theta(r - ||x_{i+j-1} - x_{j}||) \]

where \(m\) is the embedding dimension, \(r\) is the tolerance, \(N\) is the length of the signal, \(x_i\) is the \(i^{th}\) sample of the signal, and \(\Theta\) is the Heaviside step function.

Bases: Transform

Compute the approximate entropy of the signal.

References

Approximate Entropy - https://en.wikipedia.org/wiki/Approximate_entropy

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

Compute the approximate entropy of the values in x where where is True. It used to quantify the amount of regularity and the unpredictability of fluctuations in the signal.

Parameters:

Name Type Description Default
signal_window ndarray

The signal to find the approximate 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 approximate 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.ApproxEntropyTransform()

# 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/Approximate_entropy

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