Delta Std Preprocessor Transform¶
The Delta Std Preprocessor Transform shifts the input signal by the std of the signal. This is defined as:
For shifting signals by a custom \(\delta\), see the Delta Transform Preprocessor
. For more on how we compute the std of a signal, check out std
function.
Bases: Preprocess
Preprocess the signal by shifting each element in the signal by the standard deviation of the signal.
__call__(signal, ddof=0, where=lambda : not np.isnan(x))
¶
Compute the standard deviation of the signal and shift the signal by this standard deviation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
signal | ndarray | The array to compute the delta with. | required |
ddof | Union[int, int_] | The delta degrees of freedom. Default is | 0 |
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¶
Here we look at an example where we shift two signals by their std to demonstrate the effect of the Delta Std Preprocessor Transform.
Transform Signal¶
First, we define the signals as two normal distributions with different means and standard deviations. Then, we apply the Delta Std Preprocessor Transform to both signals.
A univariate normal distribution with mean \(\mu\) and std \(\sigma\) is defined as:
import numpy as np
import autonfeat as aft
# Number of samples
n_samples = 100
# Generate sample data
x1 = np.random.normal(0, 1, n_samples)
x2 = np.random.normal(5, 5, n_samples)
# Define preprocessor
preprocessor = aft.preprocess.DeltaStdPreprocessor()
shifted_x1 = preprocessor(x1)
shifted_x2 = preprocessor(x2)
Visualize Transform¶
Next, we visualize the effect of the transform on the signals.
import matplotlib.pyplot as plt
# Plot original data
plt.figure(figsize=(8, 4))
plt.subplot(1, 2, 1)
plt.plot(x1, 'b.', label='x1')
plt.plot(x2, 'r.', label='x2')
plt.legend()
plt.title('Original Data')
# Plot shifted data
plt.subplot(1, 2, 2)
plt.plot(shifted_x1, 'b.', label='x1 shifted')
plt.plot(shifted_x2, 'r.', label='x2 shifted')
plt.legend()
plt.title('Shifted Data')
plt.tight_layout()
plt.show()
This can be seen in the figure below.
If you enjoy using AutonFeat
, please consider starring the repository ⭐️.