similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation...

119
1 Download slides while waiting: Abdullah Mueen Assistant Professor of Computer Science University of New Mexico [email protected] http://www.cs.unm.edu/~mueen/Tutorial/CIKM2016Tutorial.pdf

Transcript of similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation...

Page 1: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

1

Download slides while waiting:

Abdullah MueenAssistant Professor of Computer Science

University of New [email protected]

http://www.cs.unm.edu/~mueen/Tutorial/CIKM2016Tutorial.pdf

Page 2: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

2

Acknowledgements

• The following people helped with advice slidea or images: Amanda Minnich, Sindhuja Sivakumar, Diego Silva, François Petitjean, Gustavo Batista, Michail Vlachos, George Kollios, Dimitrios Gunopulos, Eamonn Keogh (If I forgot anyone, apologies)

• I also acknowledge NSF CCF # 1527127. Any error or opinion is solely my responsibility

• My GOAL: Present a survey of literature on similarity search on time series data

• There will be a Q/A segment after every hour

Page 3: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

3

What are Time Series? 1 of 2A time series is a collection of observations made sequentially in time.

More than most types of data, time series lend themselves to visualinspection and intuitions…

0 100 200 300 400 50023

24

25

26

27

28

2925.35025.35025.40025.40025.32525.22525.20025.175..24.62524.67524.67524.675

For example, looking at the numbers in this green vector tells us nothing.But after plotting the data, we can recognize a heartbeat, and possibly even diagnose this person's disease.This tutorial will leverage the visual intuitiveness of time series.

Page 4: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

4

Mantled Howler MonkeyAlouatta palliata

What are Time Series? 2 of 2As an aside… (not the main point for today)

Many types of data that are not true time series can be fruitfully transformed into time series, including DNA, speech, textures, core samples, ASCII text, historical handwriting, novels and even shapes.

0 50 100 150 200 250 300 350 400 450

Page 5: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Similarity Measures

• A similarity measure compares two time series and produces a number representing their similarity• A distance measure is an inverted similarity measure

• Lockstep Measures• Euclidean Distance• Correlation Coefficient• Cross-correlation

• Elastic Measures• Dynamic Time Warping• Edit Distance• Longest Common Subsequence

5

Page 6: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Similarity Search• A query Q is given of length m

• n independent candidate time series C1, C2, …, Cn

• Nearest Neighbor query• Find K nearest neighbor of Q under a distance measure d

• Range Query• Find all time series C where 𝑑 𝑄, 𝐶 ≤ 𝜖

• Density Estimation• Count the number of time series C where 𝑑 𝑄, 𝐶 ≤ 𝜖

6

original

DBquery

Final

Answer

set

Page 7: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Why Similarity Search?

• Most data mining algorithms (e.g. clustering, classification, outlier detection, etc.) use similarity measures and similarity search as subroutines

• Interpretable mining of heterogeneous data objects is possible through similarity search

• Great way to embed scientific knowledge in mining algorithms by modifying and adapting similarity measures

7

Page 8: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

8

Top-level Outline

•Similarity Measures

•Similarity Search• Lock-step search (e.g. Correlation Search)• Elastic search (e.g. DTW search)

Page 9: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Euclidean Distance Metric

y

x

d(x,y)

Given two time series

x = x1…xn

and

y = y1…yn

their z-Normalized Euclidean distance is

defined as:

9

d(x,y)ෝ𝑥𝑖 =

𝑥𝑖 − 𝜇𝑥𝜎𝑥

ෝ𝑦𝑖 =𝑦𝑖 − 𝜇𝑦

𝜎𝑦

𝑑 𝑥, 𝑦 =

𝑖=1

𝑛

( ෝ𝑥𝑖 − ෝ𝑦𝑖)2

Page 10: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Pearson’s Correlation Coefficient

• Given two time series 𝒙 and 𝒚 of length 𝑚.

• Correlation Coefficient:

𝑐𝑜𝑟𝑟 𝒙, 𝒚 =σ𝑖=1𝑚 𝑥𝑖𝑦𝑖 −𝑚𝜇𝑥𝜇𝑦

𝑚𝜎𝑥𝜎𝑦

• Where 𝜇𝑥 =σ𝑖=1𝑚 𝑥𝑖𝑚

and 𝜎𝑥2 =σ𝑖=1𝑚 𝑥𝑖

2

𝑚− 𝜇𝑥

2

• Sufficient Statistics:

σ𝑖=1𝑚 𝑥𝑖𝑦𝑖 σ𝑖=1

𝑚 𝑥𝑖 σ𝑖=1𝑚 𝑦𝑖 σ𝑖=1

𝑚 𝑥𝑖2 σ𝑖=1

𝑚 𝑦𝑖2

One linear scan

Page 11: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Relationship with Euclidean Distance𝑑 ෝ𝒙, ෝ𝒚 = 2𝑛(1 − 𝑐𝑜𝑟𝑟(𝒙, 𝒚))

ො𝑥𝑖 =𝑥𝑖−𝜇𝑥

𝜎𝑥and ො𝑦𝑖 =

𝑦𝑖−𝜇𝑦

𝜎𝑦

𝑑2 ෝ𝒙, ෝ𝒚 =

𝑖=1

𝑛

ො𝑥𝑖 − ො𝑦𝑖2

• Correlation coefficient does not obey triangular inequality• Maximizing correlation coefficient can be achieved by

minimizing normalized Euclidean distance and vice versa

Abdullah Mueen, Suman Nath, Jie Liu: Fast approximate correlation for massive time-series data. SIGMOD Conference 2010: 171-182

Page 12: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

12

0 150 300

chf11 chf10

0 1000-3

-2

-1

0

1

BIDMC Congestive Heart

Failure Database: chf10

BIDMC Congestive Heart

Failure Database: chf11

The Importance of z-Normalization and correlation 1 of 2

Essentially all datasets must have everysubsequence z-normalized.

There are a handful of occasions where it does not make sense to z-normalize, but in those cases, similarity search does not make sense either.

In this example, we begin by extracting heartbeats from two unrelated people.

Even without normalization, it happens that both sets have almost the same mean and standard deviation. Given that, do we need to bother to normalize them? (next slide)

Extracted beats

Page 13: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

13

0 150 300

chf11 chf10

0 1000-3

-2

-1

0

1

BIDMC Congestive Heart

Failure Database: chf10

BIDMC Congestive Heart

Failure Database: chf11

Extracted beats

Without normalization, the results are very poor, some blue heartbeats are closer to red heartbeats than there are to another blue beat .

With normalization, the results are perfect.

Un-normalized Normalized

In this example, we extracted heartbeats from two different time series, and clustered them with and without normalization.

The Importance of z-Normalization and correlation 2 of 2

Surprisingly z-normalizing can be a computational bottleneck, but later we will show you how to fix that.

Page 14: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

14

What is Dynamic Time Warping?

• DTW is an algorithm for measuring similarity between two time series which may vary (i.e. warp) in timing.

DTWEuclidean Distance

• This invariance to warping is critical in many domains, for many tasks.

• Without warping invariance, we are often condemned to very poor results.

Page 15: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

15

C

QC

Q

How is DTW Calculated? I

We create a matrix the size of |Q| by |C|, then fill it in with the distance between every possible pair of points in our two time series.

Page 16: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

16

C

Q

How is DTW Calculated? II

C

Q

Warping path w

KwCQDTWK

k k1min),(

Every possible warping between two time series, is a path through the matrix. We want the best one…

This recursive function gives us the minimum cost path

(i,j) = d(qi,cj) + min{ (i-1,j-1), (i-1,j ), (i,j-1) }

Page 17: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

17

Let us visualize the cumulative matrix on a real world problem I

This example shows two one-week periods from an electrical power demand time series.

Note that although they both describe 4-day work weeks, the blue sequence had Monday as a holiday, and the red sequence had Wednesday as a holiday.

Page 18: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

18

DTW is a Distance Measure, not a Metric 1 of 2

Requirements to be a metric D(A,B) = D(B,A) Symmetry

D(A,A) = 0 Constancy of Self-Similarity

D(A,B) = 0 IIf A=B Positivity (Separation)

D(A,B) D(A,C) + D(B,C) Triangular Inequality

Yes for DTW

No for DTW

Normally we prefer metrics over measures for two reasons:

• Non-Metrics can sometimes give pathological solutions when clustering or classifying data etc.• Almost all speed-up “tricks” for high dimensional data exploit the Triangular Inequality.

Page 19: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

19

C

Q

Sakoe-Chiba Band

Understanding w, the Warping Constraint

We need to understand wbecause:

• The most useful speedup tricks all exploit w.

• The value chosen for wcan greatly affect accuracy.

n

The value of w is the maximum amount the warping path is allow to deviate from the diagonal.

It is normally expressed as the ratio

w = r/n (or as a percentage)

r

Page 20: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

20

Generalizing to Multi-Dimensional Data 1 of 3

It is increasingly common to encounter Multi-Dimensional (MD) time series data. Here we measure the X-axis acceleration of both the left and right hand.

There are two obvious ways to compute the MD DTW score.

Independent: Just compute the DTW score for each dimension independently, and sum up each score.

Dependent: Create a single distance matrix that reflect the distance between each corresponding pair of time series, then find the single warping path and distance as per normal.

Q

C

x

y

x

y

DTWI(Q,C) = DTW(Qx,Cx) + DTW(Qy,Cy) = 2.4

DTWD(Q,C) = DTW({Qx,Qy},{Cx,Cy}) = 3.2

Given these pair of 2D objects…

Page 21: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

21

Generalizing to Multi-Dimensional Data 2 of 3

So, of DTWI and DTWD which is best?

Lets think of it this way:

The thing we want classify is an physical process, the utterance of the word “bicycle”, the beat of a heart, an autograph, a tennis shot etc.

We cannot see the actual event, just 2 or more time series it created.•If the physical process affects the time series simultaneously, then DTWD will probably be best. We call this the tightly coupled case.

•If the physical process affects the time series with varying lags, then DTWI will probably be best. We call this the loosely coupled case.

Example: Suppose we measure the directionless acceleration of the left and right wrists of a tennis player.

The “physical process” is a backhand stoke. If a two-handed backstroke, the two time series are tightly coupled. If a one-handed backhand, the two hands will be very loosely coupled .

Jo-Wilfried Tsonga

Page 22: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Generalizing to Multi-Dimensional Data 3 of 3

We can demonstrate the claim in the last slide with experiments.

Let us begin with a dataset that we are 100% sure is tightly coupled, then slowly add some random time lags into the data…

0 5 10 15 20 25 30 35 400.4

0.5

0.6

0.7

0.8

DTWDDTWI

Erro

r R

ate

More Random Lag

We know that the handwriting dataset is tightly coupled. We find that DTWD has an error-rate of about 0.42, much better than that DTWI has an error-rate of about 0.55.

However, as we uncouple the perfect synchronization by adding some random lag, DTWD quickly gets worse, while that DTWI is barely effected.

handwriting dataset

Page 23: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Longest Common Subsequence Measures

(Allowing for Gaps in Sequences)

Gap skipped

M. Vlachos, G. Kollios and D. Gunopulos, "Discovering similar multidimensional trajectories," ICDE 2002, pp. 673-684.

Page 24: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Longest Common Subsequence (LCSS)

ignore majority

of noise

match

match

Advantages of LCSS:

A. Outlying values not matched

B. Distance/Similarity distorted less

C. Constraints in time & space

Disadvantages of DTW:

A. All points are matched

B. Outliers can distort distance

C. One-to-many mapping

LCSS is more resilient to noise than DTW.

Page 25: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Longest Common SubsequenceSimilar dynamic programming solution as DTW, but

now we measure similarity not distance.

Can also be expressed as distance

𝐿𝐶𝑆𝑆 𝑖, 𝑗 =

00

1 + 𝐿𝐶𝑆𝑆[𝑖 − 1, 𝑗 − 1]

max(𝐿𝐶𝑆𝑆 𝑖 − 1, 𝑗 , 𝐿𝐶𝑆𝑆 𝑖, 𝑗 − 1 )

𝑖𝑓 𝑖 = 0𝑖𝑓 𝑗 = 0

𝑖𝑓 𝑎𝑖,𝑘 − 𝑏𝑗,𝑘 < 𝜖

otherwise

𝐷𝐿𝐶𝑆𝑆 𝐴, 𝐵 = 1 −𝐿𝐶𝑆𝑆𝛿,𝜖(𝐴, 𝐵)

min 𝑛,𝑚 𝑜𝑟 max(𝑛,𝑚)

Page 26: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

26

Preprocessing

Uniform Scaling

O(n)

Z-Normalization

O(n)

Rotation Invariance

O(n)

Euclidean Distance

O(n)

Cross-correlation

O(n log n)

Sliding Distance

O(n log n)

Complexity Invariance

O(n)

Length Normalization

O(n)

Alignment Postprocessing

Various extensions of lock-step measures

• Preprocessing • Alignment• Postprocessing

Let us assume that a sin wave should match with another sin wave without considering phase, amplitude, frequency, noise, etc.

1. Michail Vlachos, D. Gunopulos, and Gautam Das. 2004. Rotation invariant distance measures for trajectories. KDD '04. 707-712.

2. Dragomir Yankov, Eamonn J. Keogh, Jose Medina, Bill Yuan-chi Chiu, Victor B. Zordan: Detecting time series motifs under uniform scaling. KDD 2007: 844-853

3. Lexiang Ye, Eamonn J. Keogh: Time series shapelets: a new primitive for data mining. KDD 2009: 947-956

4. Gustavo E. A. P. A. Batista, Xiaoyue Wang, Eamonn J. Keogh: A Complexity-Invariant Distance Measure for Time Series. SDM 2011: 699-710

Page 27: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Other Similarity Measures

• Move-Split-Merge (MSM) to achieve both dynamic alignment and metric properties

• MUNICH, PROUD, DUST: Similarity measure for uncertain time series

27

We will consider Euclidean distance and Dynamic Time Warping distance as representatives

1. Alexandra Stefan, Vassilis Athitsos, Gautam Das: The Move-Split-

Merge Metric for Time Series. IEEE Trans. Knowl. Data Eng. 25(6):

1425-1438 (2013)

2. Smruti R. Sarangi and Karin Murthy. 2010. DUST: a generalized notion of similarity between uncertain time series. KDD '10 , 383-392.

3. M. Yeh, K. Wu, P. Yu, and M. Chen. PROUD: a probabilistic approach to processing similarity queries over uncertain data streams. In EDBT, pages 684–695. ACM, 2009.

4. J. Aßfalg, H.-P. Kriegel, P. Kr¨oger, and M. Renz. Probabilistic similarity search for uncertain time series. In SSDBM, pages 435–443, 2009.

Page 28: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

28

Page 29: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

29

Top-level Outline

•Similarity Measures

•Similarity Search• Lock-step search (e.g. Correlation Search)• Elastic search (e.g. DTW search)

Page 30: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Generic Search

query

original

DBFinal

Answer

set

Computational cost: O(m n)

m

Page 31: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

GEMINI Framework*

Solution: Quick-and-dirty filter:

• extract k features

• map into a point in k-d feature space

• organize points with off-the-shelf spatial access method (‘SAM’)

• retrieve the answer using a NN query

• discard false alarms

C. Faloutsos, M. Ranganathan, and Y. Manolopoulos. Fast subsequence matching in time-series databases. In Proceedings 1994 ACM SIGMOD Conference, Mineapolis, MN, USA, 1994.

* R. Agrawal, C.Faloutsos, and A.Swami. Efficient similarity search in sequence databases. In FODO Conference, volume 730, 1993.

Page 32: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Generic Search

query

simplified

query

Index on

simplified

data

original

DBAnswer

Superset

Verify

against

original

DB

Final

Answer

set

Computational cost: O(m log n)

Page 33: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

GEMINI: Key Requirement

• GEMINI works when:Dfeature(F(x), F(y)) ≤ D(x, y)

to ensure zero false negatives

• Dfeature is a metric to have working Spatial Indexes

• Dfeature is significantly inexpensive compared to D to gain efficiency

Page 34: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

DLB(Q',S')

DLB(Q',S')

S

Q

D(Q,S)

n

iii sq

1

2

D(Q,S)

Exact (Euclidean) distance D(Q,S) Lower bounding distance DLB(Q,S)

Q'

S'

Lower bounding means that for all Q and S, we have…

DLB(Q’,S’) D(Q,S)

What is lower bounding?

M

i ii sq1

2)(

Page 35: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

35

Lower Bound 1:DFT Coefficients

Discrete Fourier Transform (DFT) 𝑋𝑓 =1

𝑛

𝑡=0

𝑛−1

𝑥𝑡𝑒−𝑗

2𝜋𝑓𝑡𝑛

𝑥𝑡 =1

𝑛

𝑓=0

𝑛−1

𝑋𝑓𝑒+𝑗

2𝜋𝑓𝑡𝑛Inverse DFT

𝑗 = −1

Property 1: DFT is an orthonormal transform,

σ𝑥𝑡2 = σ 𝑋𝑓

2 σ 𝑥𝑡 − 𝑦𝑡

2 = σ 𝑋𝑓 − 𝑌𝑓2

Property 2: DFT of a real sequence is symmetric in magnitude. Thus we need only half of the transform.

20 40 60 80 100 120051015202530354045

20 40 60 80 100 120-2024681012141618

FrequencyTime

Ener

gy

Ob

serv

atio

ns

DFT

Page 36: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

36

Lower Bound 1:DFT based Lower Bound

Real time series contains most of the energy in few frequencies, commonly in the first few.

𝑛

𝑥𝑡 − 𝑦𝑡2 = 2

𝑛/2

𝑋𝑓 − 𝑌𝑓2≥ 2

𝑘

𝑋𝑓 − 𝑌𝑓2

If we take the difference between any subset of k coefficients, we get a lower bound

Page 37: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

0 20 40 60 80 100 120 140

C

0.4995

0.5264

0.5523

0.5761

0.5973

0.6153

0.6301

0.6420

0.6515

0.6596

0.6672

0.6751

0.6843

0.6954

0.7086

0.7240

0.7412

0.7595

0.7780

0.7956

0.8115

0.8247

0.8345

0.8407

0.8431

0.8423

0.8387

Raw

Data

The graphic shows a time series

with 128 points.

The raw data used to produce the

graphic is also reproduced as a

column of numbers (just the

first 30 or so points are

shown).n = 128

Lower Bound 1:Example

Page 38: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

0 20 40 60 80 100 120 140

C

. . . . . . . . . . . . . .

1.5698

1.0485

0.7160

0.8406

0.3709

0.4670

0.2667

0.1928

0.1635

0.1602

0.0992

0.1282

0.1438

0.1416

0.1400

0.1412

0.1530

0.0795

0.1013

0.1150

0.1801

0.1082

0.0812

0.0347

0.0052

0.0017

0.0002

...

Fourier

Coefficients

0.4995

0.5264

0.5523

0.5761

0.5973

0.6153

0.6301

0.6420

0.6515

0.6596

0.6672

0.6751

0.6843

0.6954

0.7086

0.7240

0.7412

0.7595

0.7780

0.7956

0.8115

0.8247

0.8345

0.8407

0.8431

0.8423

0.8387

Raw

Data

We can decompose the

data into 64 pure sine

waves using the Discrete

Fourier Transform (just the

first few sine waves are

shown).

The Fourier Coefficients

are reproduced as a

column of numbers (just

the first 30 or so

coefficients are shown).

Lower Bound 1:Example

Page 39: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

0 20 40 60 80 100 120 140

C 1.5698

1.0485

0.7160

0.8406

0.3709

0.4670

0.2667

0.1928

Truncated

Fourier

Coefficients

C’

We have

discarded

of the data.16

15

1.5698

1.0485

0.7160

0.8406

0.3709

0.4670

0.2667

0.1928

0.1635

0.1602

0.0992

0.1282

0.1438

0.1416

0.1400

0.1412

0.1530

0.0795

0.1013

0.1150

0.1801

0.1082

0.0812

0.0347

0.0052

0.0017

0.0002

...

Fourier

Coefficients

0.4995

0.5264

0.5523

0.5761

0.5973

0.6153

0.6301

0.6420

0.6515

0.6596

0.6672

0.6751

0.6843

0.6954

0.7086

0.7240

0.7412

0.7595

0.7780

0.7956

0.8115

0.8247

0.8345

0.8407

0.8431

0.8423

0.8387

Raw

Data

n = 128

k = 8

Only k coefficients can provide a good approximation of the data and produce an inexpensive lower bound.

Page 40: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

baabccbc

Lower Bound 2:Symbolic Aggregate ApproXimation (SAX)

Page 41: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

00 20 40 60 80 100 120

baabccbc

First convert the time series to PAA representation, then convert the PAA to symbols

It take linear time

bb

b

a

c

c

c

a

20 40 60 80 100 120

PAA

C

Lower Bound 2:How to obtain SAX

Page 42: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Visual Comparison

A raw time series of length 128 is transformed into the

word “ffffffeeeddcbaabceedcbaaaaacddee.”– We can use more symbols to represent the time series since each symbol

requires fewer bits than real-numbers (float, double)

DFT

PLA

Haar

APCA

a

bcde

f

Page 43: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

= baabccbcC

= babcaccaQ

w

i iiwn cqdistCQMINDIST

1

2)ˆ,ˆ()ˆ,ˆ(

dist() can be implemented using a

table lookup.

PAA distance

lower-bounds

the Euclidean

Distance

w

i iiw

n cqCQDR1

2),(

0 20 40 60 80 100 120

-1.5

-1

-0.5

0

0.5

1

1.5

ҧ𝐶

ത𝑄

0 20 40 60 80 100 120

-1.5

-1

-0.5

0

0.5

1

1.5

Q

w

i iiw

n cqCQDR1

2),(

Euclidean DistanceC

Lower Bound 2:SAX provides a lower bound

Page 44: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Time Series Representations

Data Adaptive Non Data Adaptive

SpectralWavelets PiecewiseAggregate

Approximation

Piecewise Polynomial

SymbolicSingularValue

Decomposition

RandomMappings

PiecewiseLinear

Approximation

AdaptivePiecewiseConstant

Approximation

DiscreteFourier

Transform

DiscreteCosine

Transform

Haar Daubechiesdbn n > 1

Coiflets Symlets

Sorted Coefficients

Orthonormal Bi-Orthonormal

Interpolation Regression

Trees

Natural Language

Strings

0 20 40 60 80 100 120 0 20 40 60 80 100 120 0 20 40 60 80 100 120 0 20 40 60 80 1001200 20 40 60 80 100 120 0 20 40 60 80 100120

DFT DWT SVD APCA PAA PLA

0 20 40 60 80 100120

SYM

UUCUCUCD

UU

CU

CU

DD

Page 45: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

GEMINI: Other Assumptions

• The database consists of fixed length time series and the query length matches the length of the database• Not true for most real-application (e.g. seismology,

physiology)

• The method is exact• Does not sell accuracy for speed

• The time series in the database are independent• Not true for subsequence search

45

Page 46: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Generic Prefix-based Search

query

Prefix of

simplified

query

Index on

prefixes of

simplified data

original

DBAnswer

Superset

Verify

against

original

DB

Final

Answer

set

Computational cost: O(m log n)

Page 47: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Prefix distance is not a lower bound of the original distance

1. Two time series 𝒙 and 𝒚 of length 𝑚

2. Prefix distance is a trivial lower bound of un-normalized distance

3. Normalized Euclidean distance 𝑑 ෝ𝒙, ෝ𝒚 , can increase or decrease if we extend ෝ𝒙and ෝ𝒚 by appending the next two numbers.

1 2 3 4 5

345678910

Without Normalization

Values Changed

1 2 3 4 5-4-3-2-101234

With Normalization

Page 48: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Lower-bound upon extension 1 of 3

1 2 3 4 5-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

1 2 3 4 5-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

1 2 3 4 5-2

-1.5

-1

-0.5

0

0.5

1

1.5

2

Length 4 Length 5 Length 5

Append 10 and re-normalize Append 20 and re-normalizeNormalized

Area between blue and red is the distance between the signals

If infinity is appended to both the signals, they will have zero area/distance.

Page 49: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Lower-bound upon extension 2 of 3

• 𝑑𝐿𝐵2 ෝ𝒙+1, ෝ𝒚+1 =

1

𝜎𝑚2 𝑑𝑚

2 ෝ𝒙, ෝ𝒚 < 𝑑𝑚2 (ෝ𝒙, ෝ𝒚)

Variances of ෝ𝒙+1and ෝ𝒚+1, 𝜎𝑚2 =

𝑚

𝑚+1+

𝑚

𝑚+1 2 𝑧2

𝑧 = maximum normalized value in the databaseA safe approximation of 𝑧 = max(𝑎𝑏𝑠 ෝ𝒙 , 𝑎𝑏𝑠 ෝ𝒚 )

Abdullah Mueen: Enumeration of Time Series Motifs of All Lengths. ICDM 2013: 547-556

Page 50: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Lower-bound upon extension 3 of 3

0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

x 1050

5

10

15

20

25

30

35

Pairs in ascending order of distances

Norm

aliz

ed D

ista

nce

Blue: Distances of random signals of length 255Yellow: Distances of the signals when they are extended by one random sample Red: The upper and lower bounds before observing the extensions

2 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3x 105

20

20.5

21

21.5

22

22.5

23

23.5

24

24.5

25

Page 51: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

ϵ - Approximate Correlation(1)

• Result: given ϵ, compute k

• Smooth Signal k is small for small ϵ

0 200 400 600 800 1000-2

-1

012

……

0 200 400 600 800 1000-4-2

024

……

DFT

DFT

Length m

Length m

Reduce scanning cost from O(m) to O(k)

Exact correlation ci,j

Compute lower boundin frequency domain

Approx corr. ci,j ± ϵ

Length k

Page 52: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Example: ϵ=0.1

0 200 400 600 800 1024

-2

0

2 Signal x

0 200 400 600 800 1024

-2

0

2 Signal y

Prefix length for time domain1014 1017

k = max(kx,ky) = 18 For most signals k << m

0 100 250

0.1

0.3

0.5

DFT

0 100 250

0.1

0.3

0.5

DFT Y

kx= 14 ky= 18

Prefix Length

𝑐𝑜𝑟𝑟 𝑥, 𝑦 − 0.1 < 1 − σ𝑖𝑘 |𝑋𝑖 − 𝑌𝑖|

2 < 𝑐𝑜𝑟𝑟 𝑥, 𝑦 + 0.1

Abdullah Mueen, Suman Nath, Jie Liu: Fast approximate correlation for massive time-series data. SIGMOD Conference 2010: 171-182

Page 53: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

GEMINI: Other Assumptions

• The database consists of fixed length time series and the query length matches the length of the database• Not true for most real-application (e.g. seismology,

physiology)

• The method is exact• Does not sell accuracy for speed

• The time series in the database are independent• Not true for subsequence search

53

Page 54: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Subsequence Similarity Search

• Subsequences have large overlaps that GEMINI does not exploit

• Normalization makes it difficult to exploit the overlaps

• Two techniques to exploit overlaps• just-in-time normalization with constant overhead per

comparison• MASS: Mueen’s Algorithm for Similarity Search using

convolution

54

100 200 300 400 500 600 700 800 900 1000

-8000

-7500

-7000

12345678...

873

time:1000

Page 55: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Just-in-time Normalization

• In one pass, calculate cumulative sums of over x and x2 and store

• Subtract two cumulative sums to obtain the sum over a window

• Use the sums to calculate the means and standard deviations of all windows in linear time

• Dynamically normalize observations when calculating distance and possibly abandon early

55

𝐶 = σ𝑥 𝐶2 = σ𝑥2

𝑆𝑖2 = 𝐶𝑖+𝑤

2 − 𝐶𝑖2𝑆𝑖 = 𝐶𝑖+𝑤 − 𝐶𝑖

𝜇𝑖 =𝑆𝑖𝑤

𝜎𝑖 =𝑆𝑖2

𝑤−

𝑆𝑖𝑤

2

𝑐𝑜𝑠𝑡 =𝑥𝑖𝑗 − 𝜇𝑥𝑖

𝜎𝑥𝑖−𝑞𝑖 − 𝜇𝑞𝑖𝜎𝑞𝑖

2

Thanawin Rakthanmanon, et al. Searching and mining trillions of time series subsequences under dynamic time warping. KDD 2012: 262-270

Page 56: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Early Abandoning

y

x

d(x,y)

Given two time series

x = x1…xn

and

y = y1…yn

their z-Normalized Euclidean distance is

defined as:

Early abandoning reduces number of operations when minimizing

56

0 10 20 30 40 50 60 70 80 90-2

0

2sum of squared error exceeded best2

d(x,y)ෝ𝑥𝑖 =

𝑥𝑖 − 𝜇𝑥𝜎𝑥

ෝ𝑦𝑖 =𝑦𝑖 − 𝜇𝑦

𝜎𝑦

𝑑 𝑥, 𝑦 =

𝑖=1

𝑛

( ෝ𝑥𝑖 − ෝ𝑦𝑖)2

Page 57: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Mueen’s Algorithm for Similarity Search (MASS) (1 of 4)

• Convolution based method• 𝑂(𝑛 log 𝑛) cost to obtain all the sliding dot products

• On-the-fly normalization• Use the dot products to calculate normalized distances

in 𝑂(𝑛) cost

57

Chin-Chia Michael Yeh, Yan Zhu, Liudmila Ulanova, Nurjahan Begum, Yifei Ding, Hoang Anh Dau, Diego Furtado Silva, Abdullah

Mueen, Eamonn Keogh (2016). Matrix Profile I: All Pairs Similarity Joins for Time Series: A Unifying View that Includes Motifs,

Discords and Shapelets. IEEE ICDM 2016.

http://www.cs.unm.edu/~mueen/FastestSimilaritySearch.html

Page 58: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Mueen’s Algorithm for Similarity Search (MASS) (2 of 4)

• Double the time series by appending zeros

• Reverse the normalized query and append zeros to match length

• Use FFT based convolution technique• 𝑖𝑓𝑓𝑡( 𝑓𝑓𝑡(𝑥). 𝑓𝑓𝑡(𝑦) )

58

Output

InputX1 0 Y2

Streaming Time Series Pattern

0 0 0 0 0 0 0 0 0X2 X3 X4 Y1

0 0 0 0 0 0 0 0 0 0Y2X1 Y2X2+Y1X1 Y1X4Y2X2+Y1X1 Y2X4+Y1X3

Page 59: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Mueen’s Algorithm for Similarity Search (MASS) (3 of 4)

• Since query is normalized, we reform the distance function by applying σ𝑦 = 0,σ𝑦2 = 𝑛

• 𝑑2 𝑥, 𝑦 = σ𝑥−𝜇𝑥

𝜎𝑥− 𝑦

2

=σ𝑥2 − 2σ𝑥𝜇𝑥 + 𝑛𝜇𝑥

2

𝜎𝑥2 − 2

σ𝑥𝑦

𝜎𝑥+ 𝑛

• The distance can be calculated by using the sliding dot products and cumulative sums

59

Page 60: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Mueen’s Algorithm for Similarity Search (MASS) (4 of 4)

• Produces a “distance profile” of the query to the subsequences of the time series. Every distance is reported, nothing is abandoned

• Can be used to answer K-NN queries, range queries, and density estimation all at the same time

• Data and query independent execution.

• Can be further optimized when multiple queries are issued

60

Page 61: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

61

Page 62: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

62

Top-level Outline

•Similarity Measures

•Similarity Search• Lock-step search (e.g. Correlation Search)• Elastic search (e.g. DTW search)

Page 63: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Similarity Search under DTW

• The general conception: DTW is slow and we have a never-ending need for speed

• Better performance in knowledge extraction

• Better scalability to process BigData

• Better interactivity in human driven data analysis

63

Page 64: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

What can be made fast?

• One-to-One comparison• Exact Implementation and Constraints• Efficient Approximation• Exploiting Sparsity

• One-to-Many comparisons• Nearest Neighbor Search

• In subsequences of a long time series• Density Estimation

• In clustering • Averaging Under Warping

• In classification

• Many-to-Many comparisons• All-pair Distance Calculations

64

Page 65: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Speeding up DTW: one-to-one

• One-to-One comparison• Exact Implementation

• Efficient Constraints

• Exploiting Hardware

• Efficient Approximation

• Exploiting Sparsity

65

Page 66: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Simplest Exact Implementation

66

0 5 10 15 20 25

D(1:n+1,1:m+1) = inf;

D(1,1) = 0;

for i = 2 : n+1 %for each row

for j = 2 : m+1 %for each column

cost = (x(i-1)-y(j-1))^2;

D(i,j) = cost + min( [ D(i-1,j), D(i,j-1), D(i-1,j-1) ]);

d = sqrt(D(n+1,m+1));

𝑂(𝑛2) time𝑂(𝑛2) space

Input: x and y are time series of length n and mOutput: DTW distance d between x and y

Page 67: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Simplest Implementation (Constrained)

67

D(1:n+1,1:m+1) = inf;

D(1,1) = 0;

w = max(w, abs(n-m));

for i = 2 : n+1

for j = max(2,i-w) : min(m+1,i+w)

cost = (x(i-1)-y(j-1))^2;

D(i,j) = cost + min( [ D(i-1,j), D(i,j-1), D(i-1,j-1) ]);

d = sqrt(D(n+1,m+1));6767

0 5 10 15 20 25 30

𝑂(𝑛𝑤) time𝑂(𝑛2) space

𝑤

Page 68: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Memoization

68

1 2 2 1 2 3 4 5 3 2 1

1 3 3

D(2,1:m+1) = inf;

D(1,1) = 0;

p = 1; c = 2;

for i = 2 : n+1

for j = 2 : m+1

cost = (x(i-1)-y(j-1))^2;

D(c,j) = cost + min( [ D(p,j), D(c,j-1), D(p,j-1) ]);

swap(c,p);

d = sqrt(D(n+1,m+1));

Previous Row

Current Row

𝑂(𝑛2) time𝑂(𝑛) space

Page 69: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Hardware Acceleration

• Single Instruction Multiple Data (SIMD) architecture

• Cells on a diagonal are computed in parallel

• Values of a diagonal depend on the previous two diagonals

69

𝑂(𝑛) time𝑂(𝑛) space

Page 70: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

PAA based approximation

70

1 2 3 4 5 6 7

𝑂𝑛

𝑤

2time

𝑂𝑛

𝑤

2space

Piecewise Aggregate Approximation𝑤

Selina Chu, Eamonn J. Keogh, David M. Hart, Michael J. Pazzani: Iterative Deepening Dynamic Time Warping for Time Series. SDM 2002: 195-212

Page 71: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Approximation by Length-encoding

71

0 2 4 6 8 10 11

0

1

1 0 0 0 1 0 0 0 1 1 0 0 0 1

1 0 0 0 0 1 0 0 0 0 1

0

1

0 2 4 6 8 10 12 14

1 (4) 1 (4) 1

1 (3) 1 (3) 1 1 (3) 1

To exploit sparsity,encode lengths of the

runs of zeros

A Mueen, N Chavoshi, N Abu-El-Rub, H Hamooni, A Minnich, Fast Warping Distance for Sparse Time Series, ICDM 2016. http://www.cs.unm.edu/~mueen/Projects/AWarp/awarp.pdf

Page 72: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

1 0 0 0 0 1 0 0 0 0 1

1 0 1 2 3 4 4 5 6 7 8 8

0 1 0 0 0 0 1 1 1 1 1 2

0 2 0 0 0 0 1 1 1 1 1 2

0 3 0 0 0 0 1 1 1 1 1 2

1 3 1 1 1 1 0 1 2 2 2 1

0 4 1 1 1 1 1 0 0 0 0 1

0 5 1 1 1 1 2 0 0 0 0 1

0 6 1 1 1 1 2 0 0 0 0 1

1 6 2 2 2 2 1 1 1 1 1 0

1 6 3 3 3 3 1 2 2 2 2 0

0 7 3 3 3 3 2 1 1 1 1 1

0 8 3 3 3 3 3 1 1 1 1 2

0 9 3 3 3 3 4 1 1 1 1 2

1 9 4 4 4 4 3 2 2 2 2 1

Exploiting Sparsity (1)

72

0 2 4 6 8 10 11

0

1

0

1

0 2 4 6 8 10 12 14

y

x

Page 73: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

1 0 0 0 0 1 0 0 0 0 1

1 0 1 2 3 4 4 5 6 7 8 8

0 1 0 0 0 0 1 1 1 1 1 2

0 2 0 0 0 0 1 1 1 1 1 2

0 3 0 0 0 0 1 1 1 1 1 2

1 3 1 1 1 1 0 1 2 2 2 1

0 4 1 1 1 1 1 0 0 0 0 1

0 5 1 1 1 1 2 0 0 0 0 1

0 6 1 1 1 1 2 0 0 0 0 1

1 6 2 2 2 2 1 1 1 1 1 0

1 6 3 3 3 3 1 2 2 2 2 0

0 7 3 3 3 3 2 1 1 1 1 1

0 8 3 3 3 3 3 1 1 1 1 2

0 9 3 3 3 3 4 1 1 1 1 2

1 9 4 4 4 4 3 2 2 2 2 1

Exploiting Sparsity (2)

73

0 4 4 8 83 0 1 1 23 1 0 2 16 1 2 0 16 2 1 1 06 3 1 2 09 3 4 1 29 4 3 2 1

1 (4) 1 (4) 1

1(3)

1(3)

11

(3)1

y

x X

Y

0 2 4 6 8 10 11

0

1

0

1

0 2 4 6 8 10 12 14

Page 74: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Exploiting Sparsity (2)

74

0

2

4 0

2

4

0 1 4

1

1 0

1 2 3 4 5 6

Correct Alignment

No change Lower bound

0 4

1

1 0

0

2

4 0

2

4

1 2 3 4 5 6

Missing Alignment

0 1 1 4

1

1 0

0

2

4 0

2

4

1 2 3 4 5 6

Linear change Upper bound

0 1 1 4

1

1 0

0

2

4 0

2

4

1 2 3 4 5 6

Extra Alignment

0 1 2 11 111 4 5 6 75 10 13 6 106 5 5 21 76 6 6 14 7

1 2

3 0

1

1 0 0 4 1

x

y

0 2 11 111 4 6 75 10 5 96 5 21 66 6 14 6

1 2

3 (1

) 1

1 (2) 4 1

x

y y

0 2 11 111 6 6 75 15 7 106 5 21 86 6 14 8

1 (2) 4 1

x

y

0 2 11 111 6 6 75 15 7 106 5 21 86 6 14 8

1 2

3 (1

) 1

1 (2) 4 1

x

Sub-Linear change Exact Distance

Page 75: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Exploiting Sparsity (3)

75

Normal Distribution

2 4 8 12 16 24 3210

20

30

40

50

60

70

80

90

100

Sparsity Factor

Pe

rcen

tage

Awarp_UB ≤ 1.05 * DTWAWarp_UB = DTWAWarp_LB = DTW

Uniform Distribution

Awarp_UB ≤ 1.05 * DTWAWarp_UB = DTWAWarp_LB = DTW

2 4 8 12 16 24 32

Sparsity Factor

10

20

30

40

50

60

70

80

90

100

Pe

rcen

tage

Exponential Distribution

20

30

40

50

60

70

80

90

100

2 4 8 12 16 24 32

Sparsity Factor

Awarp_UB ≤ 1.05 * DTWAWarp_UB = DTWAWarp_LB = DTW

Per

cen

tage

30

40

50

60

70

80

90

100

Awarp_UB ≤ 1.05 * DTWAWarp_UB = DTWAWarp_LB = DTW

2 4 8 12 16 24 32

Sparsity Factor

Pe

rcen

tage

Binomial Distribution

Sparsity Factor of s

means 1

𝑠% of the time

series is filled with non-zeros.

Page 76: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

What can be made fast?

• One-to-One comparison• Exact Implementation and Constraints• Efficient Approximation• Exploiting Sparsity

• One-to-Many comparisons• Nearest Neighbor Search

• In subsequences of a long time series• Density Estimation

• In clustering • Averaging Under Warping

• In classification

• Many-to-Many comparisons• All-pair Distance Calculations

77

Page 77: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Nearest Subsequence Search

• A Q query is given

• A long time series of length n

• O(n) distance calculations are performed to

78

Find THE nearest subsequence of the given query under DTW.

100 200 300 400 500 600 700 800 900 1000

-8000

-7500

-7000

12345678...

873

time:1000

Page 78: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Brute Force Subsequence Search

79

1. best_so_far = infinity;2. for all sequences in database3.4.5.6. if true_dist < best_so_far7. best_so_far = true_dist;8. index_of_best_match = i;9. endif10.11. endfor

Algorithm

1. best_so_far = infinity;2. for all sequences in database3.4.5.6. if true_dist < best_so_far7. best_so_far = true_dist;8. index_of_best_match = i;9. endif10.11. endfor

Algorithm Sequential_Scan(Q)

true_dist = DTW(Ci ,Q);

Computational cost: O(nm2)

Page 79: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Lower Bounding Nearest Neighbor Search

80

We can speed up similarity search under DTW by using a lower bounding function

1. best_so_far = infinity;2. for all sequences in database3.4. if LB_dist < best_so_far5.6. if true_dist < best_so_far7. best_so_far = true_dist;8. index_of_best_match = i;9. endif10. endif11. endfor

Algorithm Lower_Bounding_Sequential_Scan(Q)

1. best_so_far = infinity;2. for all sequences in database3.4. if LB_dist < best_so_far5.6. if true_dist < best_so_far7. best_so_far = true_dist;8. index_of_best_match = i;9. endif10. endif11. endfor

Algorithm Lower_Bounding_Sequential_Scan(Q)

Only do the expensive, full calculations when it is absolutely necessary

Try to use a cheap lower bounding calculation as often as possible.LB_dist = lower_bound_distance(Ci ,Q);

true_dist = DTW(Ci ,Q);

Page 80: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

A

B

C

D

The squared difference between the two sequence’s first (A), last (D), minimum (B) and maximum points (C) is returned as the lower bound

Kim, S, Park, S, & Chu, W. An index-based approach for similarity search supporting time warping in large sequence databases. ICDE 01, pp 607-614

LB_Kim

Lower Bound of Kim

81

𝑂(1) time if considered only first and last points

𝑂(𝑛) time for all four distances

Page 81: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Lower Bound of Yi

82

The sum of the squared length of white lines represent the minimum contribution of the observations above and below the yellow lines.

Yi, B, Jagadish, H & Faloutsos, C. Efficient retrieval of similar time sequences under time warping. ICDE 98, pp 23-27.

max(Q)

min(Q)LB_Yi

𝑂(𝑛) time

Page 82: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

L

U

Q

C

Q

Sakoe-Chiba Band

Ui = max(qi-w : qi+w)Li = min(qi-w : qi+w)

Lower Bound of Keogh

83

CU

LQ

Envelope-Based Lower Bound

n

i

iiii

iiii

otherwise

LqifLq

UqifUq

CQKeoghLB1

2

2

0

)(

)(

),(_

𝑂(𝑛) time

Page 83: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

CU

LQ

Reversing the Query/Data Role in LB_Keogh

• Make LB_Keogh tighter• Much cheaper than DTW• U/L envelops on the

candidates can be calculated online or pre-calculated

84

Envelop on Q

CU

LQ

Envelop on C

max(LB_KeoghEQ, LB_KeoghEC)

Page 84: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

LB_KeoghSakoe-Chiba

LB_KeoghItakura

LB_Yi

LB_Kim

The tightness of the lower bound for each technique is proportional to the length of lines used in the illustrations

85

Page 85: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Cascading Lower Bounds• At least 18 lower bounds of DTW was proposed.

• Use lower bounds only on the Skyline.

• Use the bounds on the skyline in cascade from least expensive to most expensive

• When unable to prune, use early abandoning techniques

86

0

1

O(1) O(n) O(nR)

LB_KimFLLB_KeoghEQ

max(LB_KeoghEQ, LB_KeoghEC)

Early_abandoning_DTW

LB_Kim

LB_Yi

Tig

htn

ess o

f

low

er

bo

und

LB_Ecorner

LB_FTW DTW

LB_PAA

99.9% of the time DTW is not calculated

Page 86: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Early Abandoning Techniques

Abandon accumulating errors as soon as the current total is larger than the best_so_far

Four techniques to abandon early

1. Early Abandoning of LB_Keogh

2. Early Abandoning of DTW

3. Earlier Early Abandoning of DTW using LB_Keogh

4. Reordering Early Abandoning

87

Page 87: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Early Abandoning of LB_Keogh

88

U, L are upper and lower envelopes of Q

CU

LQ

Abandon the computation, when the accumulated error is larger than best_so_far

Page 88: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Early Abandoning of DTW

89

C

Q

w (Warping Windows)

dtw_dist

Abandon the computation, when the dtw_dist is larger than best_so_far

C

Q

Page 89: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Earlier Early Abandoning of DTWusing LB_Keogh

90

C

Q

w (Warping Windows)

(partial)dtw_dist

(partial)lb_keogh

U, L are upper and lower envelopes of Q

Abandon the computation, when the

dtw_dist + lb_keogh is larger than best_so_far

CU

LQ

Page 90: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Reordering Early Abandoning• We don’t have to compute LB from left to right.

• Order points by expected contribution.

91

- Order by the absolute height of the query point.

1 2 3 4 5 6 7 8 97 3 1 2 6

8 4 5 9

Idea

Page 91: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Summary of the techniques

Group-2 Techniques• Just-in-time Z-normalizations

• Reordering Early Abandoning

• Reversing LB_Koegh

• Cascading Lower Bounds

92

Group-1 Techniques– Early Abandoning of LB_Keogh

– Early Abandoning of DTW

– Earlier Early Abandoning of DTW using LB_Keogh

UCR SuiteCode and data is available at:

www.cs.ucr.edu/~eamonn/UCRsuite.html

Thanawin Rakthanmanon, Bilson J. L. Campana, Abdullah Mueen, Gustavo E. A. P. A. Batista, M. Brandon Westover, Qiang Zhu, Jesin Zakaria, Eamonn J. Keogh: Searching and mining trillions of time series subsequences under dynamic time warping. KDD 2012: 262-270

Page 92: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Experimental Result: Random Walk

93

Million

(Seconds)

Billion

(Minutes)

Trillion

(Hours)

DTW-Naive 75.21 1,252.2 20,869

Group-1 2.447 38.14 472.80

Group-1 and 2 0.159 1.83 34.09

• Random Walk: Varying size of the data, |Q| = 128

Extrapolated

• Experiments performed on a commodity machine• Disk is accessed sequentially as the algorithm is

invariant to data order• The computation is performed while the next disk

block is read

Page 93: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Experimental Result: Random Walk

• Random Walk: Varying size of the query, n = 20 million

94

Naïve DTW

100

1000

10000

seconds

Group-1 Techniques

For query lengths of 4,096 (rightmost part of this graph)

The times are:

Naïve DTW 24,286

Group-1 5,078

Group-1 and 2 567

Query Length

Group 1 and 2

4 5 6 7 8 9 10 11 12Power of two

Page 94: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Experimental Result: Random Walk

• Random Walk: Varying size of the band

95

0

100

200

300

400

500

600

0 5 10 15 20 25 30 35

DTW-Naïve Group-1 Group-1 and 2

Seco

nd

s

Sakoe-Chiba Band Width (percentage of query length)

Page 95: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Experimental Result: ECG

• Data: One year of Electrocardiograms 8.5 billion data points.

• Query: Idealized Premature Ventricular Contraction (PVC) of length 421 (w=21=5%).

96

Group-1 Group 1 & 2

ECG 49.2 hours 18.0 minutes

PVC (aka. skipped beat)

Page 96: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Chromosome 2: BP 5709500:5782000

Human

Chimp

Gorilla

Orangutan

Gibbon

Rhesus

macaque

Catarrhines

Hominidae

Homininae

Hominini

Hominoidea

Experimental Result: DNA• Query: Human Chromosome 2 of length 72,500 bps

• Data: Chimp Genome 2.9 billion bps

• Time: UCR Suite 14.6 hours

97

Page 97: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

What can be made fast?

• One-to-One comparison• Exact Implementation and Constraints• Efficient Approximation• Exploiting Sparsity

• One-to-Many comparisons• Nearest Neighbor Search

• In subsequences of a long time series• Density Estimation

• In clustering • Averaging Under Warping

• In classification

• Many-to-Many comparisons• All-pair Distance Calculations

98

Page 98: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Density based clustering

• Density Peaks (DP)* Algorithm• Find the densities of every point to pick cluster centers

• Connect every point to the nearest higher density point

99*Rodriguez, A., & Laio, A. (2014). Clustering by fast search and find of density peaks. Science, 344(6191), 1492-1496.

Page 99: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Range Search/Density Estimation

• Density is estimated by the number of points within a radius/threshold t

100

all sequences Ci in database1.2.

for

3.LB_dist = lower_bound_distance (Ci, Q)

4.

if LB_dist <

5.

true_dist = DTW(Ci, Q)6.

if7.8.9.

endif10.

endif11.

endfor

Algorithm Bounding_Range_Search(Q,t)

1.2.

for

3.4.

if LB_dist < t

5.6.

true_dist < t7.8.9.

endif10.11.

Algorithm

if UB_dist < t then output Cielse

output Ci

12.

UB_dist = upper_bound_distance (Ci, Q)

13.

Try to use an upper bound to identify a point within the range

Nurjahan Begum, Liudmila Ulanova, Jun Wang, Eamonn J. Keogh: Accelerating Dynamic Time Warping Clustering with a Novel Admissible Pruning Strategy. KDD 2015: 49-58

Page 100: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Density Connectedness

• Distance between a pair of points is an upper bound of the NN distance from both of the points

101

1. best_so_far =min(upper_bound_NN_distance(D,Q)2. for3. LB_dist = lower_bound_distance(4. if LB_dist < best_so_far5. true_dist = DTW(6. if true_dist < best_so_far7. best_so_far = true_dist;8. index_of_best_match = i;9. endif10. endif11. endfor

Algorithm

1. best_so_far2. for all sequences in D3.4. if LB_dist < best_so_far5. C i, Q);C i, Q);6. if true_dist < best_so_far7. best_so_far = true_dist;8. index_of_best_match = i;9. endif10. endif11. endfor

Algorithm Bounding_Scan(D,Q)

C i, Q);C i, Q);

Try to use an upper bound to the NN distance as the best_so_far

Nurjahan Begum, Liudmila Ulanova, Jun Wang, Eamonn J. Keogh: Accelerating Dynamic Time Warping Clustering with a Novel Admissible Pruning Strategy. KDD 2015: 49-58

D

Q

Page 101: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Upper bounding• Euclidean distance is a trivial upper bound

• DTW distance in a band w is an upper bound for DTW distance in band w+1

102

0 2 4 6 8 10 120

2

4

6

8

10

12

0 20

2

Euclidean Distance

DT

W D

ista

nce

Zoom-In

Page 102: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Speedup by upper bounds

103

Density Peak: 9 HoursTADPole: 9 minutes

Dis

tance

Cal

cula

tio

ns

0 3500

1

3

5

7

x 106

TADPole

Number of objects

Absolute

Number

0 35000

100

Number of objects

Brute force

TADPole

Percentages

Dis

tance

Cal

cula

tio

ns

StarLightCurves dataset

Nurjahan Begum, Liudmila Ulanova, Jun Wang, Eamonn J. Keogh: Accelerating Dynamic Time Warping Clustering with a Novel Admissible Pruning Strategy. KDD 2015: 49-58

Page 103: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

What can be made fast?

• One-to-One comparison• Exact Implementation and Constraints• Efficient Approximation• Exploiting Sparsity

• One-to-Many comparisons• Nearest Neighbor Search

• In a database of independent time series• In subsequences of a long time series

• Density Estimation• In clustering

• Averaging Under Warping• In classification

• Many-to-Many comparisons• All-pair Distance Calculations

104

Page 104: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Data Reduction for 1NN Classification• The training set is reduced to a smaller set keeping

a representative set of labeled instances

• Smaller training set entails performance gain

• Smaller training set may gain accuracy if noisy instances are filtered effectively

• Reduction methods• Random Selection

• Rank the instances and take top-K

• Cluster instances based on proximity and take representative from each cluster

105

Page 105: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Many clustering algorithms require finding a centroid of two or more instances

Compute average

The issue is then:

How to average time series consistently with DTW?

300

François Petitjean, Germain Forestier, Geoffrey I. Webb, Ann E. Nicholson, Yanping Chen, Eamonn J. Keogh: Dynamic Time Warping Averaging of Time Series Allows Faster and More Accurate Classification. ICDM 2014: 470-479

Trace dataset

106

Page 106: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Mathematically, the mean ҧ𝑜 of a set of objects 𝑂embedded in a space induced by a distance 𝑑 is:

107

argminത𝑜

𝑜∈𝑂

𝑑2 ҧ𝑜, 𝑜

The mean of a set minimizes the sum of the squared distances

If 𝑑 is the Euclidean distance

The arithmetic mean solves the problem exactly

ҧ𝑜 =1

𝑁

𝑜∈𝑂

𝑜

Arithmetic mean

Page 107: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

To solve the optimization problem for DTW distance, we need to perform simultaneous alignment of many time series.

108

But, finding the optimal multiple alignment:1. Is NP-complete [a]

2. Requires 𝑶 𝑳𝑵 operations• 𝐿 is the length of the sequences (≈ 100)• 𝑁 is the number of sequences (≈ 1,000)

⇒ Efficient solutions will be heuristic• Pairwise Averaging• DTW Barycenter Averaging (DBA)

[a] F. Petitjean, A. Ketterlin and P. Gançarski, “A global averaging method for dynamic time warping, with applications to clustering,” Pattern Recognition, vol. 44, no. 3, pp. 678–693, 2011.

Page 108: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Pairwise averaging for DTW

109V. Niennattrakul and C. A. Ratanamahatana, “On Clustering Multimedia Time Series Data Using K-Means and Dynamic Time Warping,” IEEE International Conference on Multimedia and Ubiquitous Engineering, pp.733-738, 2007.

0 5 10 15 20 25

• Average each alignment between the two time series

• Commonly increases the length• Chaining can produce average over a set• The operation is not associative, the

average produced depends on the order

X2

X1

X3

X4

Average

Average

X1,2

X3,4

Average X1-4

Average

Page 109: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

DTW Barycenter Averaging (DBA)

Algorithm DBA(D,av)

1 Iterate until convergence

2 for each sequence si in D

3 Ai = GetAlignment(DTW(si , av))

4 for each observation j in av

5 av[j] = mean([A1[j] A2[j] A3[j] …. An[j])

110

s1

s2av

s1

s2

• Does not increase length• Does not depend on the

order of the points

Page 110: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

0 20 40 60 80 1000

0.1

0.2

0.3

Kmeans

AHC

random

Drop2

Drop3

Drop1

SR

Err

or-

Rate

The minimum error-rate is

0.092, with 19 pairs of objects

The full dataset error-rate is

0.14, with 100 pairs of objects

Items per class in reduced training set

Experimental Evaluation on Insect Data

111Code Available : http://www.francois-petitjean.com/Research/ICDM2014-DTW

2 average-based techniques1. K-means2. AHC… both using DBA

4 rank-based competitors 1. Drop 12. Drop 23. Drop 34. Simple Rank

Page 111: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

What can be made fast?

• One-to-One comparison• Exact Implementation and Constraints• Efficient Approximation• Exploiting Sparsity

• One-to-Many comparisons• Nearest Neighbor Search

• In a database of independent time series• In subsequences of a long time series

• Density Estimation• In clustering

• Averaging Under Warping• In classification

• Many-to-Many comparisons• All-pair Distance Calculations

112

Page 112: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Speeding up DTW: many-to-many

• Several variants• Self-join within a threshold - top-K Self-join

• Use similarity search techniques as subroutine

• Application: Motif discovery [a], Discord discovery

• A/B Join within a threshold - top-K A/B Join• Use similarity search techniques as subroutine

• Application: Motion Stitching [b]

• All-pair distance matrix• Use techniques to speedup one-to-one comparisons

• Application: Hierarchical Clustering

113[b] Y. Chen, G. Chen, K. Chen and B. C. Ooi, "Efficient Processing of Warping Time Series Join of Motion Capture Data," ICDE, 2009, pp. 1048-1059.

[a] N Chavoshi, H Hamooni, A Mueen, “DeBot: Real-Time Bot Detection via Activity Correlation” UNM Technical Report

Page 113: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

PrunedDTW: speeding up all-pair distance matrix calculation• Two types of pruning

when calculating DTW matrix

• Exact method

114

0

1 2 3 4 5 6

3

4

5

6

≤UB

≤UB

≤UB

≤UB

>UB >UB ≤UB

0

0

1 2 3 4 5 6

0

1

2

3

≤UB

≤UB

≤UB

>UB≤UB ≤UB

∞ ∞ ∞ ∞ ∞

>UB >UB

≤UB >UB

200 400 600 800 1000 200 400 600 800 1000

100 100

200 200

300 300

400 400

500 500

600 600

700 700

800 800

900

1000

900

1000

Diego F. Silva, Gustavo E. A. P. A. Batista, Speeding Up All-Pairwise Dynamic Time Warping Matrix Calculation, SDM 2016

Lower triangle pruning

Upper triangle pruningUB = Euclidean distance UB = DTW distance

Page 114: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Experiments

115

DTW Pruned

DTW

Oracle

DTW

Warping Window

Length

Tim

e (

s)

0.1 0.2 0.3 0.4 0.5

10

20

30

Lighting-2

0.1 0.2 0.3 0.4 0.5

10

20

30

Car

0.1 0.2 0.3 0.4 0.5

1

2

3

x 104

CinC ECG torso

0.1 0.2 0.3 0.4 0.5

500

1000

1500

Haptics0.1 0.2 0.3 0.4 0.5

2000

4000

6000

8000

InlineSkate

0.1 0.2 0.3 0.4 0.5

2

4

6

Olive Oil

0.1 0.2 0.3 0.4 0.5

1

3

5

x 104

Non-Invasive Fetal ECG 2

0.1 0.2 0.3 0.4 0.5

1

3

5

x 104

Non-Invasive Fetal ECG 1

0.1 0.2 0.3 0.4 0.5

2

4

x 104

MALLAT

0.1 0.2 0.3 0.4 0.5

2

4

6x 10

5

Starlight Curves

Page 115: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Future of Similarity Search (1 of 2)

• Adapt to data domains• Incorporate scientific knowledge in similarity measures

• Phase-locking

• Linear attenuation

• Improvise the search techniques to work with data domains• Apply constraints in lower bounding and early abandoning

techniques: band-limited signals, minimum lag between signals, etc.

• Scalability via distributed computation• Preserve algorithmic improvements upon distribution. Do

not settle with larger pool of workers, when smaller pool is enough

116

Page 116: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Future of Similarity Search (2 of 2)

• Streaming Analytics• Keep pace with the data rate: worst case is the average

case

• Reduce memory footprint and achieve interactivity

• Predictive Analytics• Similarity based predictions

• Minimize lag before prediction

117

Page 117: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Additional References

• H. Sakoe and S. Chiba, “Dynamic programming algorithm optimization for spoken word recognition,” IEEE Trans. Acoust. Speech, Lang. Process., vol. 26, no. 1, pp. 43–50, 1978.

• Mustafa S. Çetin, Abdullah Mueen, Vince D. Calhoun: Shapelet Ensemble for Multi-dimensional Time Series. SDM 2015: 307-315

• X. Wang, A. Mueen, H. Ding, G. Trajcevski, P. Scheuermann, and E. Keogh, “Experimental comparison of representation methods and distance measures for time series data,” Data Min. Knowl. Discov., vol. 26, no. 2, pp. 275–309, 2013.

• D. Sart, A. Mueen, W. Najjar, V. Niennattrakul, and E. Keogh, “Accelerating Dynamic Time Warping Subsequnce Search with GPUs and FPGAs. ICDM 2010,” in Proceedings - IEEE International Conference on Data Mining, ICDM, 2010, pp. 1001–1006.

• Abdullah Mueen, Hossein Hamooni, Trilce Estrada: Time Series Join on Subsequence Correlation. ICDM 2014: 450-459

• Ira Assent, Marc Wichterich, Ralph Krieger, Hardy Kremer, and Thomas Seidl. 2009. Anticipatory DTW for efficient similarity search in time series databases. Proc. VLDB Endow. 2, 1 (August 2009), 826-837.

118

Page 118: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

Conclusion

• Time series similarity search is no longer a slow operation to build data mining algorithms on

• Lockstep and Elastic measures both have applications in various domains. Their usages are limited only by our imagination.

119

Page 119: similarity join for time series subsequencesmueen/Tutorial/CIKM2016Tutorial.pdf · Rotation invariant distance measures for trajectories. KDD '04. 707-712. 2. Dragomir Yankov, Eamonn

120