---
title: DTW-Certified Robust Defense
url: https://www.emergentmind.com/topics/dtw-certified-robust-defense
type: topic
---

# DTW-Certified Robust Defense

Searching arXiv for the specified paper and closely related certification work.
DTW-certified robust defense denotes a certified robustness framework for time-series anomaly detection in which robustness guarantees are stated in terms of Dynamic Time Warping (DTW) rather than only in an $\ell_p$ norm. In the formulation introduced by "Fortifying Time Series: DTW-Certified Robust Anomaly Detection" [2605.07690], the objective is to guarantee that, for all perturbed inputs within a DTW radius $\varepsilon$, the anomaly detector’s anomaly/benign decision remains unchanged with high probability. The framework is motivated by the mismatch between indexwise $\ell_p$ distances and the temporal alignment structure of time series, and it adapts randomized smoothing by first obtaining an $\ell_2$ certificate for a smoothed anomaly score and then converting that certificate into a DTW certificate through a lower-bound argument based on the Keogh lower bound. In methodological terms, it belongs to a broader line of research that extends randomized smoothing to non-additive metrics by introducing a metric-specific bridge to a normed certificate space, as also exemplified by Wasserstein smoothing in image classification [1910.10783].

## 1. Definition and problem setting

The setting is time-series anomaly detection on
\[
\mathcal{X}=\mathbb{R}^{L\times C},
\]
where $L$ is sequence length and $C$ is the number of channels. The detector operates on windows of size $T\le L$ and assigns a real-valued anomaly score $f(x)\in\mathbb{R}$. The binary decision rule is
\[
d(x)=
\begin{cases}
1, & f(x)>\gamma,\\
0, & f(x)\le \gamma,
\end{cases}
\tag{1}
\]
where $1$ denotes anomaly and $0$ denotes benign [2605.07690].

The central robustness requirement is pointwise and worst-case: the detector should certify that no perturbation within a prescribed radius can flip the anomaly decision. In the threat model considered, the adversary is white-box, has full access to the detector, and has unlimited computation. Given an input $x$, the attacker seeks $x'$ such that
\[
d(x')\ne d(x)
\]
subject to the budget
\[
DTW(x,x')\le \varepsilon.
\]
This covers both evasion attacks, which hide a true anomaly, and availability attacks, which cause a benign signal to be flagged as anomalous [2605.07690].

The motivation is explicitly safety-critical. The cited application domains include healthcare, finance, and infrastructure monitoring, where anomaly detectors may trigger alarms, initiate interventions, or prevent failures. Under that interpretation, robustness is not treated as an average-case performance attribute but as a requirement for provable trust under worst-case perturbations [2605.07690].

## 2. Why DTW is the relevant robustness metric

Standard $\ell_p$ threat models are treated as inadequate for time-series data because they compare signals index-by-index and therefore ignore temporal alignment. The paper states the conventional distance as
\[
\|x-x'\|_p=\left(\sum_{i=1}^{T}|x_i-x'_i|^p\right)^{1/p}.
\tag{2}
\]
This geometry is poorly matched to temporal distortions such as small temporal shifts, local delay, stretching or compression, and rescaling in time, all of which can preserve semantic identity while producing a large $\ell_p$ discrepancy [2605.07690].

DTW is introduced as the more appropriate similarity and attack metric because it explicitly permits elastic temporal alignment. The DTW distance of norm order $p$ is defined as
\[
DTW_p(x,x')=\min_{\pi\in\mathcal{A}(x,x')}\left(\sum_{(i,j)\in\pi}\|x_i-x'_j\|^p\right)^{1/p},
\tag{3}
\]
where $\pi$ is an admissible alignment path and $\mathcal{A}(x,x')$ is the set of all such paths. The path satisfies matched ends, monotonicity and continuity, and the requirement that each time index appears at least once. In the main text, the construction uses $p=2$ [2605.07690].

Under this definition, DTW better captures phase shifts, temporal stretching, compression, and local misalignment. The paper therefore argues that previous certified defenses for time-series anomaly detection that simply import $\ell_p$ smoothing certify the wrong geometry. A model can be certified in an $\ell_p$ ball and still remain vulnerable to natural or adversarial temporal distortions. The explicit novelty claim is the introduction of the first certified defense for time-series anomaly detection under the DTW distance and, more specifically, the first theoretical framework that provides certified robustness in DTW distance for this problem [2605.07690].

A plausible implication is that the notion of robustness becomes application-aligned only when the attack metric respects temporal equivalence classes induced by alignment, rather than only raw samplewise deviations.

## 3. Smoothed anomaly scoring and the $\ell_2$ certificate

The defense pipeline begins with an arbitrary anomaly detector with score function $f$, then constructs a smoothed anomaly score function $h_p$ using Gaussian randomized smoothing, computes an $\ell_2$-type certified radius for the smoothed detector using percentile smoothing, and finally converts that $\ell_2$ certificate into a DTW certified radius [2605.07690].

Ordinary smoothing is described as insufficient because the anomaly score is a real-valued scalar and can be unbounded, high variance, and unstable under noise. The adopted alternative is percentile smoothing. With Gaussian noise
\[
\eta\sim\mathcal{N}(0,\sigma^2 I),
\]
the percentile-smoothed anomaly score is
\[
h_p(x)=\sup\left\{u\in\mathbb{R}\mid \mathbb{P}_{\eta\sim \mathcal{N}(0,\sigma^2 I)}[f(x+\eta)\le u]\le p \right\}.
\tag{4}
\]
For $p=0.5$, this behaves as a median-like smoothing rule. The smoothed detector uses $h_p(x)$ in place of $f(x)$ and retains the threshold $\gamma$ [2605.07690].

The paper gives the percentile smoothing certificate in $\ell_2$ form:
\[
h_{\underline{p}(x)}\le h_p(x')\le h_{\overline{p}(x)}, \quad \forall x' \in \{x' \mid \|x-x'\|_2 < r\},
\tag{5}
\]
where
\[
\underline{p}=\Phi\!\left(\Phi^{-1}(p)-\frac{r}{\sigma}\right), \qquad
\overline{p}=\Phi\!\left(\Phi^{-1}(p)+\frac{r}{\sigma}\right),
\]
and $\Phi$ is the standard Gaussian CDF. This provides a sufficient condition ensuring that the smoothed score stays on the same side of the decision threshold throughout an $\ell_2$ ball [2605.07690].

The certified $\ell_2$ radius $r$ depends on whether the smoothed score is above or below the threshold:
\[
r=
\begin{cases}
\sigma\big(\Phi^{-1}(p)-\Phi^{-1}(\underline{p})\big), & \text{if } h_p(x)>\gamma,\\[4pt]
\sigma\big(\Phi^{-1}(\overline{p})-\Phi^{-1}(p)\big), & \text{if } h_p(x)\le \gamma.
\end{cases}
\tag{10, part}
\]
This is the radius within which the smoothed decision is unchanged [2605.07690].

Within the logic of certified defense, the role of smoothing is therefore modular: it supplies a norm-ball certificate around the test point, and the main theoretical task is to replace that norm geometry with the DTW geometry relevant to temporal distortions.

## 4. The Keogh lower bound and the bridge from $\ell_2$ to DTW

The key technical step is the conversion of the $\ell_2$ certificate into a DTW certificate through a lower-bound contradiction argument. For a warping window $w$, the upper and lower envelopes are
\[
U_{i,k}=\max(x_{i-w,k}:x_{i+w,k}), \qquad
L_{i,k}=\min(x_{i-w,k}:x_{i+w,k}).
\tag{6}
\]
These envelopes characterize, at each time step and channel, the range of values that can align to $x_i$ within the allowed warping window [2605.07690].

The Keogh lower bound is then defined as
\[
LB_{\text{Keogh},p}(x,x')=
\left(
\sum_{i=1}^{T}\sum_{k=1}^{C}
\begin{cases}
(x'_{i,k}-U_{i,k})^p, & \text{if } x'_{i,k}>U_{i,k},\\
0, & \text{if } L_{i,k}\le x'_{i,k}\le U_{i,k},\\
(x'_{i,k}-L_{i,k})^p, & \text{if } x'_{i,k}<L_{i,k},
\end{cases}
\right)^{1/p}.
\tag{7}
\]
If a point of $x'$ stays inside the envelope of $x$, it contributes nothing to the lower bound; only envelope violations contribute. Since this is a lower bound on DTW, any sufficiently large value implies a large DTW distance [2605.07690].

The conceptual bridge is stated as Lemma 3.2. If a smoothed function $h$ satisfies
\[
a\le h(x')\le b,\quad \forall x' \in \{x' \mid \|x'-x\|\le r\},
\]
then it also satisfies
\[
a\le h(x')\le b,\quad \forall x' \in \{x' \mid DTW(x,x')\le \varepsilon\},
\]
where $LB(x,x')$ is a strict lower bound of $DTW(x,x')$ and
\[
\varepsilon = \inf\{LB(x,x') \mid \|x-x'\| > r\}.
\tag{8}
\]
The proof mechanism is contradiction: if some point had $DTW(x,x')\le\varepsilon$ while lying outside the safe $\ell_2$ ball, the strict lower bound would violate the definition of $\varepsilon$ [2605.07690].

The main theorem instantiates this bridge with $LB_{\text{Keogh}}$. The decision condition is
\[
\begin{cases}
h_{\underline{p}(x)} > \gamma, & \text{if } h_p(x) > \gamma,\\
h_{\overline{p}(x)} \le \gamma, & \text{if } h_p(x) < \gamma.
\end{cases}
\tag{9}
\]
Then robustness is guaranteed for all $x'$ satisfying
\[
DTW(x,x')\le \varepsilon,
\]
where
\[
\varepsilon=
\begin{cases}
0, & \text{if } r\le R,\\[4pt]
\sqrt{M^2+r^2-R^2}-M, & \text{if } r>R,
\end{cases}
\tag{10}
\]
with
\[
A_i=\max(U_i-x_i,\;x_i-L_i), \qquad
R=\sqrt{\sum_{i=1}^{n}\|A_i\|_2^2}, \qquad
M=\max_{1\le i\le n}\|A_i\|_2.
\]
Here $R$ is the total amount of Euclidean perturbation that can remain inside the envelope with zero Keogh penalty, while $M$ is the largest single-coordinate slack [2605.07690].

The two-case structure is significant. If $r\le R$, the infimum DTW lower bound outside the $\ell_2$ ball is still $0$, so the DTW certificate degenerates to $\varepsilon=0$. If $r>R$, any point outside the $\ell_2$ ball must protrude beyond the envelope and therefore induce positive Keogh cost, producing a positive DTW certificate. This suggests that certificate quality depends jointly on the smoothing-derived Euclidean radius and on the tightness of the envelope slack permitted by the chosen DTW window.

## 5. Certification semantics, evaluation protocol, and operationalization

The formal certified-defense definition is pointwise: the detector provides certified defense at input $x$ with DTW radius $\varepsilon$ if there is no $x'$ such that
\[
DTW(x,x')\le \varepsilon
\]
and
\[
d(x')\ne d(x)
\]
with confidence at least $1-\alpha$ [2605.07690].

The practical certification procedure is given as a seven-step pipeline. For a test input $x$, one samples Gaussian noise $\eta_1,\dots,\eta_n\sim\mathcal N(0,\sigma^2 I)$, computes noisy scores
\[
X_i=f(x+\eta_i),
\]
sorts the scores and estimates confidence bounds on the relevant percentiles using binomial tail bounds, derives the smoothed decision and the $\ell_2$ certificate radius $r$, constructs DTW envelopes $U,L$ for a chosen wrapping window $w$, computes the slack values $A_i$ and then $R$ and $M$, and finally outputs the DTW certified radius
\[
\varepsilon=
\begin{cases}
0, & r\le R,\\
\sqrt{M^2+r^2-R^2}-M, & r>R.
\end{cases}
\]
The method does not require retraining and can be applied to pre-trained anomaly detectors. At inference, the described pipeline is: inject Gaussian noise, optionally pass through a denoising stage, aggregate scores via percentile smoothing, and output the anomaly decision together with the DTW certificate [2605.07690].

The empirical study uses seven benchmark datasets, listed in the text as SMAP, MSL, SMD, NIPS-TS-SWAN, NIPS-TS-CREDITCARD, NIPS-TS-WATER, UCR-1, and UCR-2, with UCR split into two subsets. These include both univariate and multivariate anomaly detection tasks. The anomaly detection backbones are COUTA, TimesNet, and DeepSVDDTS. The primary baselines are the undefended base model, a traditional $\ell_p$-norm certified defense based on standard randomized smoothing, and the proposed DTW-certified defense, all evaluated under DTW-based adversarial attacks [2605.07690].

Default hyperparameters are sequence length $T=50$, DTW wrapping window $w=4$, number of noisy samples $n=1000$, Gaussian noise level $\sigma=0.5$, percentile $p=0.5$, and confidence parameter $\alpha=10^{-3}$. The implementation is reported in PyTorch on Linux with Intel Xeon Gold 6326 CPUs and NVIDIA A100 80GB GPUs [2605.07690].

The evaluation includes both ordinary detection metrics and certification metrics. Detection performance is measured by point-adjusted F1-score and ROC AUC. Certified radii over test instances are summarized by mean radius, maximum radius, standard deviation, and certified proportion, defined as the fraction with non-zero certificate. The paper also extends certified accuracy to anomaly detection via certified confusion matrices:
\[
\text{Certified Accuracy}(e)=\frac{1}{N}\sum_{i=1}^N \mathbf{1}\{\forall x' \text{ with } DTW(x_i,x')\le e : f(x')=y_i\},
\tag{22}
\]
\[
\text{Certified Accuracy}=\frac{\text{Certified TP}+\text{Certified TN}}{N},
\tag{23}
\]
\[
\text{Certified F1}=2\cdot \frac{\text{Certified Precision}\cdot \text{Certified Recall}}{\text{Certified Precision}+\text{Certified Recall}},
\tag{24}
\]
with
\[
\text{Certified Precision}=\frac{\text{Certified TP}}{\text{Certified TP}+\text{FP}},
\tag{25}
\]
\[
\text{Certified Recall}=\frac{\text{Certified TP}}{\text{Certified TP}+\text{FN}}.
\tag{26}
\]
These are conservative worst-case metrics [2605.07690].

## 6. Empirical findings, trade-offs, and methodological context

The reported results indicate that the defense is broadly applicable across datasets and models, often with only small degradation and occasionally even improvement in clean detection performance. One example from Table 1 is NIPS-TS-WATER with DeepSVDDTS, where the method certifies $99.46\%$ of test inputs with mean DTW certified radius $0.189$, with no performance degradation in F1 or AUC. On many tasks, DeepSVDDTS attains the strongest robustness, which the authors state may be because it handles noisy inputs better. Robustness is weaker on datasets such as SMAP and NIPS-TS-SWAN, which the paper attributes to higher channel dimensionality, higher variance, and looser lower-bound estimation [2605.07690].

Under strong DTW-based adversarial attack, the main empirical comparison is between undefended models, $\ell_p$-certified models, and the DTW-certified defense at attack budget
\[
\varepsilon_{\text{att}}=1.0.
\]
This budget exceeds the average certified radius of roughly $0.5$ and is presented as a strong stress test. DTW attacks severely damage undefended models, with F1 drops of $60.6\%$ on SMD and $89.7\%$ on UCR-1. The $\ell_p$-certified defense improves robustness somewhat but remains inconsistent when attacks involve strong temporal distortions. The DTW-certified defense consistently outperforms both baselines: on MSL, F1 under attack improves from $0.672$ for the $\ell_p$-certified defense to $0.784$ for the DTW-certified defense, a gain of $11.2$ percentage points; on UCR-1, F1 improves from $0.761$ to $0.948$, a gain of $18.7$ percentage points [2605.07690].

The paper also reports dataset-level certified performance curves. Figure 3 shows certified F1 and certified accuracy versus DTW attack budget $t$ for COUTA on MSL and SMAP under both evasion and availability attacks. On SMAP, with suitable $\sigma$ such as $\sigma=1.0$, the defense maintains certified F1 of roughly $0.5$ under evasion attack at budget $t=0.2$ [2605.07690].

The principal trade-off concerns the smoothing noise level $\sigma$. Increasing $\sigma$ generally increases mean certified radius, maximum radius, and certified proportion, but too large a value hurts F1-score and ROC AUC. The examples singled out in the text are that moderate $\sigma=0.5$ or $1.0$ can improve both robustness and sometimes generalization, whereas large $\sigma=2.0$ often degrades clean detection. The paper characterizes this as the standard smoothing trade-off: more noise yields larger certificates but can blur the detector. It also notes that moderate smoothing can improve clean performance by stabilizing the decision boundary [2605.07690].

The limitations are explicit. Certification requires many noisy evaluations at test time, introducing inference overhead. The DTW certificate is conservative because it is derived through $LB_{\text{Keogh}}$ rather than exact DTW geometry; failure to certify beyond radius $\varepsilon$ does not imply actual non-robustness beyond that radius. Longer sequences and higher-dimensional multivariate series can reduce certificate tightness, and the use of a Sakoe-Chiba warping window means the quality of the certificate depends on the chosen warping constraint. The scope of the current framework is limited to anomaly detection rather than classification or forecasting [2605.07690].

In a broader methodological context, the DTW construction follows the same general research pattern as Wasserstein smoothing: a non-additive metric is not certified directly in raw input space but through a metric-specific reduction that permits the reuse of randomized smoothing machinery. Wasserstein smoothing converts a transport-based perturbation model into an $L_1$-type perturbation model in flow space and then applies an existing $L_1$ randomized smoothing certificate [1910.10783]. DTW-certified robust defense does not use a latent additive transformation space in the same way; instead, it converts an $\ell_2$ certificate into a DTW certificate through a strict lower-bound bridge. This suggests a broader taxonomy of certified defenses for non-additive metrics: one class reduces the metric to a norm in a transformation space, while another uses provable lower or upper bounds to transfer a norm-ball certificate into the target geometry.

Source: https://www.emergentmind.com/topics/dtw-certified-robust-defense