---
title: Randomized Time Warping (RTW)
url: https://www.emergentmind.com/topics/randomized-time-warping-rtw
type: topic
---

# Randomized Time Warping (RTW)

Randomized Time Warping (RTW) denotes a set of sequence-analysis methods that preserve the elastic-alignment motivation of Dynamic Time Warping (DTW) while replacing exhaustive path-based comparison with randomized constructions. In current arXiv usage, the term most directly refers to a general extension of DTW for sequence comparison and recognition that uses randomized, order-preserving sampling of subsequences, PCA-derived “hypo subspaces,” and canonical-angle similarity, with an interpretation as an attention mechanism in motion recognition [2508.16366]. A separate established usage realizes RTW through Random Warping Series (RWS), where each time series is aligned to short random warping series to obtain an explicit alignment-aware random-features embedding and a positive definite kernel [1809.05259]. Across these formulations, randomness enters through sampled subsequences or sampled warping series rather than through a single deterministic optimal path.

## 1. Terminology and scope

The expression “Randomized Time Warping” is not attached to a single universally adopted formalism. At least two technical lineages are documented in the recent literature.

| Formulation | Core mechanism | Representative source |
|---|---|---|
| Randomized Time Warping for motion recognition | Randomized, order-preserving sampling of subsequences; PCA hypo subspaces; canonical angles; attention interpretation | [2508.16366] |
| Randomized Time Warping via Random Warping Series | Alignment to short random series; explicit feature map; positive definite kernel; Monte Carlo random features | [1809.05259] |
| RTW as acronym for a different concept | Riemannian manifold-aware multiple sequence alignment | [2506.01635] |

This terminological plurality matters because the acronym RTW is not semantically unique. In “Riemannian Time Warping: Multiple Sequence Alignment in Curved Spaces,” RTW stands for Riemannian Time Warping, not randomized time warping [2506.01635]. Two additional neighboring lines of work further widen the conceptual field: one studies estimation from randomly time-warped observations without naming a method RTW [2112.01464], and another develops a stochastic process model for time warping functions that can be used to generate random warpings in a principled way [2201.09970].

A common source of confusion is therefore the assumption that RTW always denotes one algorithmic pipeline. The literature instead supports a narrower and more precise statement: RTW refers either to a randomized DTW extension built from sampled subsequences and subspace geometry [2508.16366], or to an alignment-aware random-features construction built from random warping series [1809.05259], while other papers use the same acronym for unrelated manifold-based alignment [2506.01635].

## 2. DTW as the baseline that RTW generalizes or bypasses

Classical DTW aligns two sequences \(X=(x_1,\dots,x_{T_X})\) and \(Y=(y_1,\dots,y_{T_Y})\) by finding an admissible alignment path \(P\) from \((1,1)\) to \((T_X,T_Y)\) that minimizes accumulated local dissimilarity:
\[
\mathrm{DTW}(X,Y)=\min_{P\in\Pi}\sum_{(i,j)\in P} d(x_i,y_j).
\]
The admissible paths satisfy boundary conditions, monotonicity, and continuity, and the standard dynamic-programming solution operates on a \(T_X\times T_Y\) cost matrix with typical time and space complexity \(O(T_X\cdot T_Y)\), often written as \(O(T^2)\) when the two lengths are comparable [2508.16366].

The same baseline appears in the RWS literature in a slightly different notation. For time series \(x=(x_1,\dots,x_n)\) and \(y=(y_1,\dots,y_m)\), DTW is written as
\[
\mathrm{DTW}(x,y)=\min_{\pi\in\mathcal{A}(x,y)}\sum_{(i,j)\in\pi} d(x_i,y_j),
\]
with the dynamic-programming recurrence
\[
D(i,j)=d(x_i,y_j)+\min\{D(i-1,j),D(i,j-1),D(i-1,j-1)\},
\]
plus standard boundary initialization and, optionally, a Sakoe–Chiba warping window \(|i-j|\le w\) [1809.05259].

The technical motivation for RTW follows from the computational and statistical limitations of DTW and its kernelized descendants. In the RWS account, DTW-inspired global-alignment kernels suffer from diagonal dominance of the Gram matrix and quadratic complexity with respect to the sample size, since evaluating all pairwise kernel values requires \(O(N^2)\) dynamic-programming runs, each with \(O(L^2)\) cost in the unwindowed case, for a total of \(O(N^2L^2)\) time [1809.05259]. In the motion-recognition account, DTW’s single optimal path is replaced by randomized sampling of many order-preserving subsequences, and the computational focus shifts from path search to subspace estimation and canonical-angle comparison [2508.16366].

This suggests a unifying interpretation: RTW methods keep temporal elasticity as the central modeling objective, but they randomize the representation of possible warpings so that the algorithm need not commit to one explicit global path.

## 3. Randomized Time Warping as randomized subsequence sampling and subspace matching

In the motion-recognition formulation, RTW is a general extension of DTW that forgoes a single optimal warping path and instead represents many possible time-warped patterns through randomized, order-preserving sampling of subsequences called Time Elastic (TE) features [2508.16366]. The input is a sequence of \(N\) deep feature vectors \(\{z_i\}_{i=1}^N\), with \(z_i\in\mathbb{R}^{d_{\text{model}}}\).

A TE feature is formed by sampling \(R\) indices \(1\le t_1<\cdots<t_R\le N\) and concatenating the corresponding frame features:
\[
f\in\mathbb{R}^{d_{\text{te}}},\qquad d_{\text{te}}=d_{\text{model}}\times R,
\]
\[
f=[z_{t_1};z_{t_2};\dots;z_{t_R}].
\]
Repeating the randomized, order-preserving sampling \(L\) times yields a set \(\{f_i\}_{i=1}^L\subset\mathbb{R}^{d_{\text{te}}}\), and an analogous set \(\{g_i\}_{i=1}^L\) is built for a reference sequence [2508.16366]. The stated effect is to induce a diverse collection of time-elastic patterns covering local to global scales, thereby approximating multiple warping possibilities that DTW would otherwise consider through path search.

The TE feature sets are then compressed into low-dimensional hypo subspaces by PCA. Writing
\[
F=[f_1,\dots,f_L]\in\mathbb{R}^{d_{\text{te}}\times L},\qquad
G=[g_1,\dots,g_L]\in\mathbb{R}^{d_{\text{te}}\times L},
\]
the orthonormal basis matrices \(X\in\mathbb{R}^{d_{\text{te}}\times m_x}\) and \(Y\in\mathbb{R}^{d_{\text{te}}\times m_y}\) are taken as the eigenvectors corresponding to the \(m\) largest eigenvalues of \(FF^\top\) and \(GG^\top\), respectively [2508.16366]. Structural similarity between the two subspaces is then measured with the Mutual Subspace Method (MSM): if
\[
X^\top Y = U\Sigma V^\top,
\]
and \(\kappa_i=\cos(\theta_i)\) are the singular values associated with the canonical angles \(\theta_i\), RTW defines
\[
\mathrm{Sim}(\mathcal{S}_1,\mathcal{S}_2)=\frac{1}{r}\sum_{i=1}^{r}\kappa_i^2,\qquad 1\le r\le m_x.
\]

The classification pipeline is explicitly two-stage. In the learning stage, each training video of class \(c\) is converted into TE features by repeated random order-preserving frame sampling and deep feature concatenation; PCA is applied to obtain a reference hypo subspace; and this process is repeated across the \(n_c\) training videos of the class to obtain \(\{S_c^i\}_{i=1}^{n_c}\). In the inference stage, the input video is processed by the same TE sampling procedure, PCA yields an input subspace \(S_{\text{in}}\), MSM similarities are computed against the class-specific reference subspaces, and classification is performed by \(k\)-nearest neighbors using the average of the top-\(k\) similarities within each class [2508.16366].

The complexity profile differs sharply from DTW. TE generation requires \(O(L\cdot R\cdot d_{\text{model}})\), PCA on \(FF^\top\) and \(GG^\top\) can dominate when \(d_{\text{te}}\) and \(L\) are large, and the MSM step itself is relatively light when the chosen subspace dimensions \(m_x,m_y\) are small [2508.16366]. The paper explicitly contrasts this with DTW’s \(O(N^2)\) path-search cost and with Transformer self-attention’s \(O(N^2)\) time and memory for the attention matrix.

## 4. Contribution weights, attention interpretation, and motion-recognition evidence

A distinctive claim of the 2025 formulation is that RTW’s core computational mechanism can be interpreted as a type of self-attention [2508.16366]. The derivation begins with explicit contribution weights connecting TE features, PCA, and canonical-angle computation back to per-time-step importance.

If \(w_{ik}\) denotes the contribution of the \(i\)-th TE feature to the \(k\)-th canonical vector \(u_k\), the paper gives
\[
w_{ik}=\sum_{m=1}^{m_x}\alpha_{mk}\beta_{im},
\]
where \(\alpha\) and \(\beta\) are the linear-combination coefficients arising from PCA and MSM. If \(\hat{w}_{ji}\) denotes the contribution weight of the \(j\)-th input element \(z_j\) to the \(i\)-th TE feature \(f_i\), then
\[
\hat{w}_{ji}=\frac{\mathrm{appearance}(z_j\in f_i)}{c_j},
\]
where \(\mathrm{appearance}(z_j\in f_i)\in\{0,1\}\) and \(c_j\) is the total number of sampled TE features that include \(z_j\). The contribution of \(z_j\) to the \(k\)-th canonical vector is then
\[
t_j=\sum_{i=1}^{L}\hat{w}_{ji}w_{ik},
\]
and the normalized RTW attention pattern is
\[
\mathbf{T}_k=\frac{\mathbf{t}^*}{\|\mathbf{t}^*\|},
\]
with \(\mathbf{t}^*=[t_1,\dots,t_N]\) [2508.16366].

This construction is compared to Transformer self-attention, where
\[
Q=XW_Q,\qquad K=XW_K,\qquad V=XW_V,
\]
and
\[
\mathrm{Att}(X)=\mathrm{softmax}\!\left(\frac{QK^\top}{\sqrt{d_k}}\right)V.
\]
The paper aggregates attention toward each element \(j\) as \(s_j=\sum_{i=1}^N A_{ij}\). The stated analogy is that each RTW pattern \(\mathbf{T}_k\) is a global weighting over the entire sequence, while the set \(\{\mathbf{T}_k\}_{k=1}^K\) parallels \(K\) attention heads [2508.16366]. The key distinction is operational rather than superficial: RTW attention is computed over the entire input sequence through TE sampling and subspace analysis, whereas practical video Transformers often restrict attention to local or windowed views because naive self-attention requires an \(N\times N\) matrix.

On Something-Something V2, the empirical alignment between RTW and Transformer attention patterns is reported through cosine-similarity-based pairing of RTW canonical-angle patterns and Transformer heads. Averaged across 174 classes, the per-pair correlations are described as high, including values such as \(0.85, 0.85, 0.84, 0.84,\dots,0.68\), with overall average approximately \(0.80\) across the ten smallest canonical angles [2508.16366].

The same study reports a classification advantage for RTW over a ViViT-style Transformer baseline on SSv2. The dataset comprises 193k training and 27k test videos across 174 classes, with sequences averaging 40 frames, maximum 119, and standard deviation 10 [2508.16366]. The Transformer baseline uses a two-stage design with a ViT pre-trained on ImageNet-21k for spatial features and a temporal Transformer with 10 heads operating on 16-frame views. RTW uses the same spatial features, 10 canonical angles, and TE features built from 16-frame clips.

| Method | Data fraction | Accuracy (%) |
|---|---:|---:|
| Transformer (ViViT-like) | Full | 46.84 |
| Transformer (ViViT-like) | 1/5 | 47.53 |
| Transformer (ViViT-like) | 1/10 | 45.63 |
| RTW \(r_c=1\) | Full | 51.06 |
| RTW \(r_c=1\) | 1/5 | 48.29 |
| RTW \(r_c=1\) | 1/10 | 46.74 |
| RTW \(r_c=2\) | Full | 51.18 |
| RTW \(r_c=2\) | 1/5 | 48.90 |
| RTW \(r_c=2\) | 1/10 | 47.30 |
| RTW \(r_c=3\) | Full | 51.34 |
| RTW \(r_c=3\) | 1/5 | 49.00 |
| RTW \(r_c=3\) | 1/10 | 47.65 |
| RTW \(r_c=5\) | Full | 51.11 |
| RTW \(r_c=5\) | 1/5 | 49.10 |
| RTW \(r_c=5\) | 1/10 | 47.82 |

The reported full-data comparison yields about a 5% absolute improvement for RTW over the Transformer baseline, for example \(51.34\%\) versus \(46.84\%\) [2508.16366]. The same source states that RTW trained on only 10% of the dataset, at \(47.82\%\), approaches the Transformer’s full-data performance of \(46.84\%\). Another common misconception is therefore directly addressed by the paper’s formulation: RTW does not “learn” its attention weights through gradient-based optimization; the weights are induced analytically by randomized sampling, PCA, and SVD [2508.16366].

## 5. Random Warping Series: RTW as an alignment-aware random-features method

A distinct and earlier formulation of Randomized Time Warping is given by the Random Warping Series framework [1809.05259]. Here the central object is not a hypo-subspace representation but an explicit feature map built by aligning each time series to a collection of short random series \(\omega\).

The kernel is defined as
\[
k(x,y)=\int_{\omega} p(\omega)\,\phi_\omega(x)\phi_\omega(y)\,d\omega,
\]
with feature map
\[
\phi_\omega(x):=\sum_{a\in\mathcal{A}(\omega,x)} p(a\mid \omega)\,\tau(\omega,x;a).
\]
A crucial choice is the “hard alignment” distribution that places all mass on the optimal alignment:
\[
p(a\mid\omega)=
\begin{cases}
1,& a^*=\arg\min_a \tau(\omega,x;a),\\
0,& \text{otherwise}.
\end{cases}
\]
The same feature can be written using alignment operators \((A,B)\in\mathcal{A}(\omega,x)\) as
\[
\phi_\omega(x):=\min_{(A,B)\in\mathcal{A}(\omega,x)} \tau(A\omega,Bx)
=\sum_{i=1}^{l}\tau([A\omega]_i,[Bx]_i),
\]
where \(\tau\) is a ground dissimilarity such as \(\ell_2\) or squared \(\ell_2\) applied per aligned pair [1809.05259].

Monte Carlo approximation then produces an explicit \(R\)-dimensional embedding:
\[
T_r(x)=\frac{\phi_{\omega_r}(x)}{\sqrt{R}},\qquad
\langle T(x),T(y)\rangle=\frac{1}{R}\sum_{r=1}^{R}\phi_{\omega_r}(x)\phi_{\omega_r}(y)=:s_R(x,y),
\]
with \(\mathbb{E}[s_R(x,y)]=k(x,y)\) [1809.05259]. The sampled random series follow a specified distribution: the length \(D\) is drawn uniformly on \([D_{\min},D_{\max}]\), commonly with \(D_{\min}=1\) and \(D_{\max}\in\{10,\dots,100\}\); the values are i.i.d. Gaussian with zero mean and variance \(\sigma^2\); and a Sakoe–Chiba band such as \(\min(L/10,40)\) can be used to constrain the DTW alignment [1809.05259].

The theoretical claims are twofold. First, positive definiteness follows directly from the outer-product construction:
\[
\sum_{i,j} c_i c_j k(x_i,x_j)
=\int_{\omega} p(\omega)\Big[\sum_i c_i\phi_\omega(x_i)\Big]^2 d\omega \ge 0.
\]
Second, the paper proves a uniform-convergence result for the random-features approximation on domains of time series of unbounded length, expressed in terms of a Minimum Shape-Preserving Length \(d_\epsilon\) and a sufficient number of features
\[
R=\Omega\!\left(\frac{d_\epsilon\gamma^4}{\epsilon^2}
\log\!\frac{\gamma r \sigma_\tau}{\delta\epsilon}\right),
\]
with the bounded-length case giving \(R=\Omega(L/\epsilon^2)\) [1809.05259].

The computational advantage is explicit. DTW between a series of length \(L\) and a short random series of length \(D\) costs \(O(LD)\), which behaves as \(O(L)\) when \(D\) is small or sampled from a small range. For \(R\) random series and \(N\) samples, the total cost is \(O(NRL)\) time and \(O(NR)\) memory, in contrast to the \(O(N^2L^2)\) time and \(O(NL+N^2)\) memory of DTW-based global-alignment kernels [1809.05259]. The paper also argues that the hard-min construction avoids diagonal dominance because the feature \(\phi_\omega(x)\) depends on the single optimal alignment rather than a soft sum over exponentially many paths.

Empirically, the RWS study reports experiments on 16 UCR benchmark datasets for classification and clustering. Concrete examples include Two_Patterns, where RWS(SR) achieves \(0.999\)–\(1.000\) accuracy in \(4.4\)–\(16.1\) seconds versus \(157.5\)–\(222.2\) seconds for 1NN-DTW, and Wafer, where RWS(SR) achieves \(0.993\) in \(9.6\) seconds versus \(0.986\) in \(412.3\) seconds for 1NN-DTW [1809.05259]. Against TGAK, the reported contrasts are stronger: on Wafer, RWS(SR) obtains \(0.993\) in \(9.6\) seconds versus \(0.896\) in \(11172\) seconds for TGAK; on MALLAT, the comparison is \(0.937\) in \(33.8\) seconds versus \(0.257\) in \(11882\) seconds [1809.05259]. The paper’s practical guidance recommends \(R\in[32,64]\), \(D_{\min}=1\), \(D_{\max}\in[10,40]\), \(\sigma\approx 1\), and a modest Sakoe–Chiba window.

## 6. Related stochastic models, adjacent formulations, and naming ambiguities

Several nearby papers study random time warpings without using the exact RTW formalism of either subsequence/subspace RTW or RWS. These works are useful for delimiting what Randomized Time Warping is and is not.

“Time-Series Estimation from Randomly Time-Warped Observations” considers the observation model
\[
y_k(t)=f(g_k(t))+n_k(t),
\]
with random warpings \(g_k\) that are close to identity, for example \(g_k(t)=t+u_k(t)\) where \(u_k\) is drawn from a zero-mean stationary Gaussian process [2112.01464]. The paper’s proposed estimator does not use DTW; instead it constructs a sparse graph Laplacian over observed signals, repeatedly solves discrete Dirichlet problems with random boundary seeds, defines centrality by inverse temperature variance, and estimates the template by averaging the most central observations. It further shows that naive ensemble averaging converges to a blurred version \((f*q)(t)\), which motivates selecting near-unwarped observations rather than averaging all warped ones [2112.01464]. The paper explicitly states that it does not use “RTW” as a named method; RTW there refers only to the generative setting of random time warpings.

“A Stochastic Process Model for Time Warping Functions” also does not explicitly discuss Randomized Time Warping by name, but it supplies a mathematically rigorous way to generate random warpings [2201.09970]. The key construction maps a warping function \(\gamma\) to the centered logratio transform of its derivative,
\[
h(t)=\log(\dot{\gamma}(t))-\int_0^1 \log(\dot{\gamma}(s))\,ds,
\]
which places the problem in a zero-mean \(\mathbb{L}^2\) Hilbert subspace. Sampling a finite stochastic expansion
\[
X_m(t)=\sum_{i=1}^{m} G_i\phi_i(t)
\]
then induces a valid random warping through
\[
\gamma_m(t)=\frac{\int_0^t \exp(X_m(s))\,ds}{\int_0^1 \exp(X_m(\tau))\,d\tau}.
\]
The paper presents this as a generative model for warping functions in \(\Gamma_1\), supports functional PCA, ANOVA, and regression in the transformed space, and develops a Bayesian registration method with efficient gradient-based MAP estimation [2201.09970]. A plausible implication is that this framework can serve as a principled prior or generator for RTW-style randomization, although the paper itself does not define such an algorithm.

Finally, the overloaded acronym RTW must be distinguished from “Riemannian Time Warping: Multiple Sequence Alignment in Curved Spaces,” where RTW denotes a manifold-aware method for multiple sequence alignment on Riemannian manifolds [2506.01635]. That method performs windowed sinc interpolation in tangent spaces, computes a Karcher mean trajectory by Gauss–Newton, and optimizes monotone warpings with a Gaussian-windowed geodesic loss and monotonicity penalty. It is therefore related to time warping at the problem level, but not to randomized time warping in the sense of sampled subsequences or random warping series.

Taken together, these papers delimit the encyclopedia meaning of Randomized Time Warping. In the strictest sense, RTW refers to randomized constructions that replace or approximate explicit alignment search, either through TE-feature sampling and canonical-angle subspace comparison in video recognition [2508.16366] or through random-warping-series feature maps and positive definite kernels in time-series embedding [1809.05259]. In a broader sense, the adjacent literature on random warp generative models and randomly time-warped observations provides the probabilistic and inferential background against which those RTW methods can be understood [2112.01464] [2201.09970].

Source: https://www.emergentmind.com/topics/randomized-time-warping-rtw