Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] dunders for time series distances and kernels #3949

Merged
merged 12 commits into from Dec 27, 2022
Merged

Conversation

fkiraly
Copy link
Collaborator

@fkiraly fkiraly commented Dec 18, 2022

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 satisfies d(X1, X2) == dist1(X1, X2) * dist2(X1, X2), for all pairwise transformers dist1, dist2, equality for all elements of the resulting matrix
  • d = dist1 + dist2 gives d(X1, X2) == dist1(X1, X2) + dist2(X1, X2), for all pairwise transformers dist1, dist2
  • for a pairwise distance dist and an int or float const, d = dist * const or d = const * dist gives d(X1, X2) == dist(X1, X2) * const
  • for a pairwise distance dist and an int or float const, d = dist + const or d = const + dist gives d(X1, X2) == dist(X1, X2) + const

pipeline concatenation between ordinary transformers and time series distances or kernels

  • for a transformer trafo and a pairwise dist, the esteimator pipe = trafo * dist is also a pairwise distance, with pipe(X1, X2) == dist(trafo.fit_transform(X1), trafo.fit_transform(X2))
  • above, the transformer trafo can be an sktime transformer, or an sklearn 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.

@fkiraly fkiraly added module:distances&kernels dists_kernels and distances modules: time series distances, kernels, pairwise transforms enhancement Adding new functionality labels Dec 18, 2022
@fkiraly fkiraly merged commit 65a5304 into main Dec 27, 2022
@fkiraly fkiraly deleted the dists-dunders branch December 27, 2022 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Adding new functionality module:distances&kernels dists_kernels and distances modules: time series distances, kernels, pairwise transforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant