Skip to content
AI.info

Unsupervised learning

Time-Series Clustering and Alignment

Cluster sequences using feature summaries, elastic distances, shape normalization, and alignment-aware validation.

By the end you can

Comparison

Euclidean distance and dynamic time warping

Elastic alignment can recover shared shape. It can also erase timing differences that mattered. Both the brake on it and the price of it have been measured rather than argued.

The brake came fitted from the start. Dynamic time warping arrived in 1978 with its limit already built in. Sakoe and Chiba restrict the warping path with an “adjustment window” j - r <= i <= j + r and with a slope constraint P. Their abstract announces it: “A new technique, called slope constraint, is successfully introduced, in which the warping function slope is restricted so as to improve discrimination between words in different categories.” The constraint carried a number. They set the window length r to 6 frames, which at their 18 ms sampling period “covered the utmost +-108 ms timing difference”. Across 3,000 recognition tests — 10 speakers, 6 reference-pattern sets, 50 input patterns — the optimized symmetric-form algorithm “gives no more than about two-thirds errors, even compared to the best conventional algorithm”, against 0.8 percent error for plain linear time normalization. The window was not a later patch. It shipped with the method.

The third column is not the poor relation of the second. Over 48 UCR data sets, Paparrizos and Gravano found no significant difference in average rank between shape-based distance (SBD), cDTW_opt and cDTW_5, under a Friedman test with post-hoc Nemenyi at 95% confidence. SBD is only 4.4x slower than Euclidean distance. The cost gap runs the other way too: “SBD is three orders of magnitude (3533x) faster than DTW”. An independent benchmark ran eight clustering methods over 112 UCR data sets and reached the same shape. For k-means “the tallies are 32, 31 and 28 for DTW, shape-based, and Euclidean, respectively”, and the average Adjusted Rand Index across all eight methods ran only from 0.26 (agglomerative + Euclidean) down to 0.16 (density peaks + DTW). "Is more computationally expensive" has a factor attached to it. The accuracy it buys may not survive a significance test.

FigureComparison · 3 columns

Pointwise Euclidean distance

Compares values at corresponding timestamps.

  • Fast after equal-length alignment
  • Treats timing shift as difference
  • Works when clocks are synchronized
  • Needs scaling and missingness rules

Dynamic time warping

Finds a low-cost path through pairwise time alignments.

  • Handles local speed variation
  • Can over-align unrelated events
  • Needs a warping constraint
  • Is more computationally expensive

Feature-space distance

Compares engineered temporal summaries.

  • Supports scalable conventional clustering
  • Can encode domain invariances
  • May lose local sequence detail
  • Depends on feature design

Two machines with the same failure shape at different speeds

One motor develops a vibration pattern over six minutes. Another shows the same progression over nine. Euclidean pointwise distance calls them different, because the peaks fall at different timestamps. Time-series similarity must decide whether timing variation is noise, signal, or evidence of a different process. Alignment is therefore a modeling choice. It is not a preprocessing afterthought.

A sequence can match in shape while differing in clock time.

Analogy

Comparing melodies played at different tempos

Two musicians play the same melody, one slowly and one quickly. A listener still hears one tune. Elastic alignment can match corresponding phrases despite timing differences.

Sometimes tempo is the message — an accelerating machine, a delayed response. Warping should then be constrained by the timing variation the domain considers irrelevant. How much that is has been measured. Ratanamahatana and Keogh varied the Sakoe-Chiba warping window from 0% (Euclidean) to 100% (unconstrained) on seven classification data sets, under 1-NN leave-one-out. Every data set peaked in single or low double digits: Trace at 1%, Face, Gun, TwoPatterns and Wordspotting at 3%, Syn_contrl_chrt at 8%, Leaf at 10%. Their summary is four clauses long: “a little warping is a good thing, but too much warping is a bad thing”.

Those numbers contradicted the setting the field was using. “The vast majority of the data mining researchers have used a Sakoe-Chiba Band with a 10% width for the global constraint”, they report, a width “inherited from the speech processing community” rather than tuned on the data at hand. Paparrizos and Gravano later tuned the window per data set across the 48 UCR data sets and landed on the same order of magnitude: “across the 48 datasets the average warping window is 4.5%”. A reader now has a starting value. Not a principle.

Alignment encodes which timing differences the model is allowed to forgive.

Key idea

Subsequence clustering can manufacture duplicated evidence

Overlapping windows from one long series are strongly dependent. A common event can appear in dozens of nearly identical windows and dominate cluster size or stability.

Split and resample by source series or episode, not by window alone. Track overlap so that repeated slices do not masquerade as independent support.

Many windows do not necessarily mean many independent examples.

Case

Sliding-window centers came out as sine waves whatever the data held

Cluster sliding windows from a long series and the centers come out as sine waves, whatever the data contained. Keogh and Lin took subsequence clustering to that conclusion in 2003. It happens, they found, “regardless of the clustering algorithm, the number of clusters, or the dataset used”. Their Theorem 1 gives the reason. For a series with zero overall trend and a window much shorter than the series, the mean of all windows is “an approximately constant vector”.

The result did not stay one laboratory's claim. Ide, at IBM Research in Tokyo, opens his abstract with the reception: “The data mining and machine learning communities were surprised when Keogh et al. (2003) pointed out that the k-means cluster centers in subsequence time-series clustering become sinusoidal pseudo-patterns for almost all kinds of input time-series data.” Then he reproduced it. His series was 90 random instances of the Cylinder-Bell-Funnel patterns, concatenated — “We set the number of clusters and the window size of SW to be k = 3 and w = 128, respectively” — and out came exactly the predicted object: “Close inspection shows that the three sinusoids have the same wavelength of w, separated by a phase of 2 pi/3”. His 2006 paper does not stop at observing the effect. It derives it, from spectral clustering and translational symmetry.

Steps

Design a time-series clustering experiment

Begin with the temporal question and only then select the representation. Steps 1 to 4 fix the unit, the invariances, the representation and the split. Step 5 is where the elastic route becomes expensive a second time, because under DTW the prototype you are asked to inspect is itself a research problem.

The obvious way to average sequences under DTW is pairwise — schemes such as NLAAF and PSA. In 2011 Petitjean and colleagues showed that this is not associative: “Pairwise averaging strategies are intrinsically sensitive to the order, with no guarantee that a different order would lead to the same result.” Their global alternative, DTW Barycenter Averaging, does better on the archive data sets: “for all datasets, DBA reduces/improves the intraclass inertia”, with a geometric average of inertia ratios of 65% against both NLAAF and PSA.

A better centroid did not, by itself, buy a better clustering. An independent evaluation over 48 UCR data sets found k-DBA beat k-means with DTW on 39 of 48 data sets, “with an average improvement in Rand Index of 25.6%”. And yet k-DBA “still does not perform better than k-AVG+ED in a statistical significant manner”. That is why step 5 names medoids before centroid curves. A medoid is an observed series. It costs neither an averaging algorithm nor an argument about ordering.

FigureProcess · 6 steps
  1. 1. Define sequence unit

    Choose whole entity, episode, fixed window, event-aligned window, or subsequence.

  2. 2. State invariances

    Decide whether offset, scale, phase, speed, and duration should affect similarity.

  3. 3. Build representations

    Compare engineered features, raw normalized sequences, and constrained elastic distance.

  4. 4. Split by source and time

    Prevent overlapping windows and future periods from leaking across evaluation.

  5. 5. Inspect prototypes

    Review medoids, centroid curves, boundary cases, and within-cluster temporal variation.

  6. 6. Test future assignment

    Evaluate whether later sequences fit, drift, or require an unknown-regime label.

Example

Temporal choices that change cluster meaning

Time-series pipelines should expose which differences were normalized away. The field's most-used benchmark makes one of those choices for you, before you open the data. The UCR Time Series Archive grew from 16 data sets to 45, then to 85, then to 128, and it states the policy in Section III-C: “The time series are already z-normalized to remove offset and scaling (transformed data have zero mean and in unit of standard deviation).” The same curators grant the exception: “for some (we believe, very rare) cases, data normalization is ill-advised”. Their own Fall 2018 briefing records where the line falls. The 85 data sets of the Summer 2015 release “are z-normalized by legacy”. The 43 added in 2018 are “kept as is unless they were already z-normalized by donating source”.

  • Amplitude normalization: Scaling each series removes absolute load, which helps shape grouping but can hide overload regimes. Paparrizos and Gravano put a number on the flip. On a pair of length-1024 sequences the biased cross-correlation peak lands at w = 1797 without z-normalization, a 773-step shift; with z-normalization and coefficient normalization it lands at w = 1024, no shift at all.
  • Phase alignment: Aligning daily cycles by peak time can merge early and late users whose schedule difference matters operationally.
  • Window length: A five-minute window captures transients, while a daily summary emphasizes operating regime. The window is also what a sliding-window prototype turns out to be a property of.
  • Seasonal leakage: Features computed with future observations can make later regimes look easier to cluster.
  • Unequal sampling: Interpolation can smooth short spikes and create similarity that the original sensors did not support.

Visual

Four routes to time-series clusters

Each route preserves a different view of temporal behavior. They are not equally exposed to the same failures. One of them, the sliding-window route, has a published result saying its output can be independent of the data.

FigureHierarchy · 5 levels
  • Feature-based clustering

    Summarize each series through statistics, trends, spectra, or event counts.

    • Raw-shape clustering

      Compare aligned observations directly after resampling and normalization.

      • Elastic-distance clustering

        Allow limited nonlinear alignment through dynamic time warping or related distances.

        • Model-based clustering

          Group series by fitted state-space, autoregressive, or motif-generating models.

          • Subsequence discovery

            Find recurring local patterns inside longer streams rather than assigning one label per series.

The unit can be a whole series, an episode, or a local subsequence.

Temporal clusters are statements about permitted deformation

Equal values, similar shapes, aligned motifs, shared spectra, and common generative dynamics can each define a cluster of series. Those are five claims, not five names for one.

Document the window, the resampling, the normalization, the alignment constraint, and the prototype. Each of those has a measured default somewhere in this lesson: a warping band of a few percent rather than ten, a benchmark that z-normalizes by policy, a centroid method whose result depends on the order it saw the series. Without that record, a cluster name hides the temporal definition that produced it.

Time-series similarity is inseparable from the clock transformations you allow.

Case

Thirty-eight data sets, and elastic measures converged with Euclidean

The alignment choice was priced in 2008. Ding and colleagues re-implemented eight representation methods and “9 different similarity measures and their variants”, then ran the comparison on “38 real world data sets”. As training sets grow, they found, “the accuracy of elastic measures converge with that of Euclidean distance”. Constraining the warping window was not a compromise either. It “can reduce the computation cost and enable effective lower-bounding, while yielding the same or even better accuracy”. The elastic advantage was largest where the training data was smallest.

Position

Sliding-window subsequence clustering reports the window, not the series

There is one route in this lesson with a published result saying its output can be independent of the data, and it is the obvious one: cut a long stream into overlapping windows and cluster the pieces. Keogh and Lin ran it to the end. Cluster sliding windows from a long series and the centers come out as approximate sine waves, “regardless of the clustering algorithm, the number of clusters, or the dataset used”.

The conditions are the content, so read them. Theorem 1 covers a series with zero overall trend and a window much shorter than the series. Under those, the mean of all windows is “an approximately constant vector”. The finding is not one group's artefact. Ide reproduced it at IBM Research in Tokyo, on 90 concatenated random instances of the Cylinder-Bell-Funnel patterns — “We set the number of clusters and the window size of SW to be k = 3 and w = 128, respectively” — and recovered three sinusoids of wavelength w, a phase of 2 pi/3 apart. He then derived the effect from spectral clustering and translational symmetry rather than leaving it as an observation. That is still a statement about one construction, not about time-series clustering in general. Feature summaries, raw shape, elastic distance and fitted models are doing something else. What it does say is narrow. A smooth periodic prototype out of a sliding-window run is not by itself a discovery about the machine.

A second problem survives wherever the theorem's conditions do not hold. Overlapping windows cut from one series are strongly dependent. A single event can appear in dozens of nearly identical windows and dominate cluster size or stability, and the same evidence gets counted many times over. So the questions to put to a subsequence result are not about how convincing the prototypes look. They are how far the windows overlapped, and whether resampling was done by source series or episode. A large count of windows need not be a large count of independent examples.

Under Keogh and Lin’s conditions the prototype is a property of the windowing.

Key takeaways