hookeai.utilities.data_denoisers.Denoiser

class Denoiser[source]

Bases: object

Data denoiser.

denoise(self, tensor, denoise_method, denoise_parameters={})[source]

Denoise features tensor.

_dn_moving_average(self, tensor, window_size)[source]

Denoising method: Moving Average.

_dn_savitzky_golay(self, tensor, window_size, poly_order)[source]

Denoising method: Savitzky-Golay filter.

_dn_frequency_low_pass(self, tensor, cutoff_frequency, is_plot_magnitude_spectrum=False)[source]

Denoising method: Frequency low-pass filter.

_check_tensor(self, tensor)[source]

Check features tensor to be denoised.

Constructor.

List of Public Methods

denoise

Denoise features tensor.

Methods

__init__()[source]

Constructor.

_check_tensor(tensor)[source]

Check features tensor to be denoised.

Parameters:

tensor (torch.Tensor) – Features PyTorch tensor stored as torch.Tensor with shape (sequence_length, n_features).

_dn_frequency_low_pass(tensor, cutoff_frequency, is_plot_magnitude_spectrum=False)[source]

Denoising method: Frequency low-pass filter.

Filtering is performed independently for each feature.

Parameters:
  • tensor (torch.Tensor) – Features PyTorch tensor stored as torch.Tensor with shape (sequence_length, n_features).

  • cutoff_frequency (int) – Cutoff frequency of the low-pass filter.

  • is_plot_magnitude_spectrum (bool, default=False) – If True, then plot magnitude spectrum and cutoff frequency.

Returns:

dn_tensor – Denoised features PyTorch tensor stored as torch.Tensor with shape (sequence_length, n_features).

Return type:

torch.Tensor

_dn_moving_average(tensor, window_size)[source]

Denoising method: Moving Average.

Convolution is performed independently for each feature.

Edge padding is performed to preserve input tensor shape.

Parameters:
  • tensor (torch.Tensor) – Features PyTorch tensor stored as torch.Tensor with shape (sequence_length, n_features).

  • window_size (int) – Convolution kernel size.

Returns:

dn_tensor – Denoised features PyTorch tensor stored as torch.Tensor with shape (sequence_length, n_features).

Return type:

torch.Tensor

_dn_savitzky_golay(tensor, window_size, poly_order)[source]

Denoising method: Savitzky-Golay filter.

Convolution is performed independently for each feature.

Edge padding is performed to preserve input tensor shape.

General thumb rules:

  1. Set an odd number for the window_size (ensures that there is a central point around which the smoothing occurs)

  2. The window_size should be around 5% to 15% of the sequence length, depending on the level of noise. Larger window_size smooths more effectively but may remove important details, while a smaller window preserves more detail but may not adequately smooth out noise

  3. The poly_order must be less than window_size (ensures that there are enough points to fit the polynomial correctly)

  4. The poly_order is usually between 1 and 4. Lower poly_order is effective when data has a simple trend or is relative smooth, while larger poly_order is effective for data that is inherently more complex. Higher polynomial orders may introduce undesired oscillations!

Parameters:
  • tensor (torch.Tensor) – Features PyTorch tensor stored as torch.Tensor with shape (sequence_length, n_features).

  • window_size (int) – Convolution kernel size (number of Savitzky-Golay coefficients).

  • poly_order (int) – Order of polynomial used to fit the samples in the window. Must be less that window_size.

Returns:

dn_tensor – Denoised features PyTorch tensor stored as torch.Tensor with shape (sequence_length, n_features).

Return type:

torch.Tensor

denoise(tensor, denoise_method, denoise_parameters={}, n_denoise_cycle=1)[source]

Denoise features tensor.

Parameters:
  • tensor (torch.Tensor) – Features PyTorch tensor stored as torch.Tensor with shape (sequence_length, n_features).

  • denoise_method (str) – Denoising method.

  • denoise_parameters (dict, default={}) – Denoising method parameters.

  • n_denoise_cycle (int, default=1) – Number of times that the denoise method is applied recurrently to denoise the features tensor.

Returns:

dn_tensor – Denoised features PyTorch tensor stored as torch.Tensor with shape (sequence_length, n_features).

Return type:

torch.Tensor