Preprocessing
dtaidistance.preprocessing
Preprocessing time series.
- author:
Wannes Meert
- copyright:
Copyright 2021-2024 KU Leuven, DTAI Research Group.
- license:
Apache License, Version 2.0, see LICENSE for details.
- dtaidistance.preprocessing.derivative(series, smooth=None)
Derivative series.
dq = ((q_i - q_{i-1}) + (q_{i+1} - q_{i-1})/2)/2
Based on Keogh, E. and Pazzani, M. “Derivative Dynamic Time Warping”. SIAM International Conference on Data Mining, 2002.
The smoothing argument is used to smooth after computing the derivative. To apply the smoothing as explained in Keogh et al. (2002) one should do exponential smoothing before applying this method.
- Parameters:
series – Time series (must be numpy compatible)
smooth – Smooth the derivative series by removing the highest frequencies. The cut-off frequency is computed using the smooth argument. This fraction (a number between 0.0 and 0.5) of the highest frequencies is removed.
- Returns:
Differenced Numpy array of length len(series) - 1
- dtaidistance.preprocessing.differencing(series, smooth=None, diff_args=None)
Differencing series.
- Parameters:
series – Time series (must be numpy compatible)
smooth – Smooth the differenced series by removing the highest frequencies. The cut-off frequency is computed using the smooth argument. This fraction (a number between 0.0 and 0.5) of the highest frequencies is removed.
diff_args – Arguments to pass the numpy.diff
- Returns:
Differenced Numpy array of length len(series) - 1
- dtaidistance.preprocessing.logdomain(series)
Transform to the log domain and retain the sign of the signal.
- Parameters:
series – Time series (must be numpy compatible)
- dtaidistance.preprocessing.mixedlinearlogdomain(series, c=10)
Transform to a mixture between linear and log domain (and retain the sign of the signal).
The transformation is (for positive values): x if x<=c c+ln(x-c+1) if x>c
- Parameters:
series – Time series (must be numpy compatible)
c (Union[int,list]) – Switch between linear to log domain at this value, should be <= 1. If two numbers are given as a tuple, the first one is used for positive values, the second for negative values.
- dtaidistance.preprocessing.scale_linearly(src_ts, tgt_ts, quantile=0.05, nb_steps=10, use_totalleastsquares=True, use_znormalization=True)
Scale the amplitude of src_ts timeseries linearly to match the tgt_ts timeries. An affine transformation is applied to the src_ts.
If the time series are multivariate, the scaling is applied independently to each variate.
- Parameters:
src_ts – array-like, shape (n_samples, n_variates) or (n_samples,) Source time series.
tgt_ts – array-like, shape (n_samples, n_variates) or (n_samples,) Target time series.
quantile – Which quantile of the points in the time series should be used.
nb_steps – How many steps to use to reduce the number of points in the time series to reach the amount specified by the quantile.
use_totalleastsquares
use_znormalization – First perform z-normalization. If the values of one series are larger, this gets more weight in the least squares.
- Returns:
A scaled src_ts
- dtaidistance.preprocessing.smoothing(series, smooth)
Smooth the series.
Since version 2.4 the filter uses Gustafsson’s method for handling the edges of the series.
- Parameters:
series – Time series (must be numpy compatible)
smooth – Smooth the series by removing the highest frequencies. The cut-off frequency is computed using the smooth argument. This fraction (a number between 0.0 and 0.5) of the highest frequencies is removed.
- Returns:
Smoothed series as Numpy array
- dtaidistance.preprocessing.znormal(series)
Z-normalize the time series.
- Parameters:
series – Time series (must be a numpy compatible)
- Returns:
Z-normalized Numpy array