changeset 307:8e66ced156dd

add delta to sample the time window in LCSS function
author Mohamed Gomaa
date Tue, 25 Dec 2012 02:16:10 -0500
parents f2cf16ad798f
children 8bafd054cda4
files python/utils.py
diffstat 1 files changed, 9 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/python/utils.py	Fri Dec 21 18:33:36 2012 -0500
+++ b/python/utils.py	Tue Dec 25 02:16:10 2012 -0500
@@ -165,19 +165,22 @@
 # maths section
 #########################
 
-def LCSS(l1, l2, threshold, distance):
+def LCSS(l1, l2, threshold, delta, distance):
     '''returns the longest common subsequence similarity
-    based on the threshold on distance between two elements of lists l1, l2'''
+    based on the threshold on distance between two elements of lists l1, l2.
+	looks for points that are sampled within a delta time window, can put 'inf' value to cancl this condition'''
     from numpy import zeros, int as npint
     m = len(l1)
     n = len(l2)
     similarity = zeros((m+1,n+1), dtype = npint)
     for i in xrange(1,m+1):
         for j in xrange(1,n+1):
-            if distance(l1[i-1], l2[j-1])<threshold:
-                similarity[i][j] = similarity[i-1][j-1]+1
-            else:
-                similarity[i][j] = max(similarity[i-1][j], similarity[i][j-1])
+			from math import fabs
+			while fabs(i-j)<= delta:
+                if distance(l1[i-1], l2[j-1])<threshold:
+                    similarity[i][j] = similarity[i-1][j-1]+1
+                else:
+                    similarity[i][j] = max(similarity[i-1][j], similarity[i][j-1])
     return similarity[-1][-1]
 
 def framesToTime(nFrames, frameRate, initialTime = (0.,0.,0.)):