[ENH] dunders for time series distances and kernels #3949
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds dunders for time series distances and kernels (descendants of
BasePairwiseTransformerPanel
), behaving as per likely user expectation, description as below.It also adds tests for the different combinations of dunders and estimators.
algebraic operations between time series distances and kernels
d = dist1 * dist2
satisfiesd(X1, X2) == dist1(X1, X2) * dist2(X1, X2)
, for all pairwise transformersdist1
,dist2
, equality for all elements of the resulting matrixd = dist1 + dist2
givesd(X1, X2) == dist1(X1, X2) + dist2(X1, X2)
, for all pairwise transformersdist1
,dist2
dist
and an int or floatconst
,d = dist * const
ord = const * dist
givesd(X1, X2) == dist(X1, X2) * const
dist
and an int or floatconst
,d = dist + const
ord = const + dist
givesd(X1, X2) == dist(X1, X2) + const
pipeline concatenation between ordinary transformers and time series distances or kernels
trafo
and a pairwisedist
, the esteimatorpipe = trafo * dist
is also a pairwise distance, withpipe(X1, X2) == dist(trafo.fit_transform(X1), trafo.fit_transform(X2))
trafo
can be ansktime
transformer, or ansklearn
transformer (which is coerced/wrapped)This especially may be interesting for users with a research interest in time series classification or clustering, as it allows to obtain common time series distances easily as composition of others.
E.g., ddtw (for common definitions of ddtw) is the same as
Differencer() * DtwDist()
(first difference, then dtw distance). Higher order differences or other combinations are also easy to obtain by this.