problem by breaking it recursively into sub-problems. The sub-problem results are saved in a tabular format to avoid duplicate computation. The problem being solved satisfies two properties • Overlapping Sub-problems • Optimal Substructure
1 2 3 minCost(m,n) = cost[m][n] + min( ) minCost(m-1, n-1), minCost(m-1, n), minCost(m, n-1) Optimal Substructure Optimal solution of the given problem can be obtained by using optimal solutions of its sub-problems. int minCost(int[][] cost, int m, int n){ if(m<0 || n<0){ return Integer.MAX_VALUE; } if(m==0 && n==0){ return cost[0][0]; } return cost[m][n] + min(minCost(cost, m-1, n-1), minCost(cost, m, n-1), minCost(cost, m-1, n)); }
BDF, AEG, ACEFG Longest Common Subsequences LCS of ABCDGH and AEDFHR AD, AH, ADH are common subsequences ADH is an LCS LCS of AGGTAB and GXTXAYB GT, AB, GTA, TAB, GTAB are common subsequences GTAB is an LCS
lengths m & n Length of LCS Case when last character of both S1 & S2 match LCS(“AGGTAB”, “GXTXAYB”) = 1 + LCS(“AGGTA”, “GXTXAY”) LCS(S1, S2, m, n) = 1 + LCS(S1, S2, m-1, n-1) Otherwise, LCS(“ABCDGH”, “AEDFHR”) = MAX ( LCS(“ABCDG”, “AEDFHR”), LCS(“ABCDGH”, “AEDFH”) ) LCS(S1, S2, m, n) = MAX(LCS(S1, S2, m-1, n), LCS(S1, S2, m, n-1))
time Any distance (Euclidean, Manhattan, …) which aligns the i-th point on one time series with the i-th point on the other will produce a poor similarity score. A non-linear (elastic) alignment produces a more intuitive similarity measure, allowing similar shapes to match even if they are out of phase in the time axis.
Series A Dynamic Time Warping To find the best alignment between A and B one needs to find the path through the grid P = p1 , … , ps , … , pk ps = (is , js ) which minimizes the total distance between them. P is called a warping function.
> 0 is the window length. A good alignment path is unlikely to wander too far from the diagonal. Guarantees that the alignment does not try to skip different features and gets stuck at similar features. i j r Warping Window
problem by breaking it recursively into sub-problems. The sub-problem results are saved in a tabular format to avoid duplicate computation. The problem being solved satisfies two properties • Overlapping Sub-problems • Optimal Substructure Conclusion & Definition Revisited