Skip to content

Delta Quantile Preprocessor

The delta quantile preprocessor function shifts the input signal by the quantile of the signal. This is defined as:

\[ x_{shifted_{i}} = x_{i} - \text{quantile}(x), \quad \forall i \in \{1, \dots, N\} \]

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 preprocessor function. For more on how we compute the quantile of a signal, check out quantile function.

Preprocess the signal x by shifting each element of x by a quantile of x.

Parameters:

Name Type Description Default
x ndarray

The array to shift by its quantile.

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 numpy.quantile for more information.

'linear'
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
ndarray

The shifted signal.

Examples

Transform Signal

import numpy as np
import autonfeat.functional as F
import autonfeat.functional.preprocess as PF

# Generate data
n_samples = 1000
x = np.random.normal(-5, 5, n_samples)

q_tile = 0.25 # 25th quantile
# Preprocess data
x_shifted = PF.delta_quantile_tf(x, q=q_tile)

Visualize Transform

import matplotlib.pyplot as plt

# Plot normal and shifted data
original_quantile = F.quantile_tf(x, q_tile)
shifted_quantile = F.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')

plt.tight_layout()
plt.show()

DeltaQuantile

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