Delta Quantile Preprocessor Transform¶
The Delta Quantile Preprocessor Transform shifts the input signal by the quantile of the signal. This is defined as:
where \(x_{i}\) represents an element of the input signal, \(x_{shifted_{i}}\) represents an element of the output signal, and \(N\) is the number of elements in the signal.
For shifting signals by a custom \(\delta\), see the Delta Transform Preprocessor
. For more on how we compute the quantile of a signal, check out quantile
function.
Bases: Preprocess
Preprocess the signal by shifting each element in the signal by the quantile of the signal.
__call__(signal, q, method='linear', where=lambda : not np.isnan(x))
¶
Compute the quantile of the signal and shift the signal by this quantile.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
signal | ndarray | The array to compute the delta with. | required |
q | Union[float, float_] | The quantile to compute. Must be between 0 and 1. | required |
method | str | The method to use when computing the quantile. Default is 'linear'. See | 'linear' |
where | Callable[[Union[int, float, int_, float_]], Union[bool, bool_]] | A function that takes a value and returns | lambda : not numpy.isnan(x) |
Returns:
Type | Description |
---|---|
ndarray | The shifted signal. |
Examples¶
Transform Signal¶
import numpy as np
import autonfeat as aft
# Generate data
n_samples = 1000
x = np.random.normal(-5, 5, n_samples)
# Create a preprocessor
preprocessor = aft.preprocess.DeltaQuantilePreprocessor()
q_tile = 0.25 # 25th quantile
# Preprocess data
x_shifted = preprocessor(x, q=q_tile)
Visualize Transform¶
import matplotlib.pyplot as plt
# Plot normal and shifted data
original_quantile = aft.functional.quantile_tf(x, q_tile)
shifted_quantile = aft.functional.quantile_tf(x_shifted, q_tile)
plt.figure(figsize=(8, 6))
plt.plot(x, '.', color='blue', label='Origianl Data')
plt.axhline(original_quantile, color='red', linestyle='--', linewidth=3, label=f'Original Data 25th quantile = {original_quantile:.2f}')
plt.plot(x_shifted, '.', color='orange', label='Shifted Data')
plt.axhline(shifted_quantile, color='green', linestyle='--', linewidth=3, label=f'Shifted Data 25th quantile = {shifted_quantile:.2f}')
plt.legend()
plt.title('Delta Quantile Preprocessing Transform')
plt.tight_layout()
plt.show()
If you enjoy using AutonFeat
, please consider starring the repository ⭐️.