arXiv:2610.13129stat.MLOct 2026

Manuscript Offprint

arXiv:2610.13129

Fast Gradient-Based Approximation of Continuous Dynamic Time Warping

Pierre Houedry, Romain Tavenard, Nicolas Courty, Romaric Gaudel

Abstract

Dynamic Time Warping (DTW) is a common choice for measuring the discrepancy between time series. It proceeds by finding an optimal warping between timestamps through dynamic programming, which can be slow and is not differentiable. Consequently, several variants have been proposed. Among them, Soft-DTW proposes a smooth formulation of DTW, amenable to gradient computation, while Continuous-DTW (CDTW) introduces a continuous formulation through parametrizable warping functions. Yet, computational costs remain high for both methods and impractical for large datasets in modern machine learning pipelines. This paper revisits CDTW in several ways. After establishing its differentiability under mild conditions, we introduce FastCDTW, which is an efficient approximate solver with two different computational strategies: an exact closed-form scheme for piecewise-linear warping functions, and an unbiased Monte Carlo estimator for smooth ones, such as implicit neural networks. Both strategies provide gradients with respect to the warping function and the input time series, and the resulting algorithm is GPU-friendly. We demonstrate its benefits through its integration into more complex learning problems, including time series averaging, classification and deep domain adaptation.

1 Introduction

Measuring similarity between time series is a core building block of many machine learning pipelines, including nearest-neighbor classification (Bagnall et al., 2017), time series averaging and clustering (Petitjean et al., 2011; Cuturi and Blondel, 2017), and, more recently, domain adaptation (Painblanc et al., 2023) and representation learning for temporal data (Lods et al., 2017; Rhodes and Lee, 2024). Because real-world signals rarely share a common clock (sensors sample at different rates (Rubanova et al., 2019), the same phenomenon can unfold faster or slower across instances, sequences start and end at slightly different times), a similarity measure between time series must account for such temporal misalignments rather than compare observations index by index, as the Euclidean distance would do. Dynamic Time Warping (DTW) (Vintsyuk, 1968; Sakoe and Chiba, 1978) has become the default answer to this need: it aligns two sequences by searching, over the combinatorially many monotonic correspondences between their samples, for the one that minimizes a cumulative discrepancy. This combinatorial construction is also the source of DTW's two main limitations. First, DTW reasons about discrete index correspondences rather than about the underlying continuous phenomenon the sequences sample from, which makes it sensitive to the sampling rate and treats differently-sampled realizations of the same signal as fundamentally different objects. Second, the arg min over warping paths that defines DTW is a non-differentiable, piecewise-constant function of its inputs, which rules out the use of DTW as a training loss or as a component of a pipeline optimized by gradient descent.

These two limitations have each spawned their own line of remedies, but, as we argue below, neither has been resolved without giving up on the other. On the differentiability side, Cuturi and Blondel (2017) introduced Soft-DTW, which replaces the minimum over alignments with a soft-minimum controlled by a temperature parameter. This relaxation is genuinely differentiable and has enabled applications such as barycenter computation, clustering, and end-to-end learning with temporal alignment. The relaxation, however, is not without cost: smoothing the minimum over an exponential number of paths tends to average alignments rather than select among them, which in practice manifests as a systematic denoising effect (Blondel et al., 2021).

A separate line of work reformulates time warping directly in continuous time. Rather than an index correspondence, a warping is modeled as a pair of continuous, monotonic reparametrizations of the two signals, and the cost of the alignment is obtained by integrating, rather than summing, a local discrepancy along the corresponding curves. This continuous counterpart to DTW, referred to as Continuous DTW (CDTW) (Buchin et al., 2025), has been argued to avoid artifacts that plague DTW. Turning this appealing formulation into a usable algorithm, however, has proven difficult: existing methods either operate at a computational cost that remains impractical at the sequence lengths and iteration budgets required by machine learning pipelines, and without differentiability. Section 2 reviews these methods and their complexity in detail.

Soft-DTW and CDTW thus address complementary symptoms of the same underlying issue (respectively, the non-differentiability of DTW and its discreteness), but neither closes both gaps at once, and the continuous formulations that do exist remain, by their own authors' admission, computationally out of reach for practical use. What is missing is a similarity measure that is simultaneously (i) genuinely continuous, to avoid the sampling-rate artifacts of discrete alignments; (ii) differentiable, so that it can serve as a training loss or as a component of a larger learned pipeline and (iii) tractable at the sequence lengths and iteration counts encountered in practice.

We introduce FastCDTW which proceeds by solving the CDTW problem by gradient descent over a finite-dimensional parametrization of the warping functions rather than solving this problem to global optimality via dynamic programming. This choice trades the global-optimality guarantee enjoyed by exact CDTW solvers for tractability: computing FastCDTW costs orders of magnitude less than exact or approximate CDTW solvers, and it is naturally suited to batched GPU computation. The price to pay is that gradient descent on the resulting non-convex objective is not guaranteed to converge to the global minimum. We show throughout Section 4 and in our experiments that, despite this lack of global guarantees, the resulting approximation is accurate enough, and considerably faster, to be useful in practice.

We make the following contributions:

• Theoretical properties of CDTW (Section 3): we reduce the CDTW optimization to a single warping, show that Lipschitz warpings reach the same optimal cost, and prove the differentiability of CDTW with respect to an input curve when the warping is restricted to a parametrized family. To our knowledge, the last two results are new;

• FastCDTW, a gradient-based method to compute CDTW (Section 4): the warping is optimized by gradient descent over a finite-dimensional parametrization, and the cost is evaluated either in closed form for piecewise-linear warpings or by an unbiased Monte Carlo estimator for smooth ones. The method is GPU-friendly;

• An empirical validation on averaging, classification and domain adaptation tasks, showing that FastCDTW can be used as a replacement for DTW or Soft-DTW at a lower computational cost: it notably avoids the peak-erosion pathology of Soft-DTW barycenters, and runs up to 50×50\times faster than DTW when plugged into a domain adaptation pipeline.

References (31)