tssearch.distances package¶
Submodules¶
tssearch.distances.compute_distance module¶
-
tssearch.distances.compute_distance.
time_series_distance
(dict_distances, x, y, tx=None, ty=None)[source]¶ Parameters: - dict_distances (dict) – Dictionary of distances parameters.
- x (nd-array) – Time series x (query).
- y (nd-array) – Time series y.
- tx (nd-array) – Time stamp time series x.
- ty (nd-array) – Time stamp time series y.
Returns: distances – Distances values.
Return type: pandas DataFrame
tssearch.distances.elastic_distances module¶
-
tssearch.distances.elastic_distances.
dlp
(x, y, p=2)[source]¶ Computes Lp norm distance between two time series.
Parameters: - x (nd-array) – Time series x (query).
- y (nd-array) – Time series y.
- p (int) – Lp norm distance degree for local cost computation.
Returns: Return type: The Lp distance.
-
tssearch.distances.elastic_distances.
dtw
(x, y, weight=None, **kwargs)[source]¶ Computes Dynamic Time Warping (DTW) of two time series.
Parameters: - x (nd-array) – Time series x (query).
- y (nd-array) – Time series y.
- dist (function) – The distance used as a local cost measure. None defaults to the squared euclidean distance.
- **kwargs –
- below (See) –
- do_sign_norm (bool) -- (*) – If
True
the signals will be normalized before computing the DTW, (default:False
) - do_dist_norm (bool) -- (*) – If
True
the DTW distance will be normalized by dividing the summation of the path dimension. (default:True
) - window (String) -- (*) – Selects the global window constrains. Available options are
None
andsakoe-chiba
. (default:None
) - factor (Float) -- (*) – Selects the global constrain factor.
(default:
min(xl, yl) * .50
)
Returns: - d (float) – The DTW distance.
- ac (nd-array) – The accumulated cost matrix.
- path (nd-array) – The optimal warping path between the two sequences.
-
tssearch.distances.elastic_distances.
lcss
(x, y, eps=1, **kwargs)[source]¶ Computes the Longest Common Subsequence (LCSS) distance between two numeric time series.
Parameters: - x (nd-array) – Time series x (query).
- y (nd-array) – Time series y.
- eps (float) – Amplitude matching threshold.
- **kwargs –
- below (See) –
- window (String) -- (*) – Selects the global window constrains. Available options are
None
andsakoe-chiba
. (default:None
)
Returns: - d (float) – The LCSS distance.
- ac (nd-array) – The similarity matrix.
- path (nd-array) – The optimal path between the two sequences.
-
tssearch.distances.elastic_distances.
twed
(x, y, tx, ty, nu=0.001, lmbda=1.0, p=2, report='distance')[source]¶ Computes Time Warp Edit Distance (TWED) of two time series.
- Reference :
- Marteau, P.; F. (2009). “Time Warp Edit Distance with Stiffness Adjustment for Time Series Matching”. IEEE Transactions on Pattern Analysis and Machine Intelligence. 31 (2): 306–318. arXiv:cs/0703033 http://people.irisa.fr/Pierre-Francois.Marteau/
Parameters: - x (nd-array) – Time series x (query).
- y (nd-array) – Time series y.
- tx (nd-array) – Time stamp time series x.
- ty (nd-array) – Time stamp time series y.
- nu (int) –
- Stiffness parameter (nu >= 0)
- nu = 0, TWED distance measure on amplitude. nu > 0, TWED distance measure on amplitude x time.
- lmbda (int) – Penalty for deletion operation (lmbda >= 0).
- p (int) – Lp norm distance degree for local cost computation.
- report (str) – distance, cost matrix, path.
Returns: - d (float) – The TWED distance.
- ac (nd-array) – The accumulated cost matrix.
- path (nd-array) – The optimal warping path between the two sequences.
tssearch.distances.elastic_utils module¶
-
tssearch.distances.elastic_utils.
acc_initialization
(x, y, _type, tolerance=0)[source]¶ Initializes the cost matrix according to the dtw type.
Parameters: - x (nd-array) – Time series x (query).
- y (nd-array) – Time series y.
- _type (string) – Name of dtw type.
- tolerance (int) – Tolerance value.
Returns: ac – The accumulated cost matrix.
Return type: nd-array
-
tssearch.distances.elastic_utils.
accumulated_cost_matrix
(c, **kwargs)[source]¶ Parameters: - c (nd-array) – The cost matrix.
- **kwargs –
Returns: ac – The accumulated cost matrix.
Return type: nd-array
-
tssearch.distances.elastic_utils.
backtracking
(ac)[source]¶ Compute the most cost-efficient path.
Parameters: ac (nd-array) – The accumulated cost matrix. Returns: Return type: Coordinates of the most cost-efficient path.
-
tssearch.distances.elastic_utils.
cost_matrix
(x, y, alpha=1, weight=None)[source]¶ Computes cost matrix using a specified distance (dist) between two time series.
Parameters: - x (nd-array) – Time series x (query).
- y (nd-array) – Time series y.
- dist (function) – The distance used as a local cost measure. None defaults to the squared euclidean distance.
- **kwargs –
- below (See) –
- do_sign_norm (bool) -- (*) – If
True
the signals will be normalized before computing the DTW, (default:False
) - do_dist_norm (bool) -- (*) – If
True
the DTW distance will be normalized by dividing the summation of the path dimension. (default:True
) - window (String) -- (*) – Selects the global window constrains. Available options are
None
andsakoe-chiba
. (default:None
) - factor (Float) -- (*) – Selects the global constrain factor.
(default:
min(xl, yl) * .50
)
Returns: c – The cost matrix.
Return type: nd-array
-
tssearch.distances.elastic_utils.
dtw_sw
(x, y, winlen, alpha=0.5, **kwargs)[source]¶ Computes Dynamic Time Warping (DTW) of two time series using a sliding window. TODO: Check if this needs to be speed up.
Parameters: - x (nd-array) – Time series x (query).
- y (nd-array) – Time series y.
- winlen (int) – The sliding window length.
- alpha (float) – A factor between 0 and 1 which weights the amplitude and derivative contributions. A higher value will favor amplitude and a lower value will favor the first derivative.
- **kwargs –
See below:
- do_sign_norm (
bool
) – IfTrue
the signals will be normalized before computing the DTW, (default:False
) - do_dist_norm (
bool
) – IfTrue
the DTW distance will be normalized by dividing the summation of the path dimension. (default:True
) - window (
String
) – Selects the global window constrains. Available options areNone
andsakoe-chiba
. (default:None
) - factor (
Float
) – Selects the global constrain factor. (default:min(xl, yl) * .50
)
- do_sign_norm (
Returns: - d (float) – The SW-DTW distance.
- c (nd-array) – The local cost matrix.
- ac (nd-array) – The accumulated cost matrix.
- path (nd-array) – The optimal warping path between the two sequences.
-
tssearch.distances.elastic_utils.
get_mirror
(s, ws)[source]¶ Performs a signal windowing based on a double inversion from the start and end segments.
Parameters: - s (nd-array) – the input-signal.
- ws (int) – window size.
Returns: Return type: Signal windowed
-
tssearch.distances.elastic_utils.
lcss_accumulated_matrix
(x, y, eps)[source]¶ Computes the LCSS cost matrix using the euclidean distance (dist) between two time series.
Parameters: - x (nd-array) – Time series x (query).
- y (nd-array) – Time series y.
- eps (float) – Amplitude matching threshold.
Returns: ac – The accumulated cost matrix.
Return type: nd-array
-
tssearch.distances.elastic_utils.
lcss_path
(x, y, c, eps)[source]¶ Computes the LCSS path between two time series.
Parameters: - x (nd-array) – The reference signal.
- y (nd-array) – The estimated signal.
- c (nd-array) – The cost matrix.
- eps (float) – Matching threshold.
Returns: Return type: Coordinates of the minimum LCSS path.
-
tssearch.distances.elastic_utils.
lcss_score
(c)[source]¶ Computes the LCSS similarity score between two time series.
Parameters: c (nd-array) – The cost matrix. Returns: Return type: The LCSS score.
-
tssearch.distances.elastic_utils.
sliding_dist
(xw, yw, dxw, dyw, alpha, win)[source]¶ Computes the sliding distance.
Parameters: - xw (nd-array) – x coords window.
- yw (nd-array) – y coords window.
- dxw (nd-array) – x coords diff window.
- dyw (nd-array) – y coords diff window.
- alpha (float) – Rely more on absolute or difference values 1- abs, 0 - diff.
- win (nd-array) – Signal window used for sliding distance.
Returns: Return type: Sliding distance
tssearch.distances.lockstep_distances module¶
-
tssearch.distances.lockstep_distances.
braycurtis_distance
(x, y, weight=None)[source]¶ Computes the Braycurtis distance between two time series.
If the time series do not have the same length, an interpolation is performed.
Parameters: - x (nd-array) – Time series x.
- y (nd-array) – Time series y.
- weight (nd-array (Default: None)) – query weight values.
Returns: Braycurtis distance value.
Return type:
-
tssearch.distances.lockstep_distances.
canberra_distance
(x, y, weight=None)[source]¶ Computes the Canberra distance between two time series.
If the time series do not have the same length, an interpolation is performed.
Parameters: - x (nd-array) – Time series x.
- y (nd-array) – Time series y.
- weight (nd-array (Default: None)) – query weight values.
Returns: Canberra distance value.
Return type:
-
tssearch.distances.lockstep_distances.
chebyshev_distance
(x, y, weight=None)[source]¶ Computes the Chebyshev distance between two time series.
If the time series do not have the same length, an interpolation is performed.
Parameters: - x (nd-array) – Time series x.
- y (nd-array) – Time series y.
- weight (nd-array (Default: None)) – query weight values.
Returns: Chebyshev distance value.
Return type:
-
tssearch.distances.lockstep_distances.
correlation_distance
(x, y, weight=None)[source]¶ Computes the correlation distance between two time series.
If the time series do not have the same length, an interpolation is performed.
Parameters: - x (nd-array) – Time series x.
- y (nd-array) – Time series y.
- weight (nd-array (Default: None)) – query weight values.
Returns: Correlation distance value.
Return type:
-
tssearch.distances.lockstep_distances.
cosine_distance
(x, y, weight=None)[source]¶ Computes the cosine distance between two time series.
If the time series do not have the same length, an interpolation is performed.
Parameters: - x (nd-array) – Time series x.
- y (nd-array) – Time series y.
- weight (nd-array (Default: None)) – query weight values.
Returns: Cosine distance value.
Return type:
-
tssearch.distances.lockstep_distances.
euclidean_distance
(x, y, weight=None)[source]¶ Computes the Euclidean distance between two time series.
If the time series do not have the same length, an interpolation is performed.
Parameters: - x (nd-array) – Time series x.
- y (nd-array) – Time series y.
- weight (nd-array (Default: None)) – query weight values.
Returns: Euclidean distance value.
Return type:
-
tssearch.distances.lockstep_distances.
hamming_distance
(x, y, weight=None)[source]¶ Computes the Hamming distance between two time series.
If the time series do not have the same length, an interpolation is performed.
Parameters: - x (nd-array) – Time series x.
- y (nd-array) – Time series y.
- weight (nd-array (Default: None)) – query weight values.
Returns: Hamming distance value.
Return type:
-
tssearch.distances.lockstep_distances.
mahalanobis_distance
(x, y, weight=None)[source]¶ Computes the Mahalanobis distance between two time series.
If the time series do not have the same length, an interpolation is performed.
Parameters: - x (nd-array) – Time series x.
- y (nd-array) – Time series y.
- weight (nd-array (Default: None)) – query weight values.
Returns: Mahalanobis distance value.
Return type:
-
tssearch.distances.lockstep_distances.
manhattan_distance
(x, y, weight=None)[source]¶ Computes the Manhattan distance between two time series.
If the time series do not have the same length, an interpolation is performed.
Parameters: - x (nd-array) – Time series x.
- y (nd-array) – Time series y.
- weight (nd-array (Default: None)) – query weight values.
Returns: Manhattan distance value.
Return type:
-
tssearch.distances.lockstep_distances.
minkowski_distance
(x, y, weight=None, p=3)[source]¶ Computes the Minkowski distance between two time series.
If the time series do not have the same length, an interpolation is performed.
Parameters: - x (nd-array) – Time series x.
- y (nd-array) – Time series y.
- weight (nd-array (Default: None)) – query weight values.
- p (int) – Lp norm distance degree.
Returns: Minkowski distance value.
Return type:
-
tssearch.distances.lockstep_distances.
pearson_correlation
(x, y, beta=None)[source]¶ Computes the Pearson correlation between two time series.
If the time series do not have the same length, an interpolation is performed.
Parameters: - x (nd-array) – Time series x.
- y (nd-array) – Time series y.
- beta (float) – Beta coefficient.
Returns: Pearson correlation value.
Return type:
-
tssearch.distances.lockstep_distances.
short_time_series_distance
(x, y, tx=None, ty=None)[source]¶ Computes the short time series distance (STS) between two time series.
Reference: Möller-Levet, C. S., Klawonn, F., Cho, K., and Wolkenhauer, O. (2003).
Parameters: - x (nd-array) – Time series x.
- y (nd-array) – Time series y.
- tx (nd-array) – Sampling index of time series x.
- ty (nd-array) – Sampling index of time series y.
Returns: Short time series distance value.
Return type:
-
tssearch.distances.lockstep_distances.
sqeuclidean_distance
(x, y, weight=None)[source]¶ Computes the squared Euclidean distance between two time series.
If the time series do not have the same length, an interpolation is performed.
Parameters: - x (nd-array) – Time series x.
- y (nd-array) – Time series y.
- weight (nd-array (Default: None)) – query weight values.
Returns: Squared Euclidean distance value.
Return type:
tssearch.distances.lockstep_utils module¶
tssearch.distances.time_distances module¶
-
tssearch.distances.time_distances.
tam
(x, y)[source]¶ Calculates the Time Alignment Measurement (TAM) based on an optimal warping path between two time series.
Reference: Folgado et. al, Time Alignment Measurement for Time Series, 2016.
Parameters: - x (nd-array) – Time series x.
- y (nd-array) – Time series y.
Returns: - In case
report=instants
the number of indexes in advance, delay and phase - will be returned.
- For
report=ratios
, the ratio of advance, delay and phase. - will be returned. In case
report=distance
, only the TAM will be returned.