Postprocess

This module offers functionality to postprocess the pattern-based embedding. All postprocessors can be imported as follows:

>>> from patsemb import postprocess

The postprocessors use the fit-transform interface to handle the pattern-based embedding. Given a pattern-based embedding, the postprocessors transform it into a new, slightly adjusted embedding.

class patsemb.postprocess.Smoother(nb_iterations: int = 1, weights: array = None)[source]

Apply temporal smoothing on the embedding matrix. Temporal smoothing will transform each column in the embedding matrix by taking the weighted average of that column and the neighboring columns. This ensures that the consecutive time steps have more similar values.

Specifically, the transformation of column i in embedding matrix E with normalized weights W equals:

E[:, i] = … + W[1] * E[:, i-1] + W[0] * E[:, i] + W[1] * E[:, i+1] + …

Parameters:
  • nb_iterations (int, default=1) – The number of times smoothing will be applied. This value must be at least 1.

  • weights (np.array of shape (size_neighborhood,)) – The weights used for aggregating the columns. The first weight corresponds to the weight of the current column, the other weights correspond to the weights of neighboring columns. The weights are interpreted to be relative and will be normalized during smoothing. At least two weights must be provided. None of the weights can be negative.

fit(X: ndarray, y=None) Smoother[source]

Fit this Smoother. For smoothing there is no fitting necessary.

Parameters:
  • X (np.ndarray of shape (n_patterns, n_samples)) – The embedding matrix to use for fitting this postprocessor.

  • y (Ignored) – Is passed for fitting the discretizer, but will typically not be used and is only present here for API consistency by convention.

Returns:

self – Returns the instance itself

Return type:

Smoother

transform(X: ndarray) ndarray[source]

Smooth the given embedding matrix.

Parameters:

X (np.ndarray of shape (n_patterns, n_samples)) – The embedding matrix on which the smoothing should be applied.

Returns:

smoothed_embedding_matrix – The smoothed embedding matrix.

Return type:

np.ndarray of shape (n_patterns, n_samples)