Professional Documents
Culture Documents
Modified DTW JATIT
Modified DTW JATIT
Modified DTW JATIT
ABSTRACT
Time series clustering is the process of grouping sequential correspondences in similar clusters. The key
characteristic behind clustering time series data lies on the similarity/distance function used to identify the
sequential matches. Dynamic Time Warping (DTW) is one of the common distance measures that have
demonstrated competitive results compared to other functions. DTW aims to find the shortest path in the
process of identifying sequential matches. DTW relies on a dynamic programming to obtain the shortest path
where the smaller distance is being computed. However, in the case of equivalent distances, DTW is selecting
the path randomly. Hence, the selection could be misguided in such randomization process which
significantly affect the matching quality. This is due to randomization may lead to longer path which drift
from obtaining the optimum path. This paper proposes a modified DTW that aims to enhance the dynamic
selection of the shortest path when handling equivalent distances. Experiments were conducted using twenty
UCR benchmark datasets. Results shown that the modified DTW reveal superior results in compared to the
standard. This can demonstrate the effectiveness of the proposed modification in which optimizing the
shortest path has enhanced the performance of clustering.
Keywords: Hierarchical Clustering, Dynamic Time Warping, Distance Measures
1
Journal of Theoretical and Applied Information Technology
XXst Month 201x. Vol. x No.x
© 2005 - 2012 JATIT & LLS. All rights reserved.
2
Journal of Theoretical and Applied Information Technology
XXst Month 201x. Vol. x No.x
© 2005 - 2012 JATIT & LLS. All rights reserved.
𝑃 PB6 0 1 1 4 1 1
𝑞
𝑞
𝑑𝑀 = √∑(𝑥𝑖𝑘 − 𝑣𝑗𝑘 ) (2) PB7 1 1 4 9 4 0
𝑘=1
Where q is a positive integer. The objective of this matrix is to find the shortest
path by starting from the top most right corner
3.2. Dynamic Time Warping (DTW) 𝑃(𝑃𝐴6 , 𝑃𝐵1 ) and using dynamic programming to
DTW has been widely used to compare between reach the point of origin 𝑃(𝑃𝐴1 , 𝑃𝐵7 ) accumulating
discrete sequences and sequences of continuous the sum of the similarity between the went thru
points (accumulated path).
values (Liao, 2005). Let 𝑆 = {𝑠1 , 𝑠2 , … , 𝑠𝑖 , … , 𝑠𝑛 }
and 𝑇 = {𝑡1 , 𝑡2 , … , 𝑡𝑗 , … , 𝑡𝑛 } be a two time series On 𝑃(𝑃𝐴6 , 𝑃𝐵1 ), DTW will pick the minimum
sequences. DTW will minimize the differences between three points 𝑃(𝑖 − 1, 𝑗) = 𝑃(𝑃𝐴5 , 𝑃𝐵1 ),
among these series by representing a matrix of 𝑛 × 𝑃(𝑖, 𝑗 − 1) = 𝑃(𝑃𝐴6 , 𝑃𝐵2 ) or 𝑃(𝑖 − 1, 𝑗 − 1) =
𝑚. In such matrix, the distance/similarity between 𝑠𝑖 𝑃(𝑃𝐴5 , 𝑃𝐵2 ). Since 𝑃(𝑃𝐴5 , 𝑃𝐵2 ) = 0 which is the
and 𝑡𝑗 will be calculated using Euclidean distance. minimum value thus, it was selected and the
accumulated cost was increment by its value. And so
However, a warping path 𝑃= on until the point P(𝑃𝐴1 , 𝑃𝐵7 ) is reached.
{𝑝1 , 𝑝2 , … , 𝑝𝑘 , … , 𝑝𝐾 } where max(𝑚, 𝑛) ≤ 𝐾 ≤ 𝑚 +
𝑛 − 1 will be elements from the matrix that meet On point 𝑃(𝑃𝐴5 , 𝑃𝐵2 ), all the neighboring cells
three constraints including boundary condition, have equivalent values, here the randomization is
continuity and monotonicity. The boundary taking a place in which the movement will be
condition constraint requires the warping path to selected randomly as shown in Fig. 1 (a). Similarly,
start and finish in diagonally opposite corner cells of in the points 𝑃(𝑃𝐴3 , 𝑃𝐵2 ) the selection has been
the matrix. That is 𝑝1 = (1,1) and 𝑝𝐾 = (𝑚, 𝑛). The performed randomly.
continuity constraint restricts the allowable steps to Hence, the modification of DTW has been
adjacent cells. The monotonicity constraint forces conducted by setting the value of 𝑃(𝑖 − 1, 𝑗 − 1)
the points in the warping path to be monotonically when handling neighbors with similar values, this
spaced in time. The warping path that has the can be represented in Fig. 1 (b).
3
Journal of Theoretical and Applied Information Technology
XXst Month 201x. Vol. x No.x
© 2005 - 2012 JATIT & LLS. All rights reserved.
As shown in Fig. 1, the summation of the path for 0 + 0 + 0 + 0 + 1} = 2. Apparently, the results of
the standard DTW can be expressed as 𝑆𝑢𝑚 = both applications shown variant values. Such
{1 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 1} = 3, whereas difference may have a potential impact on the final
for the modified DTW 𝑆𝑢𝑚 = {1 + 0 + 0 + 0 + outcome of the time series clustering. Fig. 2 depicts
the pseudo code of the modified DTW.
Algorithm 1. Modified Dynamic Time Warping
1 Input:
2 S // is a 2-dimensional matrix with 𝑚 × 𝑛
3 𝑉1 = {𝑠1 , 𝑠2 , … . , 𝑠𝑛 } //is the first vector with n time points
4 𝑉2 = {𝑠1 , 𝑠2 , … . , 𝑠𝑚 } // is the second vector with m time points
5 𝑖, 𝑗 // are loop index, cost is an integer
6
7 Steps:
8 Initialize the matrix
9 S[0,0] = 0;
10 FOR i = 1 to m DO LOOP
11 S[0 , i ] = ∞
12 END
13 FOR i = 1 to n DO LOOP
14 S[i , 0 ] = ∞
15 END
16 Populating the similarity matrix
17 FOR i = 1 to n DO LOOP
18 FOR j = 1 to m DO LOOP
19 Cost = d(V1[i], V2[j])//Euclidean distance
20 S[i , j] = cost + MINI
21 MINI = IF S[I-1, J-1] equals S[i, j-1]
22 MINI = S[i-1, j-1]
23 OR if S[i-1, j-1] equals S[i-1, j]
24 MINI = S[i-1, j-1]
25 ELSE MINI = Minimum ( S[i-1 , j] , //increment
26 S[i , j-1] , //decrement
27 S[i-1, j-1] ) //match
28 END
29 END
30 Return S[n , m]
31
32
33
4
Journal of Theoretical and Applied Information Technology
XXst Month 201x. Vol. x No.x
© 2005 - 2012 JATIT & LLS. All rights reserved.
5
Journal of Theoretical and Applied Information Technology
XXst Month 201x. Vol. x No.x
© 2005 - 2012 JATIT & LLS. All rights reserved.
Euclidean Minkowski
100 100
50 50
0 0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
P R F P R F
P R F P R F
Figure 3. Results of precision, recall and f-measure for the four distance measures
F-measure
100
80
60
40
20
0
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
As shown in Fig 4, The result shows that DTW has outperformed the other distance functions in terms of
outperformed both of Minkowski and Euclidean f-measure for 6 datasets including '4, 5, 6, 9, 12, 18'.
distance measures in terms of f-measure for 14 out Apparently, Euclidean distance function has
of 20 data sets including ‘1, 2, 3, 7, 8, 10, 11, 13, 14, obtained the lowest f-measure values for all datasets.
15, 16, 17, 19, 20’. In contrast, Minkowski has
6
Journal of Theoretical and Applied Information Technology
XXst Month 201x. Vol. x No.x
© 2005 - 2012 JATIT & LLS. All rights reserved.
7
Journal of Theoretical and Applied Information Technology
XXst Month 201x. Vol. x No.x
© 2005 - 2012 JATIT & LLS. All rights reserved.