---
title: 'DILATE: Loss for Shape & Time in Forecasting'
url: https://www.emergentmind.com/topics/distortion-loss-incorporating-shape-and-time-dilate
type: topic
---

# DILATE: Loss for Shape & Time in Forecasting

DILATE (Distortion Loss Incorporating Shape and Time) is a differentiable training objective designed for deep models in multi-step time series forecasting, with explicit sensitivity to both waveform shape and event timing. Unlike conventional losses such as Mean Squared Error (MSE) or classic Dynamic Time Warping (DTW), DILATE disentangles amplitude/shape fidelity and temporal precision via two smoothly-differentiable terms. The loss is implemented with dynamic programming, yielding computational efficiency and enabling end-to-end gradient-based training in complex neural architectures. Empirical evaluations demonstrate that DILATE substantially improves the detection and prediction of sudden or sharp changes in diverse domains such as physiological waveform modeling and traffic or electricity forecasting [2104.04610], [1909.09020], [2601.00714].

## 1. Mathematical Formulation and Key Components

The DILATE loss computes a weighted sum of two distortion terms over predicted and observed sequences of equal length, $y$ and $\hat y$, parameterized by a tradeoff scalar $\alpha \in [0,1]$ and a soft-min smoothing parameter $\gamma > 0$:

$$
\mathcal{L}_{\mathrm{DILATE}}(\hat y, y) = \alpha\,\mathcal{L}_{\mathrm{shape}}(\hat y, y) + (1-\alpha)\,\mathcal{L}_{\mathrm{temporal}}(\hat y, y)
$$

- **Shape term (soft-DTW)**: Measures morphological similarity via a log-sum-exp relaxation of classic DTW. For $\Delta_{ij} = \lVert \hat y_i - y_j \rVert^2$ (or $|\hat y_i - y_j|$ in [2601.00714]), soft-DTW is:

$$
\widetilde{\mathrm{DTW}}_\gamma(\hat y, y) = -\gamma\,\log\left[\sum_{A \in \mathcal{A}} \exp\left(-\langle A, \Delta \rangle / \gamma\right)\right]
$$
where $\mathcal{A}$ denotes monotonic alignment matrices. As $\gamma \to 0^+$, soft-DTW converges to classic DTW.

- **Temporal term (soft-TDI)**: Assesses alignment by penalizing off-diagonal associations, measuring timing errors. Using a penalty matrix $\Omega$ (typically $\Omega_{ij} = (i-j)^2$ or $|i-j|$):

$$
\widetilde{\mathrm{TDI}}_\gamma(\hat y, y) = \langle A^*_\gamma, \Omega \rangle
$$
with $A^*_\gamma = \nabla_\Delta \widetilde{\mathrm{DTW}}_\gamma(\hat y, y)$, the expected soft-alignments under the Gibbs measure induced by $\Delta$. This yields differentiability in both model output and input sequences.

## 2. Computational Implementation and Differentiation

Both shape and temporal components leverage dynamic programming for efficient evaluation and gradient computation:

- **Forward DP**: Constructs recurrence matrices to compute soft-DTW in $O(k^2)$ time and space, avoiding enumeration of all $O(3^k)$ alignment paths.
- **Backward DP**: Derivatives with respect to $\Delta$ are computed via reverse dynamic programming. The temporal loss multiplies $A^*_\gamma$ with $\Omega$ and backpropagates through the Hessian of $\widetilde{\mathrm{DTW}}_\gamma$ [1909.09020].
- **PyTorch integration**: Custom autograd functions exploit intermediate DP tables for both forward and backward passes, yielding up to $35\times$ speed-up versus naïve autograd for $k = 100$ [1909.09020], [2104.04610].

## 3. Parameterization and Hyperparameter Selection

DILATE introduces the following tunable elements for practical deployment:

| Parameter   | Purpose                                   | Typical Values       |
|-------------|-------------------------------------------|---------------------|
| $\alpha$    | Shape/timing balance in total loss        | $0.3 \leq \alpha \leq 0.7$ |
| $\gamma$    | Smoothing in soft-minimum                 | $1e{-2}$ to $1e{-1}$|
| $\Omega$    | Temporal penalty matrix                   | $(i-j)^2$, $|i-j|$  |
| $\beta, \eta$| KD vs DILATE weighting [2601.00714]      | $\beta=10$, $\eta=10$|

Cross-validation or ablation can identify optimal hyperparameters. For KDPhys (rPPG), best MAE was achieved for $\alpha = 0.5$ and $\gamma = 10^{-2}$ [2601.00714]. For generic forecasting and biomedical signals, similar mid-range $\alpha$ achieves robust shape and event detection.

## 4. Domain-Specific Roles and Significance

The shape term in DILATE enforces morphological fidelity, preserving oscillations, amplitudes, and salient event structure (e.g., systolic ramp in rPPG). The temporal term penalizes horizontal event shifts, ensuring sharp event localization—a property vital for domains where precise timing of peaks, drops, or change-points is critical.

For rPPG extraction, DILATE ensures predicted pulse cycles align in both morphology and event timing, outperforming MSE or frequency-domain losses that cannot separate these criteria [2601.00714]. In traffic or ECG forecasting, DILATE detects sudden transitions and matches ground-truth event positions better than alternatives [1909.09020], [2104.04610].

## 5. Comparative Evaluation and Ablation Results

Empirical studies confirm DILATE's advantages. On standard benchmarks:

| Loss           | MAE/DTW/TDI Improvement         | Case                    |
|----------------|---------------------------------|-------------------------|
| DILATE         | MAE reduction by $18.15\%$      | KDPhys rPPG [2601.00714]|
| DILATE vs MSE  | DTW down $10-20\%$, TDI $15-30\%$| ECG, traffic, electricity [2104.04610] |
| DILATE vs TD+FD| $22.3\%$ lower MAE              | UBFC rPPG [2601.00714]  |

In ablation, a sweep of $\alpha$ in DILATE shows optimal MAE and RMSE centrally ($\alpha=0.5$); shifting towards pure shape or timing degrades performance [2601.00714]. Separate shape and temporal terms outperform "tangled" DILATE or band-constrained soft-DTW [1909.09020].

## 6. Integration into Neural Architectures and Applications

DILATE's differentiability, DP-based efficiency, and agnostic design allow integration with MLPs, RNNs, Seq2Seq, Transformer, and convolutional architectures. No changes to output layers are required—only the loss function is modified [1909.09020], [2104.04610].

In KDPhys, DILATE is combined with an Attention Feature Distillation term for end-to-end knowledge transfer from 3D CNN teachers to lightweight 2D students [2601.00714]. In STRIPE++ [2104.04610], DILATE-driven kernels enable determinantal point process (DPP) diversity in probabilistic multi-future forecasting, with quality-weighting to encourage sharp and temporally varied forecasts.

DILATE is robust to noise, benefiting from $\gamma$ annealing and gradient clipping strategies for numerically demanding signals.

## 7. Limitations and Variants

DILATE's performance is dependent on correct balancing of shape and time—extreme values of $\alpha$ can render either criterion dominant to the detriment of the other. The quadratic time complexity ($O(k^2)$) scales favourably for moderate-length sequences but becomes limiting in very long horizons. Tangled variants that combine shape and time in a single soft-DTW term underperform the separated approach [1909.09020].

For domain-specific applications such as noisy biomedical signals or traffic, asymmetric penalty matrices $\Omega$ or adaptive smoothing may further improve event localization, especially when early or late shifts have different functional interpretations.

---

DILATE establishes a rigorous, efficiently-computable, and highly adaptable framework for deep time series learning with sensitivity to both feature morphology and timing. Its widespread empirical validation positions it as a strong alternative to conventional loss formulations in forecasting and physiological waveform analysis [2104.04610], [2601.00714], [1909.09020].

Source: https://www.emergentmind.com/topics/distortion-loss-incorporating-shape-and-time-dilate