Filtering (Filter)

Filtering removes or reduces some unwanted components (such as noise) from an observation sequence according to some window size and one of two methods: median and mean filtering.

Suppose we have an observation sequence \(\mathbf{o}^{(1)}\mathbf{o}^{(2)}\ldots\mathbf{o}^{(T)}\) and we are filtering with a window size of \(n\). Filtering replaces every observation \(\mathbf{o}^{(t)}\) with either the mean or median of the window of observations of size \(n\) containing \(\mathbf{o}^{(t)}\) in its centre.

  • For median filtering: \(\mathbf{o}^{(t)\prime}=\mathrm{med}\underbrace{\left[\ldots, \mathbf{o}^{(t-1)}, \mathbf{o}^{(t)}, \mathbf{o}^{(t+1)}, \ldots\right]}_n\)

  • For mean filtering: \(\mathbf{o}^{(t)\prime}=\mathrm{mean}\underbrace{\left[\ldots, \mathbf{o}^{(t-1)}, \mathbf{o}^{(t)}, \mathbf{o}^{(t+1)}, \ldots\right]}_n\)

API reference

class sequentia.preprocessing.Filter(window_size, method='median')[source]

Applies a median or mean filter to the input observation sequence(s).

window_size: int > 0

The size of the filtering window.

method: {‘median’, ‘mean’}

The filtering method.


>>> # Create some sample data
>>> X = [np.random.random((10 * i, 3)) for i in range(1, 4)]
>>> # Filter the data with window size 5 and median filtering
>>> X = Filter(window_size=5, method='median')(X)

Applies the transformation to a single observation sequence.

X: numpy.ndarray (float)

An individual observation sequence.

transformed: numpy.ndarray (float)

The transformed input observation sequence.

__call__(X, validate=True)

Applies the transformation to the observation sequence(s).

X: numpy.ndarray (float) or list of numpy.ndarray (float)

An individual observation sequence or a list of multiple observation sequences.

validate: bool

Whether or not to validate the input sequences.

transformed: numpy.ndarray (float) or list of numpy.ndarray (float)

The transformed input observation sequence(s).