DTW Barycenter Averaging

Statistics
Introduced by
François Petitjean
Year
2011
Type
Distance-based time-series aggregation
Family
Time-series alignment and averaging

What does it do?

DTW Barycenter Averaging (DBA) computes an average, or representative, sequence for a set of time series under dynamic time warping (DTW).

The average is defined as the sequence that minimises the sum of squared DTW distances to the inputs, so it is intended to reflect shared shape rather than point-wise alignment. Petitjean, Ketterlin and Gançarski introduced the method in Pattern Recognition, volume 44 (2011). The bibliographic record for the same DOI gives 2010, so the article was probably available online before its print issue.

The intuition behind the method

Suppose several recordings of the same spoken word differ in speed and in when their features occur. A point-wise mean of these recordings blurs the features, because it compares time index with time index. DBA instead re-aligns each recording to the current average with DTW, then updates each point of the average from the values matched to it. The result tends to place each shared feature at the time position where most recordings put it, even when the recordings are stretched or compressed differently, subject to the local-optimum and outlier limitations described below.

History

Dynamic time warping is an older distance measure, widely used in speech recognition. Averaging under the DTW distance was not straightforward, because the optimal average depends on the alignment itself. Petitjean, Ketterlin and Gançarski proposed DBA as a general averaging method and applied it to clustering. Cuturi and Blondel later introduced soft-DTW, a differentiable variant suited to learning-based pipelines.

When to use it

Choose DBA when you need one representative sequence for time series that differ in timing, speed or local warping, for example as a centroid in DTW-based clustering or as a template for matching. It is the appropriate choice when a point-wise mean would blur features that occur at different times across inputs. Do not use it when the sequences are already aligned on a common time axis, since a point-wise mean is then simpler and sufficient. It is also a poor fit when lengths are highly heterogeneous, when the computational budget cannot cover repeated DTW computations, or when you need a closed-form or invertible summary. Because the result depends on the starting average, plan for several starts when the choice matters.

Limitations and considerations

  • Each iteration needs one DTW computation per input sequence, and each DTW costs O(N^2) for sequences of length N, so runtime grows with both the number of series and their length
  • The procedure reaches a local solution, so different initial averages can give different results
  • The output length must be fixed beforehand, and the result depends on that choice
  • Outlying or atypical inputs take part in the alignment and can pull the average away from the typical pattern

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Averages in DTW space, so features that occur at different times in different inputs are matched rather than smeared, which a point-wise mean cannot do
  • Accepts sequences of different lengths, because alignment is computed by DTW rather than by time index
  • The output is a sequence in the same format as the inputs, so it can serve directly as a cluster centroid or template for DTW-based comparison
  • The DTW alignment paths computed during averaging show how each input maps onto the average, which supports downstream inspection

Applications

  • Time-series clustering, grouping similar time series by computing cluster centroids with DBA
  • Illustrative example: speech recognition, creating template models from multiple pronunciations of the same word for robust matching
  • Illustrative example: gait analysis and motion capture, averaging walking or running patterns to create typical movement profiles for comparison
  • Illustrative example: sensor data summarization, creating templates from device readings to support anomaly detection

How it works

How it works

1

Collect the sequences to be averaged, checking that they share a comparable sampling rate and represent the same kind of pattern, because DBA summarises whatever it is given.

2

Normalise amplitudes, since the squared point-wise cost lets high-amplitude sequences dominate both the alignment and the average. Decide how missing values and outliers will be handled, because a single atypical sequence can pull the average. Fix the output length in advance.

3

For the current candidate average and each input sequence, compute the DTW distance using the squared point-wise cost shown in the formula. These alignments show how each input maps onto the candidate and are the input to the update step. If FastDTW is used to reduce cost, the alignments are approximate, so the average and the objective it minimises are approximate as well.

Formula
DTW(X, Y) = \min_{w} \sqrt{\sum_{(i,j)\in w} (x_i - y_j)^2}
4

Starting from an initial sequence, DBA aligns every input to the current average with DTW. It then recomputes each point of the average as the mean of the input values aligned to it, and repeats until the change becomes small. This is an alignment-and-update scheme rather than gradient descent, and it reaches a local solution whose quality depends on the initial average. A common starting choice is the medoid of the inputs, meaning the input with the smallest total DTW distance to the others; a randomly chosen input is another option. Stop when the change in the average, or in the total DTW cost, falls below a tolerance chosen for the application. Because the result is only locally optimal, run the procedure from several starting sequences, compare the final total costs, and choose the average with the lowest cost.

Formula
DBA = \arg\min_{z} \sum_{k=1}^{K} DTW(z, X_k)^2
5

Inspect the average against the inputs, for example by plotting how each input aligns to it, before using it as a cluster centroid, template or prototype. As a fit measure, compute the summed squared DTW distance from the average to each input, which is the objective in the model step; it also allows comparison between candidate averages obtained from different starting sequences. A low cost does not by itself show that the inputs are homogeneous. If the group is multimodal, the average may fit none of its subgroups well, so split heterogeneous or multimodal groups first (for example by clustering) and summarise each subgroup separately.

Common pitfalls

  • Starting from an arbitrary or poorly chosen initial sequence can trap the iteration in an inferior local solution; compare results from several starting points
  • Skipping amplitude normalisation lets high-amplitude inputs dominate, because the DTW cost is built from squared differences
  • Running unconstrained DTW on long sequences is slow; a warping window such as the Sakoe-Chiba band limits both the cost and the range of allowed warping

Frequently asked questions

How is DBA different from simply taking the mean of time series at each time point?

Pointwise averaging (Euclidean mean) assumes all sequences are temporally aligned, which is unrealistic. DBA allows temporal warping, so each input sequence can be stretched or compressed to match the average, producing a result that better captures the actual pattern.

What should the length of the output average sequence be?

The length is typically set to the average or median length of the input sequences, or can be estimated using heuristics. Some methods optimize the length jointly with the sequence values, though this increases computational cost.

How long does DBA computation take for a large dataset?

DBA involves K DTW distance computations per iteration, where K is the number of input sequences. Each exact DTW is O(N^2) for sequences of length N. To limit cost, a Sakoe-Chiba band restricts the warping range. FastDTW is faster but gives approximate alignments, so the average and its objective are approximate too. If accuracy matters, use exact DTW with a constraint band, and check FastDTW results against exact DTW on a subset of the data.

Can DBA handle sequences of very different lengths?

Yes, DBA naturally handles variable-length sequences through DTW. However, having very heterogeneous lengths (e.g., one sequence 10x longer than others) can produce poor averages. Consider clustering by length or filtering outliers first.

Is DBA invertible or can I reconstruct original sequences from the average?

No, DBA is not invertible. The average sequence is a summary statistic. However, the DTW alignment paths computed during DBA can reveal how each input sequence aligns to the average, useful for downstream analysis.

Related methods

Sources

  1. Salvador, S., & Chan, P. (2004). FastDTW: Toward accurate dynamic time warping in linear time and space. Intelligent Data Analysis, 11(5), 561–580.

    Open publication reference
  2. Petitjean, F., Ketterlin, A., & Gançarski, P. (2011). A global averaging method for dynamic time warping, with applications to clustering. Pattern Recognition, 44(3), 678–693.

    Open DOI reference
  3. Cuturi, M., & Blondel, M. (2016). Soft-DTW: A differentiable loss function for time-series. arXiv preprint arXiv:1703.01541.

    Open publication reference