Dynamic time warping (DTW) lines up two time series that show the same events at different speeds. It stretches and compresses the time axis so that peaks match peaks, and it scores each candidate alignment by adding up point-by-point mismatches. That scoring rule has a flaw when one signal carries slow, serially correlated error, such as sensor baseline drift or a batch-level offset that wanders over a run. DTW then treats the drift as real signal and bends the time axis to explain it. Separately, the literature on autoregressive error modeling shows how to learn this kind of correlated error inside a model's loss. Those methods measure correlation between consecutive clock ticks, so they break when the two series advance at different rates. We propose to fix both problems at once. The mismatch along the warping path is modeled as a first-order autoregressive process, meaning each mismatch is partly predicted by the one before it. Its correlation coefficient is learned jointly with the alignment.
The technical core is small but, as far as the literature here shows, new. The penalty for each step of the alignment can be defined as the part of the current mismatch that the previous mismatch does not predict. This penalty depends only on the current cell and its predecessor, so ordinary DTW dynamic programming still finds the exact optimal path at the usual cost. Setting the correlation coefficient to zero recovers classic DTW. Setting it to one recovers alignment of first differences. Learning it lets the data choose. We test the method where drift is physically real and alignment matters: raw nanopore current signals and time-course single-cell expression. We also package the residual diagnostic as a check that non-specialist users can run without tuning.
Core Claim
Consider a query series $a_1,\dots,a_N$ (for example, a noisy measured current), a reference $b_1,\dots,b_M$ (the expected signal), and a warping path $W=(w_1,\dots,w_K)$ with $w_k=(i_k,j_k)$. Define the mismatch along the path as $e_k = a_{i_k} - b_{j_k}$. We score the path by
$$C(W,\rho) = \sum_{k=2}^{K} \left( e_k - \rho^{\Delta_k} e_{k-1} \right)^2,$$
where $\rho \in (-1,1)$ is the correlation of consecutive mismatches and $\Delta_k = i_k - i_{k-1} \in \{0,1\}$ is how far the query's own sampling clock advanced on that step. Correlation is counted in the clock where drift actually lives, which is the sensor's, and not in the reference index. This is the discrete, warped analogue of the gap formula $\epsilon_{w_k} = \rho^{\Delta\tau_k}\epsilon_{w_{k-1}} + \eta_{w_k}$ sketched in the research file's first gap. Here $\eta$ is the unpredictable part of the error.
Each term depends only on $w_{k-1}$ and $w_k$. The recursion is therefore an edge-weighted version of the standard one: the cumulative cost at cell $(i,j)$ is the minimum over its three predecessors of their cumulative cost plus the edge penalty. The solution is exact and costs $O(NM)$. For a fixed path, $\rho$ has a closed-form least-squares update. Alternating between the two steps is coordinate descent on a single objective. It cannot increase $C$, and we use it with several restarts over initial $\rho$ values.
The claim is empirical. When drift is present, the jointly estimated alignment recovers true timing better than classic DTW. It also beats any fixed preprocessing (detrending, per-series prewhitening, differencing), because those remove correlation before knowing which part of the signal is biology. When drift is absent, the method learns $\rho \approx 0$ and costs nothing.
Why this is a real gap and not a relabeling
The motivating evidence comes from two lines of work that each assume away the other's problem. Adjusting for Autocorrelated Errors in Neural Networks for Time Series learns $\rho$ through a tanh transform jointly with network weights. It trains on filtered targets $X_t - \rho X_{t-1}$ and reports relative gains up to 32.4% on LSTMs, but its lag is a fixed index step. Multivariate Probabilistic Time Series Forecasting with Correlated Errors extends this to a generalized-least-squares loss with temporal kernels, again on a rigid grid, using $|t-s|$ as the temporal distance. We reuse their central move of learning error correlation inside the objective rather than as an afterthought. We move it from clock time into warped time.
On the alignment side, cwDTW makes DTW practical for nanopore reads through wavelet multiscale features and coarse-to-fine search bands. It assumes that differences between observed and expected current are independent local noise. DTWscore uses pairwise DTW distances to find dynamically expressed genes in unsynchronized single-cell time courses, and it too ignores serial technical noise. We keep cwDTW's banding as the scaffolding for long reads and change only the edge cost.
The nearest competitor in spirit is Pseudotime estimation: deconfounding single cell time series. It places cells on a latent Gaussian-process time anchored to capture time, with independent Gaussian residuals. Adding a correlated noise kernel along pseudotime would be a continuous cousin of our model, so we treat it as a baseline rather than dismissing it. PACE addresses asynchrony through geometry-aware transport of cell distributions. It aligns population distributions rather than individual sequences, so it constrains the scope of our single-cell claims more than it competes with them.
Research Program
The first component is the algorithm and its long-sequence implementation. We will implement the exact edge-cost DP and the alternating $\rho$ update. We will then embed the edge cost inside cwDTW's coarse-to-fine bands, so reads of 120k bases stay near linear time. Two extensions follow. One is a per-segment $\rho$, because nanopore drift is not stationary across a read; this uses a small number of change points selected by held-out mismatch likelihood. The other is a smooth, differentiable variant that replaces the minimum with a soft-minimum, for use as a loss inside neural models. The second extension is only pursued if the first set of experiments succeeds.
The second component is identifiability analysis. There is a real risk of trading warping for correlation: a large $\rho$ can absorb a genuine timing error, much as unconstrained DTW absorbs drift. We will characterize this tradeoff on synthetic data with known warps and known drift. We will also test whether a mild prior shrinking $\rho$ toward zero, or a band constraint, is needed. If identifiability fails badly in realistic regimes, that negative result is itself the finding.
The third component is the diagnostic, which carries the accessibility direction. Tools like CellAgent automate static single-cell analysis but have no primitive for checking temporal alignment. InTimeAD argues that per-series inspection beats aggregate scores for non-experts. We will ship a module callable from Python and from an agent tool list. After classic DTW, it reports the lag-1 correlation of mismatches along the path. It switches to drift-aware alignment when that correlation exceeds a threshold, and it produces a plot of the warp before and after correction. The threshold will be calibrated on our data. We will check whether the correlation-to-gain relationship reported by Sun et al. transfers to warped residuals: a 90% chance of improvement above 0.857 and 99% above 0.984. We make no claim about user studies. The accessibility claim is limited to showing that a tuning-free rule picks the better method.
Baselines
The naive reference is classic DTW with squared pointwise cost, run with the same band constraints as our method. This is exactly our method with $\rho$ fixed to zero, so the comparison isolates the correlated-error term.
The strongest existing method for long nanopore reads is cwDTW. It reports producing the exact optimal DTW path on 86.4% of human reads (HM4530), at 0.31 seconds per long read, compared with nearly an hour for plain DTW (cwDTW). That number measures agreement with the classic DTW optimum, not agreement with the true timing. Under drift, the classic optimum is exactly what we claim is wrong, so we will report both agreement with ground-truth timing on semi-synthetic reads and runtime. We will run cwDTW's released code and our banded variant on the same reads, hardware and band widths. Beating it means lower timing error on drifted reads, no worse error on undrifted ones, and runtime within a small constant factor.
For the single-cell setting, the strongest reported result is DTWscore's AUC of 0.880, 0.907 and 0.814 for identifying heterogeneous genes on its synthetic sets (DTWscore). We will regenerate those synthetic conditions, add controlled correlated technical noise, and compare DTWscore with its DTW call replaced by ours. Everything else stays fixed, including the 4-standard-deviation mixture-model threshold. Beating it means a higher AUC under injected drift and a matched AUC without it.
The continuous competitor is Gaussian-process pseudotime (Pseudotime estimation) with an added exponentially decaying noise kernel along pseudotime. It gets the same inference budget, and its outputs will be mapped to per-gene alignments. Its reported Spearman correlation of .996 with withheld capture time on Arabidopsis sets a ceiling on that dataset, so we will not use it to claim gains there.
The ablations cover the rest of the design. One fixes $\rho = 1$, which is alignment of first differences. Another fixes $\rho$ to a value estimated once from raw series. A third learns $\rho$ with index lags that ignore the warp ($\Delta_k \equiv 1$). Together they isolate learning, warp-aware lags, and joint estimation.
Why not just…?
Why not just prewhiten or detrend each series first and then run ordinary DTW? This is the most serious threat, and it can be settled directly. Our argument is that the biological or k-mer signal is itself smooth and serially correlated. An autoregressive filter or a high-pass detrend fitted to the raw series therefore removes signal along with drift, and it flattens exactly the peaks that alignment needs. Only the mismatch relative to the reference isolates the drift, and that mismatch requires the alignment. We will run per-series prewhitening, polynomial and moving-median detrending, and high-pass filtering at a tuned cutoff, all with the same tuning budget as our $\rho$ search. We will compare them on semi-synthetic data with realistic drift. If a tuned detrend matches our timing error, the contribution shrinks to the diagnostic, and we will say so.
Why not just align first differences, which is already a standard trick against baseline offsets? Aligning first differences is our method with $\rho=1$. It removes random-walk drift but doubles the variance of white noise. It also discards level information, which nanopore event calling depends on. The $\rho=1$ ablation measures this directly across drift strengths. We expect it to win only when drift dominates, and our method to track whichever end of the range fits the data.
Why not just tighten the warping band so pathological stretches cannot happen? A narrow band limits how far a warp can go, not where inside the band it goes. Drift can still pull the path to the wrong side of the band. Every method, including ours, runs at the same band widths, and we sweep the width. If narrow bands alone close the gap, it will show up in that sweep.
Why not just use a Gaussian-process pseudotime model with a correlated noise kernel? For single-cell data this is a plausible equal, and we include it as a baseline rather than arguing it away. Its practical limits are cubic cost in the number of observations and the fact that it infers a per-cell latent time rather than aligning whole sequences. That makes it unusable at nanopore scale, where the drift problem is sharpest. If it matches us on single-cell data, our single-cell claim narrows to speed and simplicity.
Proposed Experiments
The semi-synthetic nanopore benchmark is the main test because it has ground truth. We simulate current from reference sequences with known per-k-mer dwell times, which gives a true warp. We then add drift traces extracted from real HM4530 and PP4782 reads by isolating each read's low-frequency component, scaled over a grid of strengths. Metrics are the mean absolute error of the recovered path against the true dwell boundaries, the fraction of k-mer events assigned to the correct segment, runtime, and the learned $\rho$.
On real reads, where ground truth is missing, we report two things. One is how whiteness of the mismatches along the path changes. The other is agreement between our alignment and cwDTW, split by the diagnostic's correlation score. The expectation is that disagreement concentrates in high-correlation reads.
The single-cell benchmark reuses the DTWscore synthetic protocol with and without injected correlated noise, plus the Human Skeletal Muscle Myoblast time course. On the myoblast data we check whether the separating marker genes and their ranking survive once correlated error is modeled. For the diagnostic, we measure how often the threshold rule chooses the method with the lower ground-truth error on the semi-synthetic data, and compare the calibrated thresholds with the values reported by Sun et al.
Three outcomes would decide the question. First, with zero injected drift, the learned $\rho$ must fall near zero and the timing error must match classic DTW; a failure here means the method invents correlation. Second, at moderate drift, our method must beat the best tuned detrend-then-DTW baseline on timing error; a failure here means joint estimation is unnecessary. Third, the identifiability sweep must show a regime of realistic drift and warp strength where both $\rho$ and the path are recovered. If all three hold, the result is an alignment tool that stops bending time to explain sensor drift. It comes with a one-number check that users can run without understanding the model.
References
- Adjusting for Autocorrelated Errors in Neural Networks for Time Series
- Multivariate Probabilistic Time Series Forecasting with Correlated Errors
- An accurate and rapid continuous wavelet dynamic time warping algorithm for unbalanced global mapping in nanopore sequencing
- DTWscore: differential expression and cell clustering analysis for time-series single-cell RNA-seq data
- Pseudotime estimation: deconfounding single cell time series
- PACE: Geometry-Aware Bridge Transport for Single-Cell Trajectory Inference
- CellAgent: LLM-Driven Multi-Agent Framework for Natural Language-Based Single-Cell Analysis
- InTimeAD: Interactive Time Series Anomaly Detection