A General Metric-Space Formulation of the Time Warp Edit Distance (TWED)
Zhen Yi Lau
TL;DR
This work extends the Time Warp Edit Distance (TWED) to arbitrary metric spaces by formulating the General Time Warp Edit Distance (GTWED) on observations in a metric space $(\mathcal{X},d)$ and indices in a metric time domain $(\mathcal{T},\Delta)$. By introducing a local product-space cost $D(a_{t(i)}, b_{s(j)}) = d(a_{t(i)}, b_{s(j)}) + \gamma\Delta(t_i, s_j)$ and its regularized form $\tilde{D} = g(D)$, GTWED constructs a recursive, additive edit-distance-like metric with gap penalties $\lambda$ and stiffness $\gamma$, and proves that it remains a true metric under mild conditions. The paper shows TWED as a special case when $X=\mathbb{R}^d$, $T$ is a subset of $\mathbb{R}$, and $g(x)=x$, thus subsuming classical TWED; it also provides a dynamic-programming algorithm with $O(pq)$ time and space. A key contribution is enabling TWED-like elastic distances over sequences on symbolic domains, manifolds, or embeddings, broadening applicability while noting that certain $L_p$-based bounds from TWED do not generalize to GTWED.
Abstract
This short technical note presents a formal generalization of the Time Warp Edit Distance (TWED) proposed by Marteau (2009) to arbitrary metric spaces. By viewing both the observation and temporal domains as metric spaces $(X, d)$ and $(T, Δ)$, we define a Generalized TWED (GTWED) that remains a true metric under mild assumptions. We provide self-contained proofs of its metric properties and show that the classical TWED is recovered as a special case when $X = \mathbb{R}^d$, $T \subset \mathbb{R}$, and $g(x) = x$. This note focuses on the theoretical structure of GTWED and its implications for extending elastic distances beyond time series, which enables the use of TWED-like metrics on sequences over arbitrary domains such as symbolic data, manifolds, or embeddings.
