From c995ca70e11bca7e2563eb1abe98062bcbb6044c Mon Sep 17 00:00:00 2001 From: Akari Akaza Date: Thu, 3 Dec 2026 15:56:00 +0800 Subject: [PATCH 1/2] [MRG] Reuse local distances across path lengths in constrained DTW (#848) * Reuse local distances across path lengths in constrained DTW Joint work by xiex16070-jpg and OpenAI Codex. Codex implemented the recurrence change, wrote the regression test and ran validation. * Remove the private call-count test after review Joint work by xiex16070-jpg and OpenAI Codex. Codex addressed review feedback and reran the metrics suite and constrained DTW doctests. --------- Co-authored-by: xiex16070-jpg <285003857+xiex16070-jpg@users.noreply.github.com> --- tslearn/metrics/dtw_variants.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tslearn/metrics/dtw_variants.py b/tslearn/metrics/dtw_variants.py index ed1dc719..80cb11b9 100644 --- a/tslearn/metrics/dtw_variants.py +++ b/tslearn/metrics/dtw_variants.py @@ -145,9 +145,11 @@ def _limited_warping_length_cost(s1, s2, max_length, be=None): for j in range(1, s2.shape[0]): min_s = max(i, j) max_s = _max_steps(i, j, max_length - 1, s1.shape[0], s2.shape[0]) + if min_s > max_s: + continue + local_cost = _local_squared_dist(s1[i], s2[j], be=be) for s in range(min_s, max_s + 1): - dict_costs[i, j][s] = _local_squared_dist(s1[i], s2[j], be=be) - dict_costs[i, j][s] += min( + dict_costs[i, j][s] = local_cost + min( dict_costs[i, j - 1].get(s - 1, be.inf), dict_costs[i - 1, j].get(s - 1, be.inf), dict_costs[i - 1, j - 1].get(s - 1, be.inf), From dd18a1945b1ea5118622728650765965110d70a0 Mon Sep 17 00:00:00 2001 From: Abdullah Malik <78163416+teeps-heisenberg@users.noreply.github.com> Date: Thu, 3 Dec 2026 13:37:36 +0500 Subject: [PATCH 2/2] DOC fix dead joblib.Parallel and n_jobs glossary links (#850) The `verbose` parameter docstrings link to joblib.readthedocs.io/en/latest/parallel.html#parallel-reference-documentation, which now returns HTTP 404 because joblib moved its API reference. Point them to the joblib.Parallel reference page, which documents `verbose`. cdist_ctw also links to the scikit-learn glossary with the anchor `#term-n-jobs`, which does not exist. The real anchor is `#term-n_jobs` (already used by the other docstrings). --- tslearn/metrics/_dtw.py | 2 +- tslearn/metrics/_frechet.py | 2 +- tslearn/metrics/_gak.py | 2 +- tslearn/metrics/_soft_dtw.py | 4 ++-- tslearn/metrics/ctw.py | 4 ++-- tslearn/metrics/sax.py | 2 +- tslearn/metrics/utils.py | 2 +- tslearn/neighbors/neighbors.py | 4 ++-- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tslearn/metrics/_dtw.py b/tslearn/metrics/_dtw.py index ee45bc25..f2ba8ffa 100644 --- a/tslearn/metrics/_dtw.py +++ b/tslearn/metrics/_dtw.py @@ -713,7 +713,7 @@ def cdist_dtw( Above 50, the output is sent to stdout. The frequency of the messages increases with the verbosity level. If it more than 10, all iterations are reported. - `Glossary `__ + `Glossary `__ for more details. be : Backend object or string or None diff --git a/tslearn/metrics/_frechet.py b/tslearn/metrics/_frechet.py index 477ba9a7..fb4f956e 100644 --- a/tslearn/metrics/_frechet.py +++ b/tslearn/metrics/_frechet.py @@ -719,7 +719,7 @@ def cdist_frechet( Above 50, the output is sent to stdout. The frequency of the messages increases with the verbosity level. If it more than 10, all iterations are reported. - `Glossary `__ + `Glossary `__ for more details. be : Backend object or string or None diff --git a/tslearn/metrics/_gak.py b/tslearn/metrics/_gak.py index 3b104987..c5c45ca3 100644 --- a/tslearn/metrics/_gak.py +++ b/tslearn/metrics/_gak.py @@ -423,7 +423,7 @@ def cdist_gak( Above 50, the output is sent to stdout. The frequency of the messages increases with the verbosity level. If it more than 10, all iterations are reported. - `Glossary `__ + `Glossary `__ for more details. be : Backend object or string or None Backend. If `be` is an instance of the class `NumPyBackend` or the string `"numpy"`, diff --git a/tslearn/metrics/_soft_dtw.py b/tslearn/metrics/_soft_dtw.py index c35760b8..9b86b995 100644 --- a/tslearn/metrics/_soft_dtw.py +++ b/tslearn/metrics/_soft_dtw.py @@ -819,7 +819,7 @@ def cdist_soft_dtw( Above 50, the output is sent to stdout. The frequency of the messages increases with the verbosity level. If it more than 10, all iterations are reported. - `Glossary `__ + `Glossary `__ for more details. be : Backend object or string or None (default: None) @@ -1040,7 +1040,7 @@ def cdist_soft_dtw_normalized( Above 50, the output is sent to stdout. The frequency of the messages increases with the verbosity level. If it more than 10, all iterations are reported. - `Glossary `__ + `Glossary `__ for more details. be : Backend object or string or None (default: None) diff --git a/tslearn/metrics/ctw.py b/tslearn/metrics/ctw.py index 766ab0dd..d10c1c9b 100644 --- a/tslearn/metrics/ctw.py +++ b/tslearn/metrics/ctw.py @@ -364,14 +364,14 @@ def cdist_ctw( The number of jobs to run in parallel. ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context. ``-1`` means using all processors. See scikit-learn's - `Glossary `__ + `Glossary `__ for more details. verbose : int, optional (default=0) The verbosity level: if non zero, progress messages are printed. Above 50, the output is sent to stdout. The frequency of the messages increases with the verbosity level. If it more than 10, all iterations are reported. - `Glossary `__ + `Glossary `__ for more details. be : Backend object or string or None Backend. If `be` is an instance of the class `NumPyBackend` or the string `"numpy"`, diff --git a/tslearn/metrics/sax.py b/tslearn/metrics/sax.py index c1eae00f..9137f36b 100644 --- a/tslearn/metrics/sax.py +++ b/tslearn/metrics/sax.py @@ -52,7 +52,7 @@ def cdist_sax( Above 50, the output is sent to stdout. The frequency of the messages increases with the verbosity level. If it more than 10, all iterations are reported. - `Glossary `__ + `Glossary `__ for more details. Returns diff --git a/tslearn/metrics/utils.py b/tslearn/metrics/utils.py index 087ae433..3fe1cb36 100644 --- a/tslearn/metrics/utils.py +++ b/tslearn/metrics/utils.py @@ -97,7 +97,7 @@ def _cdist_generic( Above 50, the output is sent to stdout. The frequency of the messages increases with the verbosity level. If it more than 10, all iterations are reported. - `Glossary `__ + `Glossary `__ for more details. be : Backend object or string or None diff --git a/tslearn/neighbors/neighbors.py b/tslearn/neighbors/neighbors.py index 34e2e07e..b88d4fa3 100644 --- a/tslearn/neighbors/neighbors.py +++ b/tslearn/neighbors/neighbors.py @@ -485,7 +485,7 @@ class (default: 'dtw') Above 50, the output is sent to stdout. The frequency of the messages increases with the verbosity level. If it more than 10, all iterations are reported. - `Glossary `__ + `Glossary `__ for more details. Notes @@ -625,7 +625,7 @@ class (default: 'dtw') Above 50, the output is sent to stdout. The frequency of the messages increases with the verbosity level. If it more than 10, all iterations are reported. - `Glossary `__ + `Glossary `__ for more details. Examples