diff python/utils.py @ 285:5957aa1d69e1

Integrating Mohamed's changes Changed the indicator interface to access values, so that the generic LCSS implementation can be used
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Sat, 26 Jan 2013 19:02:25 -0500
parents f2cf16ad798f
children fa95796a76b3
line wrap: on
line diff
--- a/python/utils.py	Fri Dec 21 18:33:36 2012 -0500
+++ b/python/utils.py	Sat Jan 26 19:02:25 2013 -0500
@@ -165,15 +165,16 @@
 # maths section
 #########################
 
-def LCSS(l1, l2, threshold, distance):
+def LCSS(l1, l2, threshold, distance, delta = float('inf')):
     '''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
+    '''
     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):
+        for j in xrange(max(1,i-delta),min(n+1,i+delta)):
             if distance(l1[i-1], l2[j-1])<threshold:
                 similarity[i][j] = similarity[i-1][j-1]+1
             else: